]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
2009-04-01 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 1 Apr 2009 13:59:53 +0000 (13:59 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 1 Apr 2009 13:59:53 +0000 (13:59 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@145403 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/fold-plusmult-2.c [new file with mode: 0644]

index 54cad4cddc0e525c23d86653f9bf92e825761185..f4b1e568f5a0105c668e694d8dd11d8b772b9924 100644 (file)
@@ -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
index ec0695414124b9569930c5d4088a7ffdcde39401..9c1a46322b08a839535e6ca7d2159e39680e7b2e 100644 (file)
@@ -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),
index 5aef381d4573379cc7da1c2b1f5ba4f86c1e292f..5462bead4bd335ba49d9a4bdcd263708d9a62711 100644 (file)
@@ -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 (file)
index 0000000..fd53762
--- /dev/null
@@ -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" } } */