From ba00284cedbcb0b980af4e5e41f427581af64462 Mon Sep 17 00:00:00 2001 From: Bin Cheng Date: Wed, 7 Jun 2017 10:49:09 +0000 Subject: [PATCH] tree-affine.c (ssa.h): Include header file. * tree-affine.c (ssa.h): Include header file. (tree_to_aff_combination): Handle (T1)(X - CST) when inner type has wrapping overflow behavior. From-SVN: r248957 --- gcc/ChangeLog | 6 ++++++ gcc/tree-affine.c | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b2d723250d4..708051d9b49 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-06-07 Bin Cheng + + * tree-affine.c (ssa.h): Include header file. + (tree_to_aff_combination): Handle (T1)(X - CST) when inner type + has wrapping overflow behavior. + 2017-06-07 Bin Cheng * tree-affine.c (tree_to_aff_combination): Handle (T1)(X + X). diff --git a/gcc/tree-affine.c b/gcc/tree-affine.c index d2983ab5e8a..f7a5f121c9c 100644 --- a/gcc/tree-affine.c +++ b/gcc/tree-affine.c @@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "rtl.h" #include "tree.h" #include "gimple.h" +#include "ssa.h" #include "tree-pretty-print.h" #include "fold-const.h" #include "tree-affine.h" @@ -393,6 +394,30 @@ tree_to_aff_combination (tree expr, tree type, aff_tree *comb) tree_to_aff_combination (expr, type, comb); return; } + wide_int minv, maxv; + /* If inner type has wrapping overflow behavior, fold conversion + for below case: + (T1)(X - CST) -> (T1)X - (T1)CST + if X - CST doesn't overflow by range information. Also handle + (T1)(X + CST) as (T1)(X - (-CST)). */ + if (TYPE_UNSIGNED (itype) + && TYPE_OVERFLOW_WRAPS (itype) + && TREE_CODE (op0) == SSA_NAME + && TREE_CODE (op1) == INTEGER_CST + && icode != MULT_EXPR + && get_range_info (op0, &minv, &maxv) == VR_RANGE) + { + if (icode == PLUS_EXPR) + op1 = wide_int_to_tree (itype, wi::neg (op1)); + if (wi::geu_p (minv, op1)) + { + op0 = fold_convert (otype, op0); + op1 = fold_convert (otype, op1); + expr = fold_build2 (MINUS_EXPR, otype, op0, op1); + tree_to_aff_combination (expr, type, comb); + return; + } + } } } break; -- 2.30.2