xtensa: constantsynth: Update to version 2
This patch completely replaces the existing "constantsynth" with a new
implementation, which has become unsightly due to the extension.
This new version offers the following benefits:
- Independence from the insn splitting mechanism. No define_split
descriptions are required
- Resource saving as internally required information storage no longer
persists across passes
- The replacement of insns is based on the actual costs (for both size
and speed) of the insns before and after the conversion, rather than
on some arbitrary pre-determined ones
- The replacing insn sequence is verified by formally evaluating the
RTL expressions to see if it correctly computes the original constant
value
- Easy-to-understand/-add interface for constant synthesis methods
The built-in synthesis methods are (supposedly) very effective, with 2
instructions for certain values and up to 5 instructions to cover all
32-bit values.
/* example */
_Complex double test(int a[], float b[]) {
a[0] = 2045 * 2045;
a[1] = 0xDEADBEEF;
a[2] = 0xDEADBEEF - 15;
a[3] =
4182000;
a[4] = 131071;
a[5] = 293805;
a[6] =
700972933;
a[7] = -
372738139;
b[0] = 3.
14159265359f;
b[1] *= 0.
12005615234375f;
return 1-1i;
}
;; result (-O2 -mextra-l32r-costs=5)
test:
entry sp, 32
movi a8, 0x7af
float.s f1, a8, 14
movi a8, 0x7fd
mull a8, a8, a8
lsi f0, a3, 4
s32i.n a8, a2, 0
movi.n a8, 0x57
addmi a8, a8, -0x1100
slli a8, a8, 17
addmi a8, a8, -0x4100
addi a8, a8, -17
s32i.n a8, a2, 4
addi a8, a8, -15
s32i.n a8, a2, 8
movi a8, 0x3fd
slli a8, a8, 12
addi a8, a8, -16
s32i.n a8, a2, 12
movi.n a8, -1
srli a8, a8, 15
s32i.n a8, a2, 16
movi a8, 0x85
addmi a8, a8, 0x7f00
addx8 a8, a8, a8
s32i.n a8, a2, 20
movi a8, 0x539
slli a8, a8, 19
addi a8, a8, -123
s32i.n a8, a2, 24
movi a8, -0x2c7
slli a8, a8, 19
addmi a8, a8, 0x7800
addi a8, a8, -91
s32i.n a8, a2, 28
movi.n a8, 0x49
mul.s f0, f0, f1
addmi a8, a8, 0x4000
slli a8, a8, 16
addmi a8, a8, 0x1000
addi a8, a8, -37
s32i.n a8, a3, 0
ssi f0, a3, 4
movi a5, -0x401
movi a3, 0x3ff
movi.n a2, 0
slli a3, a3, 20
movi.n a4, 0
slli a5, a5, 20
retw.n
gcc/ChangeLog:
* config/xtensa/xtensa-protos.h (xtensa_constantsynth): Remove.
* config/xtensa/xtensa.cc
(#include): Remove "context.h" and "pass_manager.h".
(machine_function): Remove "litpool_usage" member.
(xtensa_constantsynth_2insn, xtensa_constantsynth_rtx_SLLI,
xtensa_constantsynth_rtx_ADDSUBX, xtensa_constantsynth): Remove.
(constantsynth_method_lshr_m1, split_hwi_to_MOVI_ADDMI,
constantsynth_method_16bits, constantsynth_method_32bits,
constantsynth_method_square): New worker function related to
constant synthesis methods.
(constantsynth_method_info, constantsynth_methods):
New structure representing the list of all constant synthesis
methods.
(constantsynth_info): New structure that stores internal
information for "constantsynth".
(constantsynth_pass1, verify_synth_seq, constantsynth_pass2):
New functions that are the core of "constantsynth".
(do_largeconst): Add a call to constantsynth_pass1() to the insn
enumeration loop, and add a call to constantsynth_pass2() to the
end of this function.
* config/xtensa/xtensa.md (SHI): Remove.
(The two auxiliary define_splits for mov[sh]i_internal): Remove.
(The two auxiliary define_splits for movsf_internal): Remove.
gcc/testsuite/ChangeLog:
* gcc.target/xtensa/constsynth_2insns.c,
gcc.target/xtensa/constsynth_3insns.c,
gcc.target/xtensa/constsynth_double.c: Remove due to outdated.
* gcc.target/xtensa/constsynthV2_O2_costs0.c,
gcc.target/xtensa/constsynthV2_O2_costs5.c,
gcc.target/xtensa/constsynthV2_Os.c: New.