On 1/31/2026 1:14 AM, Alexandre Oliva wrote:
The insn simplification expected by the test, to get a bset
instruction, has been prevented since r15-9239, because we get rotates
for bit clear and shifts for bit flip, and we don't know how to
simplify those.

Teach the rtl simplifier, at the spots where it had been extended to
handle these logical simplifications, to also handle these less
obvious negations.

Regstrapped on x86_64-linux-gnu along with other patches in this batch;
also tested with targets riscv64-elf and riscv32-elf on the same host,
both trunk and gcc-15.  Ok to install?

(I forgot to add the final question in the previous patches in this
batch; please read them as if the question was there ;-)


for  gcc/ChangeLog

        * simplify-rtx.cc (negated_ops_p): New.
        (simpify_context::simplify_binary_operation_1): Use it.
So the argument would be that we have a regression  due to r15-9239?  I'm a bit surprised I didn't notice this on riscv64-elf in my testing.


+
+  /* (~C <r A) is a negated form of (C << A) if C == 1.  */
+  if (GET_CODE (op) == ASHIFT
+      && GET_CODE (nop) == ROTATE
+      && XEXP (op, 0) == CONST1_RTX (GET_MODE (op))
+      && CONST_INT_P (XEXP (nop, 0))
+      && INTVAL (XEXP (nop, 0)) == -2
+      && rtx_equal_p (XEXP (op, 1), XEXP (nop, 1))
+      )
+    return true;
+  if (GET_CODE (nop) == ASHIFT
+      && GET_CODE (op) == ROTATE
+      && XEXP (nop, 0) == CONST1_RTX (GET_MODE (op))
+      && CONST_INT_P (XEXP (nop, 0))
+      && INTVAL (XEXP (nop, 0)) == -2
+      && rtx_equal_p (XEXP (op, 1), XEXP (nop, 1))
+      )
Formatting nits with the final close paren.  Belongs on the previous line.

+    return true;
+
+  /* ??? Should we consider rotations of C and ~C by the same amount?  */
Probably.  Though testcases would be helpful here.  Defer since this issue may not be a regression?

OK with the formatting nit addressed assuming you're considering this a gcc-15/gcc-16 regression.

jeff

Reply via email to