Hi Suwa-san, On Sat, Jun 3, 2023 at 2:55 AM Takayuki 'January June' Suwa <jjsuwa_sys3...@yahoo.co.jp> wrote: > > This patch optimizes the boolean evaluation of EQ/NE against zero > by adding two insn_and_split patterns similar to SImode conditional > store: > > "eq_zero": > op0 = (op1 == 0) ? 1 : 0; > op0 = clz(op1) >> 5; /* optimized (requires TARGET_NSA) */ > > "movsicc_ne0_reg_0": > op0 = (op1 != 0) ? op2 : 0; > op0 = op2; if (op1 == 0) ? op0 = op1; /* optimized */ > > These also work in SFmode by ignoring their sign bits, and further- > more, the branch if EQ/NE against zero in SFmode is also done in the > same manner. > > The reasons for this optimization in SFmode are: > > - Only zero values (negative or non-negative) contain no bits of 1 > with both the exponent and the mantissa. > - EQ/NE comparisons involving NaNs produce no signal even if they > are signaling. > - Even if the use of IEEE 754 single-precision floating-point co- > processor is configured (TARGET_HARD_FLOAT is true): > 1. Load zero value to FP register > 2. Possibly, additional FP move if the comparison target is > an address register > 3. FP equality check instruction > 4. Read the boolean register containing the result, or condi- > tional branch > As noted above, a considerable number of instructions are still > generated. > > gcc/ChangeLog: > > * config/xtensa/predicates.md (const_float_0_operand): > Rename from obsolete "const_float_1_operand" and change the > constant to compare. > (cstoresf_cbranchsf_operand, cstoresf_cbranchsf_operator): > New. > * config/xtensa/xtensa.cc (xtensa_expand_conditional_branch): > Add code for EQ/NE comparison with constant zero in SFmode. > (xtensa_expand_scc): Added code to derive boolean evaluation > of EQ/NE with constant zero for comparison in SFmode. > (xtensa_rtx_costs): Change cost of CONST_DOUBLE with value > zero inside "cbranchsf4" to 0. > * config/xtensa/xtensa.md (cbranchsf4, cstoresf4): > Change "match_operator" and the third "match_operand" to the > ones mentioned above. > (movsicc_ne0_reg_zero, eq_zero): New. > --- > gcc/config/xtensa/predicates.md | 19 ++++++++++-- > gcc/config/xtensa/xtensa.cc | 43 ++++++++++++++++++++++++++ > gcc/config/xtensa/xtensa.md | 53 +++++++++++++++++++++++++++++---- > 3 files changed, 106 insertions(+), 9 deletions(-)
This change results in a bunch of new testsuite failures on configurations without FPU that are all ICEs: +FAIL: gcc.c-torture/execute/bitfld-3.c -O1 execution test +FAIL: gcc.dg/atomic/c11-atomic-exec-1.c -O1 (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/c11-atomic-exec-1.c -O1 (test for excess errors) +FAIL: gcc.dg/atomic/c11-atomic-exec-1.c -O2 (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/c11-atomic-exec-1.c -O2 (test for excess errors) +FAIL: gcc.dg/atomic/c11-atomic-exec-1.c -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/c11-atomic-exec-1.c -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions (test for excess errors) +FAIL: gcc.dg/atomic/c11-atomic-exec-1.c -O3 -g (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/c11-atomic-exec-1.c -O3 -g (test for excess errors) +FAIL: gcc.dg/atomic/c11-atomic-exec-1.c -Os (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/c11-atomic-exec-1.c -Os (test for excess errors) +FAIL: gcc.dg/atomic/c11-atomic-exec-1.c -O2 -flto -fno-use-linker-plugin -flto-partition=none (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/c11-atomic-exec-1.c -O2 -flto -fno-use-linker-plugin -flto-partition=none (test for excess errors) +FAIL: gcc.dg/atomic/c11-atomic-exec-1.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/c11-atomic-exec-1.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects (test for excess errors) +FAIL: gcc.dg/atomic/c11-atomic-exec-3.c -O1 (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/c11-atomic-exec-3.c -O1 (test for excess errors) +FAIL: gcc.dg/atomic/c11-atomic-exec-3.c -O2 (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/c11-atomic-exec-3.c -O2 (test for excess errors) +FAIL: gcc.dg/atomic/c11-atomic-exec-3.c -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/c11-atomic-exec-3.c -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions (test for excess errors) +FAIL: gcc.dg/atomic/c11-atomic-exec-3.c -O3 -g (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/c11-atomic-exec-3.c -O3 -g (test for excess errors) +FAIL: gcc.dg/atomic/c11-atomic-exec-3.c -Os (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/c11-atomic-exec-3.c -Os (test for excess errors) +FAIL: gcc.dg/atomic/c11-atomic-exec-3.c -O2 -flto -fno-use-linker-plugin -flto-partition=none (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/c11-atomic-exec-3.c -O2 -flto -fno-use-linker-plugin -flto-partition=none (test for excess errors) +FAIL: gcc.dg/atomic/c11-atomic-exec-3.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/c11-atomic-exec-3.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects (test for excess errors) +FAIL: gcc.dg/atomic/pr65345-4.c -O1 (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/pr65345-4.c -O1 (test for excess errors) +FAIL: gcc.dg/atomic/pr65345-4.c -O2 (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/pr65345-4.c -O2 (test for excess errors) +FAIL: gcc.dg/atomic/pr65345-4.c -O3 -g (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/pr65345-4.c -O3 -g (test for excess errors) +FAIL: gcc.dg/atomic/pr65345-4.c -Os (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/pr65345-4.c -Os (test for excess errors) +FAIL: gcc.dg/atomic/pr65345-4.c -O2 -flto -fno-use-linker-plugin -flto-partition=none (internal compiler error: in extract_insn, at recog.cc:2791) +FAIL: gcc.dg/atomic/pr65345-4.c -O2 -flto -fno-use-linker-plugin -flto-partition=none (test for excess errors) On configuration with FPU it results in ICEs during libgfortran build, all with the similar diagnostic: gcc/libgfortran/intrinsics/erfc_scaled_inc.c:179:1: error: unrecognizable insn: 179 | } | ^ (insn 23 22 24 2 (set (reg:CC 18 b0) (lt:CC (const_double:SF 0.0 [0x0.0p+0]) (reg/v:SF 96 [ x ]))) "gcc/libgfortran/intrinsics/erfc_scaled_inc.c":111:18 -1 (nil)) during RTL pass: vregs -- Thanks. -- Max