[AggressiveInstCombine] convert a chain of 'or-shift' bits into masked compare
authorSanjay Patel <spatel@rotateright.com>
Tue, 1 May 2018 21:02:09 +0000 (21:02 +0000)
committerSanjay Patel <spatel@rotateright.com>
Tue, 1 May 2018 21:02:09 +0000 (21:02 +0000)
commitd2025a2e311f94b15c12852ae4163cac41e2fd47
treecc26c4d668f2495835bc8d0f7f5b30631926f913
parent52fd16903569c0f8c3ca3dfe89d664969739f2f0
[AggressiveInstCombine] convert a chain of 'or-shift' bits into masked compare

and (or (lshr X, C), ...), 1 --> (X & C') != 0

I initially thought about implementing the minimal pattern in instcombine as mentioned here:
https://bugs.llvm.org/show_bug.cgi?id=37098#c6

...but we need to do better to catch the more general sequence from the motivating test
(more than 2 bits in the compare). And a test-suite run with statistics showed that this
pattern only happened 2 times currently. It would potentially happen more often if
reassociation worked better (D45842), but it's probably still not too frequent?

This is small enough that I didn't see a need to create a whole new class/file within
AggressiveInstCombine. There are likely other relatively small matchers like what was
discussed in D44266 that would slide under foldUnusualPatterns() (name suggestions welcome).
We could potentially also consolidate matchers for ctpop, bswap, etc under here.

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

llvm-svn: 331311
llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
llvm/test/Transforms/AggressiveInstCombine/masked-cmp.ll
llvm/test/Transforms/PhaseOrdering/bitfield-bittests.ll