]> granicus.if.org Git - llvm/commit
[InstCombine] Shift amount reassociation in bittest (PR42399)
authorRoman Lebedev <lebedev.ri@gmail.com>
Mon, 1 Jul 2019 15:55:15 +0000 (15:55 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Mon, 1 Jul 2019 15:55:15 +0000 (15:55 +0000)
commit458204d46507d4613d9536aa2f06293bd1f13943
tree599e3ae551e326ab2f7cfc44ba04f2c3dafc249e
parent3e56c9d4260b091ecb0332e96615f1186605ac99
[InstCombine] Shift amount reassociation in bittest (PR42399)

Summary:
Given pattern:
`icmp eq/ne (and ((x shift Q), (y oppositeshift K))), 0`
we should move shifts to the same hand of 'and', i.e. rewrite as
`icmp eq/ne (and (x shift (Q+K)), y), 0`  iff `(Q+K) u< bitwidth(x)`

It might be tempting to not restrict this to situations where we know
we'd fold two shifts together, but i'm not sure what rules should there be
to avoid endless combine loops.

We pick the same shift that was originally used to shift the variable we picked to shift:
https://rise4fun.com/Alive/6x1v

Should fix [[ https://bugs.llvm.org/show_bug.cgi?id=42399 | PR42399]].

Reviewers: spatel, nikic, RKSimon

Reviewed By: spatel

Subscribers: llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364791 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/shift-amount-reassociation-in-bittest.ll