diff options
author | Bin Cheng <bin.cheng@arm.com> | 2017-06-07 10:47:26 +0000 |
---|---|---|
committer | Bin Cheng <amker@gcc.gnu.org> | 2017-06-07 10:47:26 +0000 |
commit | 8813f50d2c8653bbc65450fd1244a85c1ba7902f (patch) | |
tree | e02b31da29b767a9a696edbd23a5c98011e7ba2d /gcc/tree-affine.c | |
parent | 1b92ccde2c059959ec7026e279dcd582438e6f4d (diff) | |
download | gcc-8813f50d2c8653bbc65450fd1244a85c1ba7902f.zip gcc-8813f50d2c8653bbc65450fd1244a85c1ba7902f.tar.gz gcc-8813f50d2c8653bbc65450fd1244a85c1ba7902f.tar.bz2 |
* tree-affine.c (tree_to_aff_combination): Handle (T1)(X + X).
From-SVN: r248956
Diffstat (limited to 'gcc/tree-affine.c')
-rw-r--r-- | gcc/tree-affine.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/gcc/tree-affine.c b/gcc/tree-affine.c index cbe2bdb..d2983ab5 100644 --- a/gcc/tree-affine.c +++ b/gcc/tree-affine.c @@ -375,17 +375,24 @@ tree_to_aff_combination (tree expr, tree type, aff_tree *comb) if ((icode == PLUS_EXPR || icode == MINUS_EXPR || icode == MULT_EXPR) && TREE_CODE (itype) == INTEGER_TYPE && TREE_CODE (otype) == INTEGER_TYPE - && TYPE_PRECISION (otype) > TYPE_PRECISION (itype) - && TYPE_OVERFLOW_UNDEFINED (itype) - && TREE_CODE (TREE_OPERAND (inner, 1)) == INTEGER_CST) + && TYPE_PRECISION (otype) > TYPE_PRECISION (itype)) { - /* Convert (T1)(X *+- CST) into (T1)X *+- (T1)CST if X's type has - undefined overflow behavior. */ - tree op0 = fold_convert (otype, TREE_OPERAND (inner, 0)); - tree op1 = fold_convert (otype, TREE_OPERAND (inner, 1)); - expr = fold_build2 (icode, otype, op0, op1); - tree_to_aff_combination (expr, type, comb); - return; + tree op0 = TREE_OPERAND (inner, 0), op1 = TREE_OPERAND (inner, 1); + + /* If inner type has undefined overflow behavior, fold conversion + for below two cases: + (T1)(X *+- CST) -> (T1)X *+- (T1)CST + (T1)(X + X) -> (T1)X + (T1)X. */ + if (TYPE_OVERFLOW_UNDEFINED (itype) + && (TREE_CODE (op1) == INTEGER_CST + || (icode == PLUS_EXPR && operand_equal_p (op0, op1, 0)))) + { + op0 = fold_convert (otype, op0); + op1 = fold_convert (otype, op1); + expr = fold_build2 (icode, otype, op0, op1); + tree_to_aff_combination (expr, type, comb); + return; + } } } break; |