Commit ba00284c by Bin Cheng Committed by Bin Cheng

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
parent 8813f50d
2017-06-07 Bin Cheng <bin.cheng@arm.com> 2017-06-07 Bin Cheng <bin.cheng@arm.com>
* 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 <bin.cheng@arm.com>
* tree-affine.c (tree_to_aff_combination): Handle (T1)(X + X). * tree-affine.c (tree_to_aff_combination): Handle (T1)(X + X).
2017-06-07 Bin Cheng <bin.cheng@arm.com> 2017-06-07 Bin Cheng <bin.cheng@arm.com>
......
...@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see
#include "rtl.h" #include "rtl.h"
#include "tree.h" #include "tree.h"
#include "gimple.h" #include "gimple.h"
#include "ssa.h"
#include "tree-pretty-print.h" #include "tree-pretty-print.h"
#include "fold-const.h" #include "fold-const.h"
#include "tree-affine.h" #include "tree-affine.h"
...@@ -393,6 +394,30 @@ tree_to_aff_combination (tree expr, tree type, aff_tree *comb) ...@@ -393,6 +394,30 @@ tree_to_aff_combination (tree expr, tree type, aff_tree *comb)
tree_to_aff_combination (expr, type, comb); tree_to_aff_combination (expr, type, comb);
return; 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; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment