From 29e810b9094513da7c1644f7581bc79742accc51 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 3 Sep 2013 10:02:56 +0000 Subject: tree-affine.c (add_elt_to_tree): Fix association issue... 2013-09-03 Richard Biener * 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 --- gcc/tree-affine.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'gcc/tree-affine.c') 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. */ -- cgit v1.1