This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Optimize (brcond (seteq (and X, (1 << C)-1), 0))
ClosedPublic

Authored by liaolucy on Jan 12 2023, 5:59 AM.

Details

Summary

Inspired by gcc's assembly: https://godbolt.org/z/54hbzsGYn, while referring to D130203

Replace AND+IMM{32,64} with a slli.

But gcc does not handle 0xffff and 0xffffffff, which also seem to be optimizable.

The testcases copies all the bits in D130203 and adds 16, 32, and 64 bits.

Diff Detail

Event Timeline

liaolucy created this revision.Jan 12 2023, 5:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2023, 5:59 AM
liaolucy requested review of this revision.Jan 12 2023, 5:59 AM
liaolucy updated this revision to Diff 488629.Jan 12 2023, 6:05 AM

Update, we can see the difference between the original code and the modified one very well

craig.topper added inline comments.Jan 12 2023, 11:02 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1546

is isShiftedMask_64(Mask) && TrailingZeros == 0 the same as isMask_64(Mask)

1553

I think you can use LHS.getValueSizeInBits() instead of Subtarget.getXLen().

liaolucy updated this revision to Diff 488821.Jan 12 2023, 5:33 PM

address comments, thanks

LGTM with that fix.

llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1549

Add curly braces around the else body to match the if.

liaolucy updated this revision to Diff 488954.Jan 13 2023, 4:54 AM

Add curly braces around the else body.
Rebase

This revision was not accepted when it landed; it landed in state Needs Review.Jan 13 2023, 5:01 AM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.