aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-affine.c
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2013-09-03 10:02:56 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2013-09-03 10:02:56 +0000
commit29e810b9094513da7c1644f7581bc79742accc51 (patch)
tree306dbde1bee536787e4b291fdb877dabd8dcd151 /gcc/tree-affine.c
parentdbfc28948e3e382cc1e6409087e963ba2266d0b9 (diff)
downloadgcc-29e810b9094513da7c1644f7581bc79742accc51.zip
gcc-29e810b9094513da7c1644f7581bc79742accc51.tar.gz
gcc-29e810b9094513da7c1644f7581bc79742accc51.tar.bz2
tree-affine.c (add_elt_to_tree): Fix association issue...
2013-09-03 Richard Biener <rguenther@suse.de> * tree-affine.c (add_elt_to_tree): Fix association issue, avoid useless converts and make sure to always return a properly typed result. From-SVN: r202205
Diffstat (limited to 'gcc/tree-affine.c')
-rw-r--r--gcc/tree-affine.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/gcc/tree-affine.c b/gcc/tree-affine.c
index 914b3d7..81da521 100644
--- a/gcc/tree-affine.c
+++ b/gcc/tree-affine.c
@@ -381,36 +381,43 @@ add_elt_to_tree (tree expr, tree type, tree elt, double_int scale,
if (scale.is_minus_one ()
&& POINTER_TYPE_P (TREE_TYPE (elt)))
{
- elt = fold_build1 (NEGATE_EXPR, sizetype, convert_to_ptrofftype (elt));
+ elt = convert_to_ptrofftype (elt);
+ elt = fold_build1 (NEGATE_EXPR, TREE_TYPE (elt), elt);
scale = double_int_one;
}
if (scale.is_one ())
{
if (!expr)
- return elt;
+ {
+ if (POINTER_TYPE_P (TREE_TYPE (elt)))
+ return elt;
+ else
+ return fold_convert (type1, elt);
+ }
if (POINTER_TYPE_P (TREE_TYPE (expr)))
- return fold_build_pointer_plus (expr, convert_to_ptrofftype (elt));
+ return fold_build_pointer_plus (expr, elt);
if (POINTER_TYPE_P (TREE_TYPE (elt)))
- return fold_build_pointer_plus (elt, convert_to_ptrofftype (expr));
+ return fold_build_pointer_plus (elt, expr);
return fold_build2 (PLUS_EXPR, type1,
- fold_convert (type1, expr),
- fold_convert (type1, elt));
+ expr, fold_convert (type1, elt));
}
if (scale.is_minus_one ())
{
if (!expr)
- return fold_build1 (NEGATE_EXPR, TREE_TYPE (elt), elt);
+ return fold_build1 (NEGATE_EXPR, type1,
+ fold_convert (type1, elt));
if (POINTER_TYPE_P (TREE_TYPE (expr)))
- return fold_build_pointer_plus
- (expr, convert_to_ptrofftype
- (fold_build1 (NEGATE_EXPR, TREE_TYPE (elt), elt)));
+ {
+ elt = convert_to_ptrofftype (elt);
+ elt = fold_build1 (NEGATE_EXPR, TREE_TYPE (elt), elt);
+ return fold_build_pointer_plus (expr, elt);
+ }
return fold_build2 (MINUS_EXPR, type1,
- fold_convert (type1, expr),
- fold_convert (type1, elt));
+ expr, fold_convert (type1, elt));
}
elt = fold_convert (type1, elt);
@@ -434,8 +441,7 @@ add_elt_to_tree (tree expr, tree type, tree elt, double_int scale,
elt = fold_build1 (NEGATE_EXPR, type1, elt);
return fold_build_pointer_plus (expr, elt);
}
- return fold_build2 (code, type1,
- fold_convert (type1, expr), elt);
+ return fold_build2 (code, type1, expr, elt);
}
/* Makes tree from the affine combination COMB. */