This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] fold lshr (sext X), C1 --> zext (lshr X, C2)
ClosedPublic

Authored by spatel on Jun 4 2017, 8:41 AM.

Details

Summary

This was discussed in D33338. We have larger pattern-matching ending in a truncate that we can reduce or remove by handling these smaller patterns first. Further motivation is that narrower shift ops are easier for value tracking and zext is better than sext.

http://rise4fun.com/Alive/rhh

Name: boolshift
%sext = sext i1 %x to i8
%r = lshr i8 %sext, 7

=>

%r = zext i1 %x to i8

Name: noboolshift
%sext = sext i3 %x to i8
%r = lshr i8 %sext, 7

=>

%sh = lshr i3 %x, 2
%r = zext i3 %sh to i8

Diff Detail

Event Timeline

spatel created this revision.Jun 4 2017, 8:41 AM
efriedma added inline comments.Jun 7 2017, 11:18 AM
lib/Transforms/InstCombine/InstCombineShifts.cpp
693

This isn't calling shouldChangeType; is that intentional? (Not sure how much this matters.)

spatel added inline comments.Jun 7 2017, 11:27 AM
lib/Transforms/InstCombine/InstCombineShifts.cpp
693

No, that's an oversight. I'll add that and a test case.

spatel updated this revision to Diff 101793.Jun 7 2017, 12:23 PM

Patch updated:

  1. Use shouldChangeType() to guard against adding a shift of an illegal type.
  2. Add/modify tests to show that difference.
efriedma accepted this revision.Jun 7 2017, 12:27 PM

LGTM.

This revision is now accepted and ready to land.Jun 7 2017, 12:27 PM
This revision was automatically updated to reflect the committed changes.