This is an archive of the discontinued LLVM Phabricator instance.

[X86] Add SimplifyMultipleUseDemandedBitsForTargetNode X86ISD::ANDNP handling
ClosedPublic

Authored by RKSimon on Jun 20 2022, 10:47 AM.

Details

Summary

See if we can remove X86ISD::ANDNP nodes by checking the state of the knownbits of the demanded elements.

This is equivalent to the generic ISD::AND handling, but flips the bits of the LHS operand to account for ANDNP.

Diff Detail

Event Timeline

RKSimon created this revision.Jun 20 2022, 10:47 AM
Herald added a project: Restricted Project. · View Herald Transcript
RKSimon requested review of this revision.Jun 20 2022, 10:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 20 2022, 10:47 AM
pengfei added inline comments.Jun 20 2022, 6:05 PM
llvm/lib/Target/X86/X86ISelLowering.cpp
41821

Why return LHS rather than ~LHS?

RKSimon planned changes to this revision.Jun 21 2022, 12:58 AM
RKSimon added inline comments.
llvm/lib/Target/X86/X86ISelLowering.cpp
41821

Doh! Nice catch! SimplifyMultipleUseDemandedBits isn't supposed to create nodes, I'll look at alternatives.

llvm/test/CodeGen/X86/combine-udiv.ll
700

It looks like we're missing and(mulh(x,c1),c2) -> mulh(x,and(c1,c2)) fold for cases where c2 is all/none bits.

RKSimon updated this revision to Diff 452159.Aug 12 2022, 5:53 AM

Limit this to the RHS case which allows us to avoid ANDNP

craig.topper added inline comments.Aug 12 2022, 9:32 AM
llvm/lib/Target/X86/X86ISelLowering.cpp
42160

This comment was copy and pasted from ISD::AND and seems incorrect. It says "known 1" but we're checking Known.Zero. We're only doing it for the LHS so "one side" and "the other" should be more precise.

RKSimon updated this revision to Diff 452507.Aug 14 2022, 3:38 AM

cleanup the comment to be ANDNP specific

The code looks good, but why only AVX1 benefit from it?

The interleaved shuffles tend to create a sequence of ORs/BLENDs with zeros - for 265-bit on AVX2+ that means usually means 2 x VPBLENDD but the AVX1 path usually ends up with a OR(AND,ANDN) pattern instead.

pengfei accepted this revision.Aug 26 2022, 5:23 AM

Got it, thanks @RKSimon. LGTM then.

This revision is now accepted and ready to land.Aug 26 2022, 5:23 AM
This revision was landed with ongoing or failed builds.Aug 26 2022, 6:29 AM
This revision was automatically updated to reflect the committed changes.