On Sun, Oct 26, 2025 at 2:32 PM Takayuki 'January June' Suwa <[email protected]> wrote: > > This patch effectively revert the past commit > 9777d446e2148ef9a6e9f35db3f4eab99ee8812c. > > Almost the only reason we committed that was because some optimizers in the > RTL ifcvt pass needed '(set (reg) (not (reg)))' RTX, however, in recent > versions of gcc, the equivalent optimizations are performed before RTL > passes, so the need for that commit has all but disappeared. > > /* example 1 */ > int test0(int a) { > return a < 0 ? ~a : a; > } > > ;; result 1 > test0: > entry sp, 32 > srai a8, a2, 31 ;; If-conversion before RTL expansion > xor a2, a8, a2 > retw.n > > Instead, expanding it to an XOR with a pseudo whose value of -1 early in > the RTL passes will take advantage of CSE, forward propagation, or loop- > invariant hoisting. > > /* example 2 */ > long long test1(long long a) { > return ~a; > } > void test2(int a[]) { > int i; > for (i = 0; i < 16; ++i) > a[i] = ~a[i]; > } > > ;; result 2 > test1: > entry sp, 32 > movi.n a8, -1 ;; consolidated by CSE > xor a2, a2, a8 > xor a3, a3, a8 > retw.n > test2: > entry sp, 32 > movi.n a10, -1 ;; hoisted out > movi.n a9, 0x10 > loop a9, .L5_LEND > .L5: > l32i.n a8, a2, 0 > xor a8, a8, a10 > s32i.n a8, a2, 0 > addi.n a2, a2, 4 > .L5_LEND: > retw.n > > Another concern with reverting that commit is the impact on complex insns > that have '(not)' as part of them, but also nothing to worry about; because > the RTL insn combiner can correctly recognize an XOR with a register value > of -1 as a one's complement operation even without such RTX, and apply the > result to subsequent combine operations. > > gcc/ChangeLog: > > * config/xtensa/xtensa.md (one_cmplsi2): > Rearrange back as an expand pattern. > > gcc/testsuite/ChangeLog: > > * gcc.target/xtensa/one_cmpl_abs.c: Remove. > --- > gcc/config/xtensa/xtensa.md | 25 ++++++------------- > .../gcc.target/xtensa/one_cmpl_abs.c | 9 ------- > 2 files changed, 7 insertions(+), 27 deletions(-) > delete mode 100644 gcc/testsuite/gcc.target/xtensa/one_cmpl_abs.c
Committed to master. -- Thanks. -- Max
