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
This commit is contained in:
Richard Biener 2013-09-03 10:02:56 +00:00 committed by Richard Biener
parent dbfc28948e
commit 29e810b909
2 changed files with 26 additions and 14 deletions

View file

@ -1,3 +1,9 @@
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.
2013-09-03 Richard Biener <rguenther@suse.de>
PR middle-end/57656

View file

@ -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. */