aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2013-10-21 11:34:04 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2013-10-21 11:34:04 +0000
commitd480e6a572799f809744075cdf447f959753b173 (patch)
treed39c87a3db103241526f21769916ac517ea36d8f /gcc/fold-const.c
parent54f9aba03140c7cdace8ff3c6847af855764656f (diff)
downloadgcc-d480e6a572799f809744075cdf447f959753b173.zip
gcc-d480e6a572799f809744075cdf447f959753b173.tar.gz
gcc-d480e6a572799f809744075cdf447f959753b173.tar.bz2
re PR middle-end/58742 (pointer arithmetic simplification)
2013-10-21 Richard Biener <rguenther@suse.de> PR middle-end/58742 * fold-const.c (fold_binary_loc): Fold ((T) (X /[ex] C)) * C to (T) X for sign-changing conversions (or no conversion). * c-c++-common/fold-divmul-1.c: New testcase. From-SVN: r203890
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index c4c09b6..2a18410 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -11002,6 +11002,13 @@ fold_binary_loc (location_t loc,
fold_build2_loc (loc, MULT_EXPR, type,
build_int_cst (type, 2) , arg1));
+ /* ((T) (X /[ex] C)) * C cancels out if the conversion is
+ sign-changing only. */
+ if (TREE_CODE (arg1) == INTEGER_CST
+ && TREE_CODE (arg0) == EXACT_DIV_EXPR
+ && operand_equal_p (arg1, TREE_OPERAND (arg0, 1), 0))
+ return fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
+
strict_overflow_p = false;
if (TREE_CODE (arg1) == INTEGER_CST
&& 0 != (tem = extract_muldiv (op0, arg1, code, NULL_TREE,