summaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
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 8faf77d8751..33467eb88f2 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -9528,6 +9528,13 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
fold_convert (sizetype, arg1),
fold_convert (sizetype, arg0)));
+ /* index +p PTR -> PTR +p index */
+ if (POINTER_TYPE_P (TREE_TYPE (arg1))
+ && INTEGRAL_TYPE_P (TREE_TYPE (arg0)))
+ return fold_build2 (POINTER_PLUS_EXPR, type,
+ fold_convert (type, arg1),
+ fold_convert (sizetype, arg0));
+
/* (PTR +p B) +p A -> PTR +p (B + A) */
if (TREE_CODE (arg0) == POINTER_PLUS_EXPR)
{