[PATCH] D69842: [InstCombine] canonicalize shift+logic+shift to reduce dependency chain

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 5 06:19:10 PST 2019


spatel created this revision.
spatel added reviewers: lebedev.ri, nikic, reames.
Herald added subscribers: hiraditya, mcrosier.
Herald added a project: LLVM.

shift (logic (shift X, C0), Y), C1 --> logic (shift X, C0+C1), (shift Y, C1)

This is an IR translation of an existing SDAG transform added here:
rL370617 <https://reviews.llvm.org/rL370617>

So we again have 9 possible patterns with a commuted IR variant of each pattern:
https://rise4fun.com/Alive/VlI
https://rise4fun.com/Alive/n1m
https://rise4fun.com/Alive/1Vn

Part of the motivation is to allow easier recognition and subsequent canonicalization of bswap patterns as discussed in PR43146:
https://bugs.llvm.org/show_bug.cgi?id=43146

We had to delay this transform because it used to allow the SLP vectorizer to create awful reductions out of simple load-combines. That problem was fixed with:
rL375025 <https://reviews.llvm.org/rL375025>
(we'll bring back load combining in IR someday...)

The backend is also better equipped to deal with these patterns now using hooks like TLI.getShiftAmountThreshold().

The only remaining potential controversy is that the -reassociate pass tends to reverse this kind of pattern (to help GVN?). But since -reassociate doesn't do anything with these specific patterns, there is no conflict currently.

Finally, there's a new pass proposal at D67383 <https://reviews.llvm.org/D67383> for general tree-height-reduction reassociation, and it could use a cost model to decide how to optimally rearrange these kinds of ops for a target. That patch appears to be stalled.


https://reviews.llvm.org/D69842

Files:
  llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
  llvm/test/Transforms/InstCombine/bswap.ll
  llvm/test/Transforms/InstCombine/shift-logic.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69842.227857.patch
Type: text/x-patch
Size: 9608 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191105/4f2fe411/attachment.bin>


More information about the llvm-commits mailing list