[indvars] Rotate zext though icmp to reduce loop varying computation
authorPhilip Reames <listmail@philipreames.com>
Wed, 3 Nov 2021 19:08:16 +0000 (12:08 -0700)
committerPhilip Reames <listmail@philipreames.com>
Wed, 3 Nov 2021 19:09:20 +0000 (12:09 -0700)
commit3fc9882e880614093a36456fe83f9de023ac7851
tree85693f1df5d635c7df7d88656614129d662f355c
parent32eb697c0a7f690947868aa4ccf05ce4000f483a
[indvars] Rotate zext though icmp to reduce loop varying computation

This change looks for cases where we can prove that an exit test of a loop can be performed in a narrower bitwidth, and that by doing so we can replace a loop-varying extend with a loop-invariant truncate.

The motivation here is that doing this unblocks the trip count analysis for narrow IVs involved in extended compare exit tests. It also has the nice side effect of simply making the code faster, even if we gain no other benefit from the improved analysis ability.

I've noted a few places this could be extended, but I think this stands reasonable on it's own as well.

Differential Revision: https://reviews.llvm.org/D112262
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
llvm/test/Transforms/IndVarSimplify/finite-exit-comparisons.ll