+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).
#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"
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;