[PATCH] D150587: [KnownBits] Make shl/lshr/ashr implementations optimal

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 15 09:34:29 PDT 2023


nikic created this revision.
nikic added reviewers: RKSimon, foad, goldstein.w.n.
Herald added subscribers: StephenFan, kerbowa, hiraditya, jvesely.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The implementations for shifts were suboptimal in the case where the max shift amount was >= bitwidth. In that case we should still use the usual code clamped to BitWidth-1 rather than just giving up entirely.

Additionally, there was an implementation bug where the known zero bits for the individual shift amounts were not set in the shl/lshr implementations. I think after these changes, we'll be able to drop some of the code in ValueTracking which *also* evaluates all possible shift amounts and has been papering over this issue.

For the "all poison" case I've opted to return an unknown value for now. It would be better to return zero, but this has fairly substantial test fallout, so I figured it's best to not mix it into this change. (The "correct" return value would be a conflicts, but given that a lot of our APIs affect conflict-freedom, that's probably not the best idea to actually return.)


https://reviews.llvm.org/D150587

Files:
  llvm/lib/Support/KnownBits.cpp
  llvm/test/CodeGen/AMDGPU/amdgpu.private-memory.ll
  llvm/test/Transforms/InstCombine/not-add.ll
  llvm/unittests/Support/KnownBitsTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150587.522232.patch
Type: text/x-patch
Size: 8363 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230515/12cac9d2/attachment.bin>


More information about the llvm-commits mailing list