On 4/28/20 11:57 AM, Richard Sandiford wrote:
> I was just quoting code from simplify_replace_fn_rtx as an example of
> something that handles a similar situation.  The recursive calls would
> be different for cse_process_notes_1.

Ok, how about the following which adds the (const:P ...) as well, which
fixes the ICE?  The FOR loop which now follows this switch statement is
what used to modify the PLUS's operands without adding the (const:P ).

This is still in the middle of bootstrap and regtesting.

Peter


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

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..4592820c04c 100644
--- a/gcc/cse.c
+++ b/gcc/cse.c
@@ -6314,6 +6314,21 @@ cse_process_notes_1 (rtx x, rtx object, bool *changed)
       break;
     }
 
+  switch (GET_RTX_CLASS (code))
+    {
+    case RTX_BIN_ARITH:
+    case RTX_COMM_ARITH:
+      /* Call simplify_gen_binary with our updated operands in case they
+        are now constant and need to be wrapped with a (const:P ...).  */
+      validate_change (object, &XEXP (x, 0),
+                      cse_process_notes (XEXP (x, 0), object, changed), false);
+      validate_change (object, &XEXP (x, 1),
+                      cse_process_notes (XEXP (x, 1), object, changed), false);
+      return simplify_gen_binary (code, GET_MODE (x), XEXP (x, 0), XEXP (x, 
1));
+    default:
+      break;
+    }
+
   for (i = 0; i < GET_RTX_LENGTH (code); i++)
     if (fmt[i] == 'e')
       validate_change (object, &XEXP (x, i),
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