rtl-optimization: ICE on testsuite/gcc.dg/sso/t5.c with -mcpu=future -mpcrel 
-O1 [PR94740]

We ICE on the test case below because decompose_normal_address()  doesn't
expect to see memory operands with constant addresses like below without
a (const:DI ...) wrapped around the PLUS:

        (mem/c:SI (plus:DI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182])
                           (const_int 4 [0x4])) [1 array+4 S4 A32])

What we expect to see is:

        (mem/c:SI (const:DI (plus:DI (symbol_ref:DI ("*.LANCHOR0") [flags 
0x182])
                                     (const_int 4 [0x4]))) [1 arrayD.2903+4 S4 
A32])

Sometimes, combine adds the (const: ...) for us via simplify_binary_operand
call, but that only happens when combine actually does something with this
insn.  The bad address from the test case actually comes from CSE, so the
fix here is to make CSE add the (const: ...) whenever it creates a MEM with
a constant address.

This passed bootstrap and regtesting on powerpc64le-linux with no regressions.
Ok for trunk?

Peter


gcc/
        PR rtl-optimization/94740
        * cse.c (cse_process_notes):

gcc/testsuite/
        PR rtl-optimization/94740
        * gcc.target/powerpc/pr94740.c: New test.

diff --git a/gcc/cse.c b/gcc/cse.c
index 5aaba8d80e0..cbe9e0a0692 100644
--- a/gcc/cse.c
+++ b/gcc/cse.c
@@ -6328,6 +6328,14 @@ cse_process_notes (rtx x, rtx object, bool *changed)
   rtx new_rtx = cse_process_notes_1 (x, object, changed);
   if (new_rtx != x)
     *changed = true;
+  if (*changed && object != NULL_RTX && MEM_P (object))
+    {
+      /* Call simplify_rtx on the updated address in case it is now
+        a constant and needs to be wrapped with a (const: ...).  */
+      rtx simplified_rtx = simplify_rtx (new_rtx);
+      if (simplified_rtx)
+       new_rtx = simplified_rtx;
+    }
   return new_rtx;
 }
 
diff --git a/gcc/testsuite/gcc.target/powerpc/pr94740.c 
b/gcc/testsuite/gcc.target/powerpc/pr94740.c
new file mode 100644
index 00000000000..78e40fc84da
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr94740.c
@@ -0,0 +1,11 @@
+/* PR rtl-optimization/94740 */
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_future_ok } */
+/* { dg-options "-O2 -mdejagnu-cpu=future -mpcrel" } */
+
+int array[8];
+int
+foo (void)
+{
+  return __builtin_bswap32 (array[1]);
+}

Reply via email to