]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
postreload: Fix up postreload combine [PR93402]
authorJakub Jelinek <jakub@redhat.com>
Thu, 23 Jan 2020 19:08:22 +0000 (20:08 +0100)
committerJakub Jelinek <jakub@redhat.com>
Thu, 13 Feb 2020 20:21:43 +0000 (21:21 +0100)
The following testcase is miscompiled, because the postreload pass changes:
-(insn 14 13 23 2 (parallel [
-            (set (reg:DI 1 dx [94])
-                (plus:DI (reg:DI 1 dx [95])
-                    (reg:DI 5 di [92])))
-            (clobber (reg:CC 17 flags))
-        ]) "pr93402.c":8:30 186 {*adddi_1}
-     (expr_list:REG_EQUAL (plus:DI (reg:DI 5 di [92])
-            (const_int 111111111111 [0x19debd01c7]))
-        (nil)))
-(insn 23 14 25 2 (set (reg:SI 0 ax)
+(insn 23 13 25 2 (set (reg:SI 0 ax)
         (const_int 0 [0])) "pr93402.c":10:1 67 {*movsi_internal}
      (nil))
 (insn 25 23 26 2 (use (reg:SI 0 ax)) "pr93402.c":10:1 -1
      (nil))
-(insn 26 25 35 2 (use (reg:DI 1 dx)) "pr93402.c":10:1 -1
+(insn 26 25 35 2 (use (plus:DI (reg:DI 1 dx [95])
+            (reg:DI 5 di [92]))) "pr93402.c":10:1 -1
      (nil))
A USE insn is not a normal insn and verify_changes called from
apply_change_group is happy about any changes into it.
The following patch avoids this optimization if we were to change
the USE operand (this routine only changes a reg into (plus reg reg2)).

2020-01-23  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/93402
* postreload.c (reload_combine_recognize_pattern): Don't try to adjust
USE insns.

* gcc.c-torture/execute/pr93402.c: New test.

gcc/ChangeLog
gcc/postreload.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr93402.c [new file with mode: 0644]

index 1916dab20d19caa2bf6b4163933235a30272b907..2029c67bf0204d87b27ce0e5a02073e9337f249c 100644 (file)
@@ -1,3 +1,12 @@
+2020-02-13  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2020-01-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/93402
+       * postreload.c (reload_combine_recognize_pattern): Don't try to adjust
+       USE insns.
+
 2020-02-11  Tamar Christina  <tamar.christina@arm.com>
 
        Backport from mainline
index 728aa9b0ed5a18b67ea7f89bd217cd0696d85b7c..b76c7b0b758f3d58494a5d07a848cff889e734e0 100644 (file)
@@ -1081,6 +1081,10 @@ reload_combine_recognize_pattern (rtx_insn *insn)
       struct reg_use *use = reg_state[regno].reg_use + i;
       if (GET_MODE (*use->usep) != mode)
        return false;
+      /* Don't try to adjust (use (REGX)).  */
+      if (GET_CODE (PATTERN (use->insn)) == USE
+         && &XEXP (PATTERN (use->insn), 0) == use->usep)
+       return false;
     }
 
   /* Look for (set (REGX) (CONST_INT))
index 1dcf894a92a087cfccd08b220bf9eb2ef2d15bec..bec5eba503327b968bdca1da2aebee966aff62d6 100644 (file)
@@ -1,3 +1,11 @@
+2020-02-13  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2020-01-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/93402
+       * gcc.c-torture/execute/pr93402.c: New test.
+
 2020-02-11  Tamar Christina  <tamar.christina@arm.com>
 
        Backport from mainline
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr93402.c b/gcc/testsuite/gcc.c-torture/execute/pr93402.c
new file mode 100644 (file)
index 0000000..6487797
--- /dev/null
@@ -0,0 +1,21 @@
+/* PR rtl-optimization/93402 */
+
+struct S { unsigned int a; unsigned long long b; };
+
+__attribute__((noipa)) struct S
+foo (unsigned long long x)
+{
+  struct S ret;
+  ret.a = 0;
+  ret.b = x * 11111111111ULL + 111111111111ULL;
+  return ret;
+}
+
+int
+main ()
+{
+  struct S a = foo (1);
+  if (a.a != 0 || a.b != 122222222222ULL)
+    __builtin_abort ();
+  return 0;
+}