aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2009-04-01 13:59:53 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2009-04-01 13:59:53 +0000
commit299b87f8a21c1ae2611434529c8c4dfc4c291d95 (patch)
tree68e3daf36617195cce79f5f8595598552dae258e /gcc
parentb85eb797e2ffda39def175285b334b721c0b2b4f (diff)
downloadgcc-299b87f8a21c1ae2611434529c8c4dfc4c291d95.zip
gcc-299b87f8a21c1ae2611434529c8c4dfc4c291d95.tar.gz
gcc-299b87f8a21c1ae2611434529c8c4dfc4c291d95.tar.bz2
fold-const.c (fold_plusminus_mult_expr): Do not fold i * 4 + 2 to (i * 2 + 1) * 2.
2009-04-01 Richard Guenther <rguenther@suse.de> * fold-const.c (fold_plusminus_mult_expr): Do not fold i * 4 + 2 to (i * 2 + 1) * 2. * gcc.dg/fold-plusmult-2.c: New testcase. From-SVN: r145403
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/fold-const.c6
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/fold-plusmult-2.c20
4 files changed, 34 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 54cad4cd..f4b1e56 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2009-04-01 Richard Guenther <rguenther@suse.de>
+
+ * fold-const.c (fold_plusminus_mult_expr): Do not fold
+ i * 4 + 2 to (i * 2 + 1) * 2.
+
2009-04-01 Jakub Jelinek <jakub@redhat.com>
PR c/37772
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index ec06954..9c1a463 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -7466,7 +7466,11 @@ fold_plusminus_mult_expr (enum tree_code code, tree type, tree arg0, tree arg1)
else
maybe_same = arg11;
- if (exact_log2 (abs (int11)) > 0 && int01 % int11 == 0)
+ if (exact_log2 (abs (int11)) > 0 && int01 % int11 == 0
+ /* The remainder should not be a constant, otherwise we
+ end up folding i * 4 + 2 to (i * 2 + 1) * 2 which has
+ increased the number of multiplications necessary. */
+ && TREE_CODE (arg10) != INTEGER_CST)
{
alt0 = fold_build2 (MULT_EXPR, TREE_TYPE (arg00), arg00,
build_int_cst (TREE_TYPE (arg00),
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5aef381..5462bea 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2009-04-01 Richard Guenther <rguenther@suse.de>
+
+ * gcc.dg/fold-plusmult-2.c: New testcase.
+
2009-04-01 Jakub Jelinek <jakub@redhat.com>
PR c/37772
diff --git a/gcc/testsuite/gcc.dg/fold-plusmult-2.c b/gcc/testsuite/gcc.dg/fold-plusmult-2.c
new file mode 100644
index 0000000..fd53762
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-plusmult-2.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-original" } */
+
+int foo (int i)
+{
+ return 2 + i * 4;
+}
+
+/* We do _not_ want the above to be canonicalized to (i * 2 + 1) * 2. */
+
+int bar (int i)
+{
+ return 4 + i * 2;
+}
+
+/* But eventually this to be canonicalized to (i + 2) * 2. */
+
+/* { dg-final { scan-tree-dump "i \\\* 4 \\\+ 2" "original" } } */
+/* { dg-final { scan-tree-dump "\\\(i \\\+ 2\\\) \\\* 2" "original" } } */
+/* { dg-final { cleanup-tree-dump "original" } } */