This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix PR 31521
- From: Diego Novillo <dnovillo at google dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 03 Aug 2007 09:06:53 -0400
- Subject: Fix PR 31521
I've applied and tested Andrew Pinski's patch for PR 31521. We were
missing an opportunity to convert a division into a shift because the
predicate test was too strict.
Bootstrapped and tested on x86_64, x86 and ppc64.
2007-08-02 Andrew Pinski <andrew_pinski@playstation.sony.com>
Diego Novillo <dnovillo@google.com>
PR 31521
* tree-vrp.c (simplify_div_or_mod_using_ranges): Also simplify
if the range includes 0.
testsuite/ChangeLog
PR 31521
* gcc.dg/tree-ssa/pr31521.c: New test.
Index: tree-vrp.c
===================================================================
--- tree-vrp.c (revision 127174)
+++ tree-vrp.c (working copy)
@@ -5541,7 +5541,7 @@ simplify_div_or_mod_using_ranges (tree s
{
bool sop = false;
- val = compare_range_with_value (GT_EXPR, vr, integer_zero_node, &sop);
+ val = compare_range_with_value (GE_EXPR, vr, integer_zero_node, &sop);
if (val
&& sop
Index: testsuite/gcc.dg/tree-ssa/pr31521.c
===================================================================
--- testsuite/gcc.dg/tree-ssa/pr31521.c (revision 0)
+++ testsuite/gcc.dg/tree-ssa/pr31521.c (revision 0)
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-vrp1" } */
+
+void fail(void) __attribute__((noreturn));
+int bar(int);
+
+int foo(int x) {
+ int i;
+ int s = 0;
+
+ if (x <= 0) fail();
+ for (i = 0; i < x; ++i) {
+ /* This division by 4 should be replaced with >> 2. */
+ s += bar(i/4);
+ }
+ return s;
+}
+
+/* { dg-final { scan-tree-dump-times " = i_.* >> 2" 1 "vrp1" } } */
+/* { dg-final { cleanup-tree-dump "vrp1" } } */