This is an archive of the discontinued LLVM Phabricator instance.

[X86] Fold bitcast(logic(bitcast(X), Y)) --> logic'(X, bitcast(Y)) for int-int bitcasts
ClosedPublic

Authored by RKSimon on Feb 6 2021, 8:20 AM.

Details

Summary

Extend the existing combine that handles bitcasting for fp-logic ops to also help remove logic ops across bitcasts to/from the same integer types.

This helps improve AVX512 predicate handling for D/Q logic ops and also allows DAGCombine's scalarizeExtractedBinop to remove some annoying gpr->simd->gpr transfers.

Diff Detail

Event Timeline

RKSimon created this revision.Feb 6 2021, 8:20 AM
RKSimon requested review of this revision.Feb 6 2021, 8:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 6 2021, 8:20 AM
RKSimon added inline comments.Feb 6 2021, 8:25 AM
llvm/test/CodeGen/X86/pr40891.ll
16

I missed this regression, will take a look.

xbolva00 added inline comments.
llvm/test/CodeGen/X86/vector-reduce-and-cmp.ll
592

Regression

RKSimon updated this revision to Diff 321941.Feb 6 2021, 8:51 AM

Add regression fix for concat of extract_subvector through bitcasts

pengfei added inline comments.Feb 6 2021, 10:09 PM
llvm/test/CodeGen/X86/sse2.ll
689

Should pand be better for integer vector?

llvm/test/CodeGen/X86/vec_saddo.ll
816

I haven't figured the math here out yet, but the removal of this doesn't look correct to me.
The previous math is xmm4[0] & xmm2[1] | xmm4[1], but we are changing it to xmm4[1] & xmm2[1] | xmm4[1].

llvm/test/CodeGen/X86/vector-reduce-and.ll
560

Is this still regression?

RKSimon added inline comments.Feb 7 2021, 2:21 AM
llvm/test/CodeGen/X86/sse2.ll
689

it would use pand if there was any int domain instructions around (if it fed a shift etc.) - but otherwise the default is to use the ps domain if possible.

llvm/test/CodeGen/X86/vec_saddo.ll
816

I think this is SimplifyDemandedElts (called from one of the shuffles below) being able to remove the shuffle now that it can see everything as <4 x i32> - but I haven't confirmed that yet.

llvm/test/CodeGen/X86/vector-reduce-and.ll
560

Yes - I'm going to have a look at this

RKSimon planned changes to this revision.Feb 9 2021, 10:07 AM

Still investigating the reduction regressions

RKSimon updated this revision to Diff 324638.Feb 18 2021, 7:53 AM

Add missing hasOneUse check to fix reduction regressions

Any more comments?

llvm/lib/Target/X86/X86ISelLowering.cpp
49366

For the record I'm intending to commit this fold as a followup commit to the fix the temporary regression.

pengfei accepted this revision.Feb 21 2021, 5:24 AM

LGTM.

llvm/test/CodeGen/X86/vec_saddo.ll
816

Verified it locally by random number https://godbolt.org/z/61eTfr, the change here should be correct.

This revision is now accepted and ready to land.Feb 21 2021, 5:24 AM
RKSimon added inline comments.Feb 21 2021, 6:09 AM
llvm/test/CodeGen/X86/vec_saddo.ll
816

Nice! Thank you.