This is an archive of the discontinued LLVM Phabricator instance.

[X86] Recognize standalone `(1 << nbits) - 1` pattern as bzhi
ClosedPublic

Authored by danilaml on Jul 18 2023, 9:54 AM.

Details

Summary

This can be thought as a subcase of x & ((1 << nbits) - 1) where x == -1

Diff Detail

Event Timeline

danilaml created this revision.Jul 18 2023, 9:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 18 2023, 9:54 AM
danilaml requested review of this revision.Jul 18 2023, 9:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 18 2023, 9:54 AM
danilaml edited the summary of this revision. (Show Details)Jul 18 2023, 9:55 AM
danilaml edited the summary of this revision. (Show Details)Jul 18 2023, 9:59 AM
goldstein.w.n added inline comments.Jul 18 2023, 10:18 AM
llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
3511

nit: needs clang format.

llvm/test/CodeGen/X86/extract-lowbits.ll
3036

Can you add a test where nbits is masked by vreg width? Just want to make sure those semantics are maintained.

danilaml added inline comments.Jul 18 2023, 10:35 AM
llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
3511

I think this part is already clang-formatted. I'll recheck.

llvm/test/CodeGen/X86/extract-lowbits.ll
3036

Could elaborate? Which semantics should the test verify?
Do you mean something like (1 << (nbits & vreg_width)) - 1?

goldstein.w.n added inline comments.Jul 18 2023, 10:39 AM
llvm/test/CodeGen/X86/extract-lowbits.ll
3036

Yes, just don't see any tests with a mask. vreg_width - 1 really. I expect it to work fine, just want to watch out for the fact that shifts can ignore word mask, but bzhi can't

danilaml updated this revision to Diff 541968.Jul 19 2023, 5:34 AM

Add test with masked nbits

danilaml marked 3 inline comments as done.Jul 19 2023, 5:43 AM
RKSimon added inline comments.Jul 19 2023, 6:14 AM
llvm/test/CodeGen/AArch64/extract-lowbits.ll
24 ↗(On Diff #541968)

This is a X86 patch - skip the aarch64 regeneration changes (or commit separately)

danilaml added inline comments.Jul 19 2023, 9:33 AM
llvm/test/CodeGen/AArch64/extract-lowbits.ll
24 ↗(On Diff #541968)

Ok, it's just this test explicitly asks to keep them in sync.

danilaml updated this revision to Diff 542076.Jul 19 2023, 9:34 AM

Remove updates to aarch64 test

goldstein.w.n added inline comments.Jul 19 2023, 10:36 AM
llvm/test/CodeGen/X86/extract-lowbits.ll
516

Can you split the new tests to a seperate patch?

I.e
commit 1: tests (updated with LLVM before this commit)
commit 2: impl (update tests with the impl)

Then submit both to phab and use "Edit Related Revisions" to make the tests patch the child of the impl patch.

That way it easier to track the changes caused by the impl itself.

danilaml updated this revision to Diff 542119.Jul 19 2023, 11:07 AM

split new tests pre-changes into separate review

danilaml marked an inline comment as done.Jul 19 2023, 11:08 AM
danilaml added inline comments.
llvm/test/CodeGen/X86/extract-lowbits.ll
516

commit 1 would be empty in this case. Everything below this line is just label renumbering caused by insertion of the new test function.

danilaml marked an inline comment as done.Jul 19 2023, 11:09 AM
danilaml added inline comments.
llvm/test/CodeGen/X86/extract-lowbits.ll
516

Disregard previous reply. Phabricator is being unwieldy. Tests are now in https://reviews.llvm.org/D155734

This revision is now accepted and ready to land.Jul 19 2023, 7:03 PM