aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2014-08-07 08:12:04 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2014-08-07 08:12:04 +0000
commit044331a86cdee0427e7b8552307c9e83f7088979 (patch)
treed7ba08e9040a1712a5107f8572a9ad61c05b7f13 /gcc/fold-const.c
parentce597aedd79e646c4a5517505088d380239cbfa5 (diff)
downloadgcc-044331a86cdee0427e7b8552307c9e83f7088979.zip
gcc-044331a86cdee0427e7b8552307c9e83f7088979.tar.gz
gcc-044331a86cdee0427e7b8552307c9e83f7088979.tar.bz2
fold-const.c (fold_binary_loc): Add folding of (PTR0 - (PTR1 p+ A) -> (PTR0 - PTR1) - A.
* fold-const.c (fold_binary_loc): Add folding of (PTR0 - (PTR1 p+ A) -> (PTR0 - PTR1) - A. c/ * c-typeck.c (pointer_diff): Remove P - (P + CST) optimization. testsuite/ * gcc.dg/fold-reassoc-3.c: New test. From-SVN: r213700
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 7180662..d444769 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -10831,6 +10831,19 @@ fold_binary_loc (location_t loc,
if (tmp)
return fold_build2_loc (loc, PLUS_EXPR, type, tmp, arg01);
}
+ /* PTR0 - (PTR1 p+ A) -> (PTR0 - PTR1) - A, assuming PTR0 - PTR1
+ simplifies. */
+ else if (TREE_CODE (arg1) == POINTER_PLUS_EXPR)
+ {
+ tree arg10 = fold_convert_loc (loc, type,
+ TREE_OPERAND (arg1, 0));
+ tree arg11 = fold_convert_loc (loc, type,
+ TREE_OPERAND (arg1, 1));
+ tree tmp = fold_binary_loc (loc, MINUS_EXPR, type, arg0,
+ fold_convert_loc (loc, type, arg10));
+ if (tmp)
+ return fold_build2_loc (loc, MINUS_EXPR, type, tmp, arg11);
+ }
}
/* A - (-B) -> A + B */
if (TREE_CODE (arg1) == NEGATE_EXPR)