[InstCombine] Don't push operation across loop phi
authorNikita Popov <npopov@redhat.com>
Fri, 10 Jun 2022 14:17:19 +0000 (16:17 +0200)
committerNikita Popov <npopov@redhat.com>
Mon, 13 Jun 2022 08:48:09 +0000 (10:48 +0200)
commit92a9b1c9184cbb382257ca8bf3e079ab8f20b038
treecea1381344b5920c442681f336b23496d7387cb5
parent2a3288776c940669fed430c3984b91e61ab0f015
[InstCombine] Don't push operation across loop phi

When pushing an operation across a phi node, we should avoid doing
so across a loop backedge. This is generally non-profitable, because
it does not reduce the number of times the operation is executed,
and could lead to an infinite combine loop.

The code was already guarding against this, but using an
insufficiently strong condition, which did not cover the case where
the operation was originally outside the loop (in which case the
transform moves the operation from outside the loop into the loop,
which is particularly undesirable).

Differential Revision: https://reviews.llvm.org/D127499
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/cast_phi.ll