https://gcc.gnu.org/g:4b364531057c973795dc15d75132fb6c2ea6219b

commit r14-11471-g4b364531057c973795dc15d75132fb6c2ea6219b
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Wed Mar 26 08:47:20 2025 +0100

    i386: Require in peephole2 that memory is offsettable [PR119450]
    
    The following testcase ICEs because a peephole2 attempts to offset
    memory which is not offsettable (in particular address is a ZERO_EXTEND
    in this case).
    
    Because peephole2s don't support constraints, I've added a check for this
    in the peephole2's condition.
    
    2025-03-26  Jakub Jelinek  <ja...@redhat.com>
    
            PR target/119450
            * config/i386/i386.md (narrow test peephole2): Test for
            offsettable_memref_p in condition.
    
            * gcc.target/i386/pr119450.c: New test.
    
    (cherry picked from commit 84f0b648aeb053b3bd8e1cb6fe282f4da4143708)

Diff:
---
 gcc/config/i386/i386.md                  |  4 +++-
 gcc/testsuite/gcc.target/i386/pr119450.c | 15 +++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index a7508d47d9b1..447a319f7a1c 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -11630,7 +11630,9 @@
          (and:SWI248 (match_operand:SWI248 0 "memory_operand")
                      (match_operand 1 "const_int_operand"))
          (const_int 0)))]
-  "!TARGET_PARTIAL_MEMORY_READ_STALL && !MEM_VOLATILE_P (operands[0])"
+  "!TARGET_PARTIAL_MEMORY_READ_STALL
+   && !MEM_VOLATILE_P (operands[0])
+   && offsettable_memref_p (operands[0])"
   [(set (reg:CCZ FLAGS_REG)
        (compare:CCZ (match_dup 2) (const_int 0)))]
 {
diff --git a/gcc/testsuite/gcc.target/i386/pr119450.c 
b/gcc/testsuite/gcc.target/i386/pr119450.c
new file mode 100644
index 000000000000..fa4bbdaf88cf
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr119450.c
@@ -0,0 +1,15 @@
+/* PR target/119450 */
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+long *a;
+int b;
+
+void
+foo (void)
+{
+  unsigned d = b >> 30;
+  a = (long *) (__UINTPTR_TYPE__) d;
+  if (*a & 1 << 30)
+    *a = 0;
+}

Reply via email to