This is an archive of the discontinued LLVM Phabricator instance.

[X86][InstCombine] Add basic constant folding support for BEXTR/BEXTRI intrinsics.
ClosedPublic

Authored by craig.topper on Jul 30 2017, 12:13 PM.

Details

Summary

This patch adds constant folding support for the BEXTR/BEXTRI intrinsics to match gcc. This only supports cases that fold to 0 or can be fully constant folded. Theoretically we could support converting to AND if the shift part is unused or to only a shift if the mask doesn't modify any bits after an equivalent shl. gcc doesn't do these transformations either.

I put this in InstCombine, but it could be done in InstSimplify. It would be the first target specific intrinsic in InstSimplify.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Jul 30 2017, 12:13 PM
zvi accepted this revision.Jul 31 2017, 12:37 AM

LGTM

This revision is now accepted and ready to land.Jul 31 2017, 12:37 AM
aymanmus added inline comments.
lib/Transforms/InstCombine/InstCombineCalls.cpp
2251 ↗(On Diff #108836)

Another case that is worth handling:
if (Shift == 0) then replace with simple (AND operand0, 2^length) instruction.

This revision was automatically updated to reflect the committed changes.