[InstCombine] canonicalize 'icmp (trunc X), C' to 'icmp (X & Mask), C'
authorSanjay Patel <spatel@rotateright.com>
Thu, 30 Jun 2022 19:00:12 +0000 (15:00 -0400)
committerSanjay Patel <spatel@rotateright.com>
Thu, 30 Jun 2022 19:51:39 +0000 (15:51 -0400)
commitcc88445a9106333bad7679f72031b5602b3a2953
tree8ec833a1716c4236543902b92879a0430f12e3ec
parentd48a3b866c3d8a7b329907c4adecf29d814ad79c
[InstCombine] canonicalize 'icmp (trunc X), C' to 'icmp (X & Mask), C'

I looked at canonicalizing in the other direction, but that causes
many potential regressions and infinite loops because we already
(possibly wrongly) canonicalize "trunc X to i1" into an and+icmp.

This has a data layout restriction to avoid creating illegal
mask instructions, but we could remove that if we can show
that the backend can undo this when needed.

The motivating example from issue #56119 is modeled by the
PhaseOrdering test.
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-gep.ll
llvm/test/Transforms/InstCombine/icmp-trunc.ll
llvm/test/Transforms/InstCombine/load-cmp.ll
llvm/test/Transforms/InstCombine/memchr.ll
llvm/test/Transforms/LoopVectorize/X86/parallel-loops.ll
llvm/test/Transforms/LoopVectorize/reduction-inloop.ll
llvm/test/Transforms/PhaseOrdering/cmp-logic.ll