]> granicus.if.org Git - llvm/commit
[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)
commit28187b07d7d1ccdb3d166c14e0d3b30f5ac49a86
treea9174c695db19de0aa8a80e5e972bdc12fed873f
parentaeb19f8cb7d02baf186b2c0dcb9bf52d8982f888
[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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368059 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/IR/PatternMatch.h
lib/Transforms/InstCombine/InstCombineShifts.cpp
test/Transforms/InstCombine/shift-amount-reassociation-with-truncation-shl.ll