[SCEVExpander] Stop hoisting IR when reusing phis
authorPhilip Reames <listmail@philipreames.com>
Tue, 17 Aug 2021 16:26:59 +0000 (09:26 -0700)
committerPhilip Reames <listmail@philipreames.com>
Tue, 17 Aug 2021 16:38:32 +0000 (09:38 -0700)
commit982da7a20c406c5725b5fe20d699a78069e54ffa
tree0676357e8d34a270eba0720275de487fcc8f6160
parent9dabacd09fdd52b5995546794290651c477d3885
[SCEVExpander] Stop hoisting IR when reusing phis

his is a fix for PR43678, and is an alternate patch to D105723.

The basic issue we're running into is that LSR + SCEVExpander are moving the very instruction whose operand we're in the process of expanding. This breaks the subtle and ill-documented invariant which let LSR work. (Full story can be found here: https://reviews.llvm.org/D105723#2878473)

Rather than attempting a fix, this change just removes the optimization entirely. The code is entirely untested, and removing it appears to have no impact I can find.  This code was added back in 2014 by 1e12f8563d4b7 with a single test which does not seem to actually test the hoisting logic.

From a philosophical standpoint, it also seems very strange to have the expander implementing optimizations which should live in a dedicated transform pass.

Differential Revision: https://reviews.llvm.org/D106178
llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
llvm/test/Transforms/LoopStrengthReduce/wrong-hoisting-iv.ll [new file with mode: 0644]