]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/19068 ([3.3 only] Wrong code for MIN_EXPR and MAX_EXPR)
authorRoger Sayle <roger@eyesopen.com>
Sun, 19 Dec 2004 20:01:36 +0000 (20:01 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Sun, 19 Dec 2004 20:01:36 +0000 (20:01 +0000)
PR middle-end/19068
* expr.c (expand_expr_real_1) <MAX_EXPR>: Ensure that target, op0
and op1 are all registers (or constants) before expanding the RTL
comparison sequence [to avoid reg_overlap_mentioned (target, op1)].

* g++.dg/opt/max1.C: New test case.

From-SVN: r92386

gcc/ChangeLog
gcc/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/max1.C [new file with mode: 0644]

index c0a6bd10ebd370b336beed679499ceaf8aa664e6..a84cbe4603d2bad7ad2e414f6aa83d1b2e69c7f5 100644 (file)
@@ -1,3 +1,10 @@
+2004-12-19  Roger Sayle  <roger@eyesopen.com>
+
+       PR middle-end/19068
+       * expr.c (expand_expr_real_1) <MAX_EXPR>: Ensure that target, op0
+       and op1 are all registers (or constants) before expanding the RTL
+       comparison sequence [to avoid reg_overlap_mentioned (target, op1)].
+
 2004-12-18  Eric Botcazou  <ebotcazou@libertysurf.fr>
 
        PR rtl-optimization/16968
index aa80ae63f46bbacaf71ff48df441a541b28c773c..fcb5b0c78d68f3d611b0274a23e2f05e3dcd5710 100644 (file)
@@ -8107,7 +8107,7 @@ expand_expr_real (tree exp, rtx target, enum machine_mode tmode,
       /* At this point, a MEM target is no longer useful; we will get better
         code without it.  */
 
-      if (GET_CODE (target) == MEM)
+      if (! REG_P (target))
        target = gen_reg_rtx (mode);
 
       /* If op1 was placed in target, swap op0 and op1.  */
@@ -8118,6 +8118,11 @@ expand_expr_real (tree exp, rtx target, enum machine_mode tmode,
          op1 = tem;
        }
 
+      /* We generate better code and avoid problems with op1 mentioning
+        target by forcing op1 into a pseudo if it isn't a constant.  */
+      if (! CONSTANT_P (op1))
+       op1 = force_reg (mode, op1);
+
       if (target != op0)
        emit_move_insn (target, op0);
 
index 505f5fa33707a9e6e1889d3948278146b6497416..d3b6dcd2d145364a3f7da9b905f7d5116010f010 100644 (file)
@@ -1,3 +1,8 @@
+2004-12-19  Roger Sayle  <roger@eyesopen.com>
+
+       PR middle-end/19068
+       * g++.dg/opt/max1.C: New test case.
+
 2004-12-18  Jakub Jelinek  <jakub@redhat.com>
 
        * gcc.c-torture/execute/20041218-1.c: New test.
diff --git a/gcc/testsuite/g++.dg/opt/max1.C b/gcc/testsuite/g++.dg/opt/max1.C
new file mode 100644 (file)
index 0000000..714116b
--- /dev/null
@@ -0,0 +1,29 @@
+/* PR middle-end/19068 */
+/* Test case by Andrew Pinski <pinskia@physics.uc.edu> */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+extern "C" void abort (void);
+
+long fff[10];
+
+void f(long a)
+{
+  int i;
+  a =  *((long*)(a+5)) >? *((long*)(a+1)); 
+
+  for(i=0;i<10;i++)
+   fff[i] = a;
+}
+
+int main(void)
+{
+  int i;
+  long a[2] = {10,5};
+  f((long)(&a)-1);
+  for(i = 0;i<10;i++)
+   if (fff[i]!=10)
+    abort ();
+  return 0;
+}
+