aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2008-04-29 15:59:43 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2008-04-29 15:59:43 +0000
commit1447bf0556ad0cb300aabd1b883fedee314b6fca (patch)
treec9e456f594c1a551adbd796e105d2374bafd6819 /gcc/fold-const.c
parent59e6913ad1743f76ca98421b9b5614caf96a7cf7 (diff)
downloadgcc-1447bf0556ad0cb300aabd1b883fedee314b6fca.zip
gcc-1447bf0556ad0cb300aabd1b883fedee314b6fca.tar.gz
gcc-1447bf0556ad0cb300aabd1b883fedee314b6fca.tar.bz2
re PR tree-optimization/15255 ([tree-ssa] a * 2 + a * 2 is not converted to a * 4)
2008-04-29 Richard Guenther <rguenther@suse.de> PR middle-end/15255 * fold-const.c (fold_binary): Fold (A + A) * C to A * 2*C. * gcc.dg/fold-plusmult.c: New testcase. From-SVN: r134798
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index aae2037..b4645ca 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -10154,6 +10154,17 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
return fold_build2 (LSHIFT_EXPR, type, op1,
TREE_OPERAND (arg0, 1));
+ /* (A + A) * C -> A * 2 * C */
+ if (TREE_CODE (arg0) == PLUS_EXPR
+ && TREE_CODE (arg1) == INTEGER_CST
+ && operand_equal_p (TREE_OPERAND (arg0, 0),
+ TREE_OPERAND (arg0, 1), 0))
+ return fold_build2 (MULT_EXPR, type,
+ omit_one_operand (type, TREE_OPERAND (arg0, 0),
+ TREE_OPERAND (arg0, 1)),
+ fold_build2 (MULT_EXPR, type,
+ build_int_cst (type, 2) , arg1));
+
strict_overflow_p = false;
if (TREE_CODE (arg1) == INTEGER_CST
&& 0 != (tem = extract_muldiv (op0, arg1, code, NULL_TREE,