[InstCombine] Shift amount reassociation: shl-trunc-shl pattern
authorRoman Lebedev <lebedev.ri@gmail.com>
Tue, 6 Aug 2019 17:03:40 +0000 (17:03 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Tue, 6 Aug 2019 17:03:40 +0000 (17:03 +0000)
commit0f957109761913c563922f1afd4ceb29ef21bbd0
tree054f2749b8017be549608633808cf4709e4c058e
parent8fbb6ce847825ebda1dfcaee8a7bf88b4c4e3e52
[InstCombine] Shift amount reassociation: shl-trunc-shl pattern

Summary:
Currently `reassociateShiftAmtsOfTwoSameDirectionShifts()` only handles
two shifts one after another. If the shifts are `shl`, we still can
easily perform the fold, with no extra legality checks:
https://rise4fun.com/Alive/OQbM

If we have right-shift however, we won't be able to make it
any simpler than it already is.

After this the only thing missing here is constant-folding: (`NewShAmt >= bitwidth(X)`)
* If it's a logical shift, then constant-fold to `0` (not `undef`)
* If it's a `ashr`, then a splat of original signbit
https://rise4fun.com/Alive/E1K
https://rise4fun.com/Alive/i0V

Reviewers: spatel, nikic, xbolva00

Reviewed By: spatel

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D65380

llvm-svn: 368059
llvm/include/llvm/IR/PatternMatch.h
llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
llvm/test/Transforms/InstCombine/shift-amount-reassociation-with-truncation-shl.ll