summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlaw <law@138bc75d-0d04-0410-961f-82ee72b054a4>2013-05-24 17:13:38 +0000
committerlaw <law@138bc75d-0d04-0410-961f-82ee72b054a4>2013-05-24 17:13:38 +0000
commit65a8f1a1cd31f5b564a7e41e9146c638aaeb0942 (patch)
treea8e876918b34462b5e7b7c8a733d2aeed5023f1d
parent72524e9190a393c0bb9f236e40b0ff45cb499756 (diff)
downloadgcc-65a8f1a1cd31f5b564a7e41e9146c638aaeb0942.tar.gz
PR tree-optimization/57124
* tree-vrp.c (simplify_cond_using_ranges): Only simplify a conversion feeding a condition if the range has an overflow if -fstrict-overflow. Add warnings for when we do make the transformation. PR tree-optimization/57124 * gcc.c-torture/execute/pr57124.c: New test. * gcc.c-torture/execute/pr57124.x: Set -fno-strict-overflow. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@199305 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/pr57124.c27
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/pr57124.x2
-rw-r--r--gcc/tree-vrp.c26
5 files changed, 68 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f5cffee34cc..3d665c3d9d9 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2013-05-24 Jeff Law <law@redhat.com>
+
+ PR tree-optimization/57124
+ * tree-vrp.c (simplify_cond_using_ranges): Only simplify a
+ conversion feeding a condition if the range has an overflow
+ if -fstrict-overflow. Add warnings for when we do make the
+ transformation.
+
2013-05-24 Dehao Chen <dehao@google.com>
* gcc/tree-cfg.c (locus_discrim_map): Fix the typo.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index af4b16e2f11..8c2e2939561 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2013-05-24 Jeff Law <law@redhat.com>
+
+ PR tree-optimization/57124
+ * gcc.c-torture/execute/pr57124.c: New test.
+ * gcc.c-torture/execute/pr57124.x: Set -fno-strict-overflow.
+
2013-05-24 Martin Jambor <mjambor@suse.cz>
PR tree-optimization/57294
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr57124.c b/gcc/testsuite/gcc.c-torture/execute/pr57124.c
new file mode 100644
index 00000000000..835d249df6a
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr57124.c
@@ -0,0 +1,27 @@
+__attribute__ ((noinline))
+foo(short unsigned int *p1, short unsigned int *p2)
+{
+ short unsigned int x1, x4;
+ int x2, x3, x5, x6;
+ unsigned int x7;
+
+ x1 = *p1;
+ x2 = (int) x1;
+ x3 = x2 * 65536;
+ x4 = *p2;
+ x5 = (int) x4;
+ x6 = x3 + x4;
+ x7 = (unsigned int) x6;
+ if (x7 <= 268435455U)
+ abort ();
+ exit (0);
+}
+
+main()
+{
+ short unsigned int x, y;
+ x = -5;
+ y = -10;
+ foo (&x, &y);
+}
+
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr57124.x b/gcc/testsuite/gcc.c-torture/execute/pr57124.x
new file mode 100644
index 00000000000..d8cacbec590
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr57124.x
@@ -0,0 +1,2 @@
+set additional_flags "-fno-strict-overflow"
+return 0
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 66c50ca4b31..ec7ef8f7548 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -8670,8 +8670,32 @@ simplify_cond_using_ranges (gimple stmt)
&& range_fits_type_p (vr,
TYPE_PRECISION (TREE_TYPE (op0)),
TYPE_UNSIGNED (TREE_TYPE (op0)))
- && int_fits_type_p (op1, TREE_TYPE (innerop)))
+ && int_fits_type_p (op1, TREE_TYPE (innerop))
+ /* The range must not have overflowed, or if it did overflow
+ we must not be wrapping/trapping overflow and optimizing
+ with strict overflow semantics. */
+ && ((!is_negative_overflow_infinity (vr->min)
+ && !is_positive_overflow_infinity (vr->max))
+ || TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (innerop))))
{
+ /* If the range overflowed and the user has asked for warnings
+ when strict overflow semantics were used to optimize code,
+ issue an appropriate warning. */
+ if ((is_negative_overflow_infinity (vr->min)
+ || is_positive_overflow_infinity (vr->max))
+ && issue_strict_overflow_warning (WARN_STRICT_OVERFLOW_CONDITIONAL))
+ {
+ location_t location;
+
+ if (!gimple_has_location (stmt))
+ location = input_location;
+ else
+ location = gimple_location (stmt);
+ warning_at (location, OPT_Wstrict_overflow,
+ "assuming signed overflow does not occur when "
+ "simplifying conditional");
+ }
+
tree newconst = fold_convert (TREE_TYPE (innerop), op1);
gimple_cond_set_lhs (stmt, innerop);
gimple_cond_set_rhs (stmt, newconst);