This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH GCC][2/4]Simplify (cond (cmp (convert (x), c1), x, c2)) into (minmax (x, c))
On Thu, Oct 27, 2016 at 2:58 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Tue, Oct 25, 2016 at 1:21 PM, Bin Cheng <Bin.Cheng@arm.com> wrote:
>> Hi,
>> Second patch optimizing (cond (cmp (convert (x), c1), x, c2)) into (minmax (x, c)). As commented in patch, this is done if:
>>
>> + 1) Comparison's operands are promoted from smaller type.
>> + 2) Const c1 equals to c2 after canonicalizing comparison.
>> + 3) Comparison has tree code LT, LE, GT or GE.
>> + This specific pattern is needed when (cmp (convert x) c) may not
>> + be simplified by comparison patterns because of multiple uses of
>> + x. It also makes sense here because simplifying across multiple
>> + referred var is always benefitial for complicated cases.
>>
>> It also adds call to fold_stmt in tree-if-conv.c so that generated cond_expr statement has its chance to be simplified.
>
> So this sounds like the fold-const.c code. Why only for GIMPLE btw?
> Thus, can you make sure you covered
> all cases fold-const.c did and remove the corresponding code there?
Hmm, no, this patch only adds simplification which is not done by GCC
at the moment. I didn't look into existing simplification from
fold-const.c when writing this one, however, I will look into it see
if it can be moved to match.pd, either along with this pattern or as a
separated ones.
Thanks,
bin
>
> Thanks,
> Richard.
>
>> Bootstrap and test on x86_64 and AArch64. It introduces below failure on both x86_64 and AArch64:
>> FAIL: gcc.dg/vect/slp-cond-3.c
>> I believe it reveals defect in vect-slp. In call to fold_stmt in ifcvt, canonicalization transforms _145 = _95 <= _96 ? _149 : _147 into _145 = _95 > _96 ? _147 : _149. As a result, this stmt has different code to the first one of SLP instance. IMO, SLP should be improved to handle operands swapping, apparently, current support is not OK.
>>
>> It also introduces more failures on AArch64(probably other targets) as below:
>> FAIL: gcc.dg/vect/pr65947-1.c -flto -ffat-lto-objects scan-tree-dump-times vect "LOOP VECTORIZED" 2
>> FAIL: gcc.dg/vect/pr65947-1.c -flto -ffat-lto-objects scan-tree-dump-times vect "condition expression based on integer induction." 4
>> FAIL: gcc.dg/vect/pr65947-1.c scan-tree-dump-times vect "LOOP VECTORIZED" 2
>> FAIL: gcc.dg/vect/pr65947-1.c scan-tree-dump-times vect "condition expression based on integer induction." 4
>> FAIL: gcc.dg/vect/pr65947-13.c -flto -ffat-lto-objects scan-tree-dump-times vect "LOOP VECTORIZED" 2
>> FAIL: gcc.dg/vect/pr65947-13.c scan-tree-dump-times vect "LOOP VECTORIZED" 2
>> FAIL: gcc.dg/vect/pr65947-4.c -flto -ffat-lto-objects scan-tree-dump-times vect "LOOP VECTORIZED" 2
>> FAIL: gcc.dg/vect/pr65947-4.c -flto -ffat-lto-objects scan-tree-dump-times vect "condition expression based on integer induction." 4
>> FAIL: gcc.dg/vect/pr65947-4.c scan-tree-dump-times vect "LOOP VECTORIZED" 2
>> FAIL: gcc.dg/vect/pr65947-4.c scan-tree-dump-times vect "condition expression based on integer induction." 4
>> FAIL: gcc.dg/vect/pr77503.c -flto -ffat-lto-objects scan-tree-dump vect "vectorized 1 loops"
>> FAIL: gcc.dg/vect/pr77503.c scan-tree-dump vect "vectorized 1 loops"
>> FAIL: gcc.dg/vect/vect-pr69848.c -flto -ffat-lto-objects scan-tree-dump vect "vectorized 1 loops"
>> FAIL: gcc.dg/vect/vect-pr69848.c scan-tree-dump vect "vectorized 1 loops"
>> Again, these failures reveal a defect in vectorizer that operand swapping is not supported for COND_REDUCTION.
>>
>> I will send another two patches independent to this patch set resolving these failures. Is this OK?
>>
>> Thanks,
>> bin
>>
>> 2016-10-21 Bin Cheng <bin.cheng@arm.com>
>>
>> * tree-if-conv.c (ifcvt_follow_ssa_use_edges): New func.
>> (predicate_scalar_phi): Call fold_stmt using the new valueize func.
>> * match.pd ((cond (cmp (convert (x), c1), x, c2)) -> (minmax (x, c))):
>> New pattern.
>>
>> gcc/testsuite/ChangeLog
>> 2016-10-21 Bin Cheng <bin.cheng@arm.com>
>>
>> * gcc.dg/fold-condcmpconv-1.c: New test.
>> * gcc.dg/fold-condcmpconv-2.c: New test.