[InstCombine] convert lshr to ashr to eliminate cast op
authorSanjay Patel <spatel@rotateright.com>
Thu, 3 Jun 2021 20:13:16 +0000 (16:13 -0400)
committerSanjay Patel <spatel@rotateright.com>
Fri, 4 Jun 2021 11:04:37 +0000 (07:04 -0400)
commit23a116c8c446f82ec5e2d2337c3253d0dc9c75b5
treed1d8512e09e66f885e64ee0fcf72e7390e9f3461
parent8937450e8581a8a135c61ff083828e6603755ef5
[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.
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/test/Transforms/InstCombine/lshr-trunc-sext-to-ashr-sext.ll