]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[RISC-V][PR target/118122] Fix modes in recently added risc-v pattern
authorJeff Law <jlaw@ventanamicro.com>
Mon, 30 Dec 2024 14:40:07 +0000 (07:40 -0700)
committerJeff Law <jlaw@ventanamicro.com>
Mon, 30 Dec 2024 14:42:54 +0000 (07:42 -0700)
The new pattern to optimize certain code sequences on RISC-V played things a
bit fast and loose with modes -- some operands were using the ALLI iterator
while the scratch used X and the split codegen used X.

Naturally under the "right" circumstances this would trigger an ICE due to
mismatched modes.  This patch uses X consistently in that pattern. It also
fixes some formatting nits.

Tested in my tester, but waiting on the pre-commit verdict before moving
forward.

PR target/118122
gcc/
* config/riscv/riscv.md (lui_constraint<X:mode>_and_to_or): Use
X iterator rather than ANYI consistently.  Fix formatting.

gcc/testsuite

* gcc.target/riscv/pr118122.c: New test.

gcc/config/riscv/riscv.md
gcc/testsuite/gcc.target/riscv/pr118122.c [new file with mode: 0644]

index 6c6155ceeb832328853a72cdd7006f0ac35af6e8..deb156075497355d812daeba61a1f35e0757bce1 100644 (file)
 ;; Transform (X & C1) + C2 into (X | ~C1) - (-C2 | ~C1)
 ;; Where C1 is not a LUI operand, but ~C1 is a LUI operand
 
-(define_insn_and_split "*lui_constraint<ANYI:mode>_and_to_or"
-       [(set (match_operand:ANYI 0 "register_operand" "=r")
-       (plus:ANYI (and:ANYI (match_operand:ANYI 1 "register_operand" "r")
-                        (match_operand 2 "const_int_operand"))
-                (match_operand 3 "const_int_operand")))
+(define_insn_and_split "*lui_constraint<X:mode>_and_to_or"
+       [(set (match_operand:X 0 "register_operand" "=r")
+       (plus:X (and:X (match_operand:X 1 "register_operand" "r")
+                      (match_operand 2 "const_int_operand"))
+               (match_operand 3 "const_int_operand")))
    (clobber (match_scratch:X 4 "=&r"))]
-  "LUI_OPERAND (~INTVAL (operands[2]))
-   && ((INTVAL (operands[2]) & (-INTVAL (operands[3])))
-   == (-INTVAL (operands[3])))
-   && riscv_const_insns (operands[3], false)
-   && (riscv_const_insns
-   (GEN_INT (~INTVAL (operands[2]) | -INTVAL (operands[3])), false)
-   <= riscv_const_insns (operands[3], false))"
+  "(LUI_OPERAND (~INTVAL (operands[2]))
+    && ((INTVAL (operands[2]) & (-INTVAL (operands[3])))
+       == (-INTVAL (operands[3])))
+    && riscv_const_insns (operands[3], false)
+    && (riscv_const_insns (GEN_INT (~INTVAL (operands[2])
+                                   | -INTVAL (operands[3])), false)
+       <= riscv_const_insns (operands[3], false)))"
   "#"
   "&& reload_completed"
   [(set (match_dup 4) (match_dup 5))
diff --git a/gcc/testsuite/gcc.target/riscv/pr118122.c b/gcc/testsuite/gcc.target/riscv/pr118122.c
new file mode 100644 (file)
index 0000000..0cdc3bf
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fno-tree-ter -fno-forward-propagate" } */
+char c;
+
+void
+foo(short s)
+{
+  s += 34231u;
+  c = s;
+}
+
+