[InstCombineCasts] Cast elimination for sext->lshr->trunc patterns

Authored by kuhar on Sep 1 2015, 2:00 AM.



There is a trunc(lshr (zext A), Cst) optimization in InstCombineCasts that removes cast by performing the lshr on smaller types. However, currently there is no trunc(lshr (sext A), Cst) variant.

This patch add such optimization by transforming trunc(lshr (sext A), Cst) to ashr A, Cst.

Diff Detail

kuhar retitled this revision from to [InstCombineCasts] Cast elimination for sext->lshr->trunc patterns.Sep 1 2015, 2:00 AM
kuhar updated this object.
kuhar set the repository for this revision to rL LLVM.
kuhar added a subscriber: llvm-commits.
aadg accepted this revision.Sep 7 2015, 5:22 AM
aadg added a reviewer: aadg.
aadg added a subscriber: aadg.

Hi Jakub,

Thanks for looking into this. This looks good to me with some fixes addressed (see below).

504 ↗(On Diff #34203)

Typo: s/comming/coming/

513 ↗(On Diff #34203)

Typo: s/destanation/destination/

516–517 ↗(On Diff #34203)

Isn't this comment redundant with the previous one ?

1072–1073 ↗(On Diff #34203)

Here you should pattern match the result, and reuse it when checking the return. This will make the test more robust if anything changes in the naming of the values.

1084–1085 ↗(On Diff #34203)

Same. Use pattern matching.

1096–1099 ↗(On Diff #34203)


This revision is now accepted and ready to land.Sep 7 2015, 5:22 AM
kuhar marked 6 inline comments as done.Sep 8 2015, 2:18 AM
kuhar updated this revision to Diff 34203.Sep 8 2015, 2:20 AM

Typos fixed, regexes used in test-cases.

This revision was automatically updated to reflect the committed changes.
kuhar updated this revision to Diff 34419.Sep 10 2015, 2:20 AM

Fix for PR24763