When evaluating formulae for LSR, we sometimes may have SCEVUnknown included
into the expression. When we try to make a fixup for an instruction outside the loop
and this SCEVUnknown is loop-variant, we are unable to duplicate/sink its s out of loop.
We must reuse the instruction from the loop after fixup. As result, it will not be trivially
dead for sure. We are also unable to evaluate the number of other instructions that will
also not become dead, because they are still used by it. This makes our reasoning about
profitability of application of the formula misleading.
On the other hand, while doing this transformation, we may create LSR IV Phis in the loop,
thus increasing the code. These new Phis will also be (likely) not dead. As result, this
misleading choise of a formula ends up with code increase without any benefits. This only
leads to performance, compile time and code size degradations.
The examples of tests where the LSR only produces new instructions inside and ouside the
loop are demonstrated in the attached test.
To avoid this situation, this patch changes LSR cost model so that it rejects formulae with
registers that include loop-variant SCEVUnknown values if they require at least one fixup
outside the loop.