From 1529557042a909fae4653e476e71c7990ac6f445 Mon Sep 17 00:00:00 2001 From: amker Date: Wed, 7 Jun 2017 10:47:26 +0000 Subject: [PATCH] * tree-affine.c (tree_to_aff_combination): Handle (T1)(X + X). git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@248956 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 4 ++++ gcc/tree-affine.c | 27 +++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4222568edcc..b2d723250d4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,9 @@ 2017-06-07 Bin Cheng + * tree-affine.c (tree_to_aff_combination): Handle (T1)(X + X). + +2017-06-07 Bin Cheng + (aff_combination_expand): Move (T1)(X *+- CST) simplification to ... (tree_to_aff_combination): ... here. diff --git a/gcc/tree-affine.c b/gcc/tree-affine.c index cbe2bdb4b6a..d2983ab5e8a 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; -- 2.11.4.GIT