summaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2012-03-13 13:47:35 +0000
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2012-03-13 13:47:35 +0000
commit7af97aed8584714fb048e16225c4a47b5612c12c (patch)
treea723864fdb306ca7d449b2c1a29153a13668ea83 /gcc/fold-const.c
parent2fa890cdd5a87419eeb3c259d8c147275df1df81 (diff)
downloadgcc-7af97aed8584714fb048e16225c4a47b5612c12c.tar.gz
2012-03-13 Richard Guenther <rguenther@suse.de>
PR middle-end/52134 * fold-const.c (fold_binary_loc): Fold (X * Y) & -(1 << CST) to X * Y if Y is a constant multiple of 1 << CST. * gcc.dg/pr52134.c: New testcase. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@185334 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 0f806752dd3..ab653ea074b 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -11398,6 +11398,20 @@ fold_binary_loc (location_t loc,
fold_convert_loc (loc, type, arg0));
}
+ /* Fold (X * Y) & -(1 << CST) to X * Y if Y is a constant
+ multiple of 1 << CST. */
+ if (TREE_CODE (arg1) == INTEGER_CST)
+ {
+ double_int cst1 = tree_to_double_int (arg1);
+ double_int ncst1 = double_int_ext (double_int_neg (cst1),
+ TYPE_PRECISION (TREE_TYPE (arg1)),
+ TYPE_UNSIGNED (TREE_TYPE (arg1)));
+ if (double_int_equal_p (double_int_and (cst1, ncst1), ncst1)
+ && multiple_of_p (type, arg0,
+ double_int_to_tree (TREE_TYPE (arg1), ncst1)))
+ return fold_convert_loc (loc, type, arg0);
+ }
+
/* For constants M and N, if M == (1LL << cst) - 1 && (N & M) == M,
((A & N) + B) & M -> (A + B) & M
Similarly if (N & M) == 0,