diff options
author | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-08-11 07:44:45 +0000 |
---|---|---|
committer | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-08-11 07:44:45 +0000 |
commit | 3cea28d762bf7cd8d486d9add64299b8d3a4ee45 (patch) | |
tree | ab98ba9561a282ffc55741231132e99c53814c2a | |
parent | 61179c97e8930e0cd465d29f7aff7390b7b88140 (diff) | |
download | ppe42-gcc-3cea28d762bf7cd8d486d9add64299b8d3a4ee45.tar.gz ppe42-gcc-3cea28d762bf7cd8d486d9add64299b8d3a4ee45.zip |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@116079 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/simplify-rtx.c | 17 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/pr28651.c | 24 |
4 files changed, 44 insertions, 9 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d42b0aa3f4a..92fd1fe42f7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +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. + 2006-08-10 Eric Botcazou <ebotcazou@adacore.com> * tree.c (build1_stat): Also propagate the TREE_CONSTANT and diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 3f627e5308a..8c437e483df 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -3733,19 +3733,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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 44a48940b89..3bc320f9690 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-08-11 Richard Guenther <rguenther@suse.de> + + PR middle-end/28651 + * gcc.c-torture/execute/pr28651.c: New testcase. + 2006-08-10 Eric Botcazou <ebotcazou@adacore.com> * gnat.dg/specs/static_initializer.ads: New test. diff --git a/gcc/testsuite/gcc.c-torture/execute/pr28651.c b/gcc/testsuite/gcc.c-torture/execute/pr28651.c new file mode 100644 index 00000000000..1262f9f625e --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr28651.c @@ -0,0 +1,24 @@ +extern void abort (void); +int +foo (unsigned int u) +{ + return (int)(u + 4) < (int)u; +} + +int +main (int argc, char *argv[]) +{ + unsigned int u; + + /* Run with no arguments so u will be MAX_INT and the optimizers + won't know its value. */ + if (argc > 1) + u = 1; + else + u = 0x7fffffff; + + if (foo (u) == 0) + abort(); + return 0; +} + |