[PATCH GCC8][30/33]Fold more type conversion into binary arithmetic operations
Richard Biener
richard.guenther@gmail.com
Thu May 11 11:02:00 GMT 2017
On Tue, Apr 18, 2017 at 12:53 PM, Bin Cheng <Bin.Cheng@arm.com> wrote:
> Hi,
> Simplification of (T1)(X *+- CST) is already implemented in aff_combination_expand,
> this patch moves it to tree_to_aff_combination. It also supports unsigned types
> if range information allows the transformation, as well as special case (T1)(X + X).
> Is it OK?
Can you first please simply move it?
+ /* In case X's type has wrapping overflow behavior, we can still
+ convert (T1)(X - CST) into (T1)X - (T1)CST if X - CST doesn't
+ overflow by range information. Also Convert (T1)(X + CST) as
+ if it's (T1)(X - (-CST)). */
+ if (TYPE_UNSIGNED (itype)
+ && TYPE_OVERFLOW_WRAPS (itype)
+ && TREE_CODE (op0) == SSA_NAME
+ && TREE_CODE (op1) == INTEGER_CST
+ && (icode == PLUS_EXPR || icode == MINUS_EXPR)
+ && get_range_info (op0, &minv, &maxv) == VR_RANGE)
+ {
+ if (icode == PLUS_EXPR)
+ op1 = fold_build1 (NEGATE_EXPR, itype, op1);
Negating -INF will produce -INF(OVF) which we don't want to have in our IL,
I suggest to use
op1 = wide_int_to_tree (itype, wi::neg (op1));
instead.
+ 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;
+ }
+ }
I think this is similar to a part of what Robin Dapp (sp?) is
proposing as fix for PR69526?
The same trick should work for (int)((unsigned)X - CST) with different
overflow checks
(you need to make sure the resulting expr does not overflow).
Richard.
> Thanks,
> bin
> 2017-04-11 Bin Cheng <bin.cheng@arm.com>
>
> * tree-affine.c: Include header file.
> (aff_combination_expand): Move (T1)(X *+- CST) simplification to ...
> (tree_to_aff_combination): ... here. Support (T1)(X + X) case, and
> unsigned type case if range information allows.
More information about the Gcc-patches
mailing list