re PR tree-optimization/66863 (wrong code at -Os and above on x86_64-linux-gnu)
authorRichard Biener <rguenther@suse.de>
Tue, 14 Jul 2015 11:39:14 +0000 (11:39 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 14 Jul 2015 11:39:14 +0000 (11:39 +0000)
2015-07-14  Richard Biener  <rguenther@suse.de>

PR tree-optimization/66863
* tree-vrp.c (register_edge_assert_for_2): Properly restrict
what we record for conversion use stmt lhs inequalities.

* gcc.dg/torture/pr66863.c: New testcase.

From-SVN: r225768

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr66863.c [new file with mode: 0644]
gcc/tree-vrp.c

index b3f695768dcd24925fa06d24bf7069eadf073790..e9773897bc87c17f9de6117feac7428d243d1d5d 100644 (file)
@@ -1,3 +1,9 @@
+2015-07-14  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/66863
+       * tree-vrp.c (register_edge_assert_for_2): Properly restrict
+       what we record for conversion use stmt lhs inequalities.
+
 2015-07-14  Richard Biener  <rguenther@suse.de>
 
        * genmatch.c (dt_node::gen_kids_1): Fix case label indenting.
index 2e32e14527e5b753a5401771dd806c335f724aa7..198775602a9e1ba4c86c08e28dca4898268e0234 100644 (file)
@@ -1,3 +1,8 @@
+2015-07-14  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/66863
+       * gcc.dg/torture/pr66863.c: New testcase.
+
 2015-07-13  Patrick Palka  <ppalka@gcc.gnu.org>
 
        PR c++/65186
diff --git a/gcc/testsuite/gcc.dg/torture/pr66863.c b/gcc/testsuite/gcc.dg/torture/pr66863.c
new file mode 100644 (file)
index 0000000..22cb397
--- /dev/null
@@ -0,0 +1,25 @@
+/* { dg-do run } */
+
+int a, b;
+
+int
+fn1 (int p1)
+{
+  if (p1 < -2147483647) 
+    return 0;
+  else 
+    return 1;
+}
+
+int
+fn2 (int p1, short p2)
+{
+  return p2 ? p1 % p2 : 0; 
+}
+
+int
+main ()
+{
+  b = fn2 (fn1 (a), a);
+  return 0;
+}
index 8b2235c0fa857aebbe701e4fb496e6860d9679e8..795b02728aeac7c5709295a9310c1d86b047f81c 100644 (file)
@@ -5381,7 +5381,17 @@ register_edge_assert_for_2 (tree name, edge e, gimple_stmt_iterator bsi,
              cst = int_const_binop (code, val, cst);
            }
          else if (CONVERT_EXPR_CODE_P (code))
-           cst = fold_convert (TREE_TYPE (name2), val);
+           {
+             /* For truncating conversions require that the constant
+                fits in the truncated type if we are going to record
+                an inequality.  */
+             if (comp_code == NE_EXPR
+                 && (TYPE_PRECISION (TREE_TYPE (name2))
+                     < TYPE_PRECISION (TREE_TYPE (name)))
+                 && ! int_fits_type_p (val, TREE_TYPE (name2)))
+               continue;
+             cst = fold_convert (TREE_TYPE (name2), val);
+           }
          else
            continue;