[IndVars] Recognize 'sub nuw' expressed as 'add' for widening
authorMax Kazantsev <mkazantsev@azul.com>
Thu, 12 Nov 2020 03:49:01 +0000 (10:49 +0700)
committerMax Kazantsev <mkazantsev@azul.com>
Thu, 12 Nov 2020 03:51:29 +0000 (10:51 +0700)
commit2e01ceafaa1ceef2428182128c3654bab56a0a4f
treeda5a0becd3039066cba0bcf2be85e49674d2a4a8
parent813781a923007a6070521ebfcb939796b0a47df8
[IndVars] Recognize 'sub nuw' expressed as 'add' for widening

InstCombine canonicalizes 'sub nuw' instructions to 'add' without the
`nuw` flag. The typical case where we see it is decrementing induction
variables. For them, IndVars fails to prove that it's legal to widen them,
and inserts unprofitable `zext`'s.

This patch adds recognition of such pattern using SCEV.

Differential Revision: https://reviews.llvm.org/D89550
Reviewed By: fhahn, skatkov
llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
llvm/test/Transforms/IndVarSimplify/widen-loop-comp.ll