]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: [multiple changes]
authorRichard Guenther <rguenther@suse.de>
Thu, 25 Jan 2007 19:05:19 +0000 (19:05 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 25 Jan 2007 19:05:19 +0000 (19:05 +0000)
2007-01-25  Richard Guenther  <rguenther@suse.de>

Backport from mainline:
2006-08-11  Richard Guenther  <rguenther@suse.de>

PR middle-end/28651
* simplify-rtx.c (simplify_const_relational_operation):
Simplify A CMP B to A - B CMP 0 only for EQ and NE comparison
codes.

* gcc.c-torture/execute/pr28651.c: New testcase.

2006-08-14  Richard Guenther  <rguenther@suse.de>

PR testsuite/28703
* gcc.c-torture/execute/pr28651.c: Do not use argc
to avoid optimization, instead forbid inlining.

From-SVN: r121181

gcc/ChangeLog
gcc/simplify-rtx.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr28651.c [new file with mode: 0644]

index d46243d3c4961ebe9b15984c3d7f7e0cd3955a9b..08b8bc312ea230ab693ab20fd7837956cc97082f 100644 (file)
@@ -1,3 +1,13 @@
+2007-01-25  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline:
+       2006-08-11  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/28651
+       * simplify-rtx.c (simplify_const_relational_operation):
+       Simplify A CMP B to A - B CMP 0 only for EQ and NE comparison
+       codes.
+
 2007-01-20  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>
 
        * pa.c (output_move_double): Change array size of xoperands to 4.
index 175a2442038133dcc7a6dff8276a92469b30ef5f..4ba2d5a9554ce97e064881cc090b30c2b6091c56 100644 (file)
@@ -3017,19 +3017,18 @@ simplify_const_relational_operation (enum rtx_code code,
      a register or a CONST_INT, this can't help; testing for these cases will
      prevent infinite recursion here and speed things up.
 
-     If CODE is an unsigned comparison, then we can never do this optimization,
-     because it gives an incorrect result if the subtraction wraps around zero.
-     ANSI C defines unsigned operations such that they never overflow, and
-     thus such cases can not be ignored; but we cannot do it even for
-     signed comparisons for languages such as Java, so test flag_wrapv.  */
+     We can only do this for EQ and NE comparisons as otherwise we may
+     lose or introduce overflow which we cannot disregard as undefined as
+     we do not know the signedness of the operation on either the left or
+     the right hand side of the comparison.  */
 
-  if (!flag_wrapv && INTEGRAL_MODE_P (mode) && trueop1 != const0_rtx
+  if (INTEGRAL_MODE_P (mode) && trueop1 != const0_rtx
+      && (code == EQ || code == NE)
       && ! ((REG_P (op0) || GET_CODE (trueop0) == CONST_INT)
            && (REG_P (op1) || GET_CODE (trueop1) == CONST_INT))
       && 0 != (tem = simplify_binary_operation (MINUS, mode, op0, op1))
-      /* We cannot do this for == or != if tem is a nonzero address.  */
-      && ((code != EQ && code != NE) || ! nonzero_address_p (tem))
-      && code != GTU && code != GEU && code != LTU && code != LEU)
+      /* We cannot do this if tem is a nonzero address.  */
+      && ! nonzero_address_p (tem))
     return simplify_const_relational_operation (signed_condition (code),
                                                mode, tem, const0_rtx);
 
index 4cb94bfdcf46578e01214bdd0aa95a0a8bea43b3..0e0027d05f4cdbae105497e7455f5c5bd4392c9d 100644 (file)
@@ -1,3 +1,17 @@
+2007-01-25  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline:
+       2006-08-14  Richard Guenther  <rguenther@suse.de>
+
+       PR testsuite/28703
+       * gcc.c-torture/execute/pr28651.c: Do not use argc
+       to avoid optimization, instead forbid inlining.
+
+       2006-08-11  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/28651
+       * gcc.c-torture/execute/pr28651.c: New testcase.
+
 2007-01-15  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        PR testsuite/12325
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr28651.c b/gcc/testsuite/gcc.c-torture/execute/pr28651.c
new file mode 100644 (file)
index 0000000..e7ccf8e
--- /dev/null
@@ -0,0 +1,17 @@
+extern void abort (void);
+int __attribute__((noinline))
+foo (unsigned int u)
+{
+  return (int)(u + 4) < (int)u;
+}
+
+int
+main (int argc, char *argv[])
+{
+  unsigned int u = 0x7fffffff;
+
+  if (foo (u) == 0)
+    abort();
+  return 0;
+}
+