[InstCombine] fold lshr(trunc(lshr X, C1)) C2
authorSanjay Patel <spatel@rotateright.com>
Fri, 24 Sep 2021 17:27:02 +0000 (13:27 -0400)
committerSanjay Patel <spatel@rotateright.com>
Fri, 24 Sep 2021 19:44:07 +0000 (15:44 -0400)
commita47c8e40c734429903d4000285ca45a1c3299321
tree2c673cb158b29d5d5863889dbdcd190fa22de353
parent29c09c76539f6171fa84811e9b4b6d2a244e2d53
[InstCombine] fold lshr(trunc(lshr X, C1)) C2

Only the multi-use cases are changing here because there's
another fold that catches the simpler patterns.

But that other fold is the source of infinite loops when we
try to add D110170, so removing that is planned as a follow-up.

Attempt to show the general proof in Alive2:
https://alive2.llvm.org/ce/z/Ns1uS2

Note that the overshift fold-to-zero tests are not
currently handled by instsimplify. If they were, we
could assert that the shift amount sum is less than
the source bitwidth.
llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
llvm/test/Transforms/InstCombine/lshr.ll