HomePhabricator

[InstCombine] convert lshr to ashr to eliminate cast op

Authored by spatel on Jun 3 2021, 1:13 PM.

Description

[InstCombine] convert lshr to ashr to eliminate cast op

This is similar to b865eead7657 ( D103617 ) and fixes:
https://llvm.org/PR50575

41b71f718b94c6f12b did this and more (noted with TODO
comments in the tests), but it didn't handle the case
where the destination is narrower than the source, so
it got reverted.

This is a simple match-and-replace. If there's evidence
that the TODO cases are useful, we can revisit/extend.

Details

Committed
spatelJun 4 2021, 4:04 AM
Parents
rG8937450e8581: [InstCombine] add tests for sext-of-trunc-of-lshr; NFC
Branches
Unknown
Tags
Unknown

Event Timeline

Herald added a subscriber: Restricted Project. ยท View Herald TranscriptJun 4 2021, 4:04 AM
xbolva00 added inline comments.
/llvm/test/Transforms/InstCombine/lshr-trunc-sext-to-ashr-sext.ll
60

Negative test? Why n3?

spatel marked an inline comment as done.Jun 4 2021, 6:11 AM
spatel added inline comments.
/llvm/test/Transforms/InstCombine/lshr-trunc-sext-to-ashr-sext.ll
60

Yes - the original tests were added with:
0ea464824aa1fd / 41b71f718b94

I tried to make the intent clearer with a follow-up:
1fc6027406c5

Note that we could transform this to use more shifts:
https://alive2.llvm.org/ce/z/CSH8QN

...but we could argue that this form is better. So one way or the other, we are missing a potential canonicalization, but I have not looked to see if there's any noticeable difference to analysis or codegen.