[PATCH] D65380: [InstCombine] Shift amount reassociation: shl-trunc-shl pattern

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 28 14:46:57 PDT 2019


lebedev.ri created this revision.
lebedev.ri added reviewers: spatel, nikic, xbolva00.
lebedev.ri added a project: LLVM.
Herald added a subscriber: hiraditya.

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` regardless whether there is `trunc` or not.
- If it's a `ashr`, then a splat of original signbit

https://rise4fun.com/Alive/KQE
https://rise4fun.com/Alive/i0V


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65380

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65380.212120.patch
Type: text/x-patch
Size: 12993 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190728/17a1b260/attachment.bin>


More information about the llvm-commits mailing list