[LSR] Don't try to fixup uses in 'EH pad' instructions
authorRoman Lebedev <lebedev.ri@gmail.com>
Sat, 13 Mar 2021 12:11:12 +0000 (15:11 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Sat, 13 Mar 2021 13:05:34 +0000 (16:05 +0300)
commit6e9b9978cfb71b3c5de315dbc628e5909baa71da
treee0880b7c829646675c238b908c22150b5dfc49e7
parent23d591efae68604a8620cbb1a7755eee0279290e
[LSR] Don't try to fixup uses in 'EH pad' instructions

The added test case crashes before this fix:
```
opt: /repositories/llvm-project/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:5172: BasicBlock::iterator (anonymous namespace)::LSRInstance::AdjustInsertPositionForExpand(BasicBlock::iterator, const (anonymous namespace)::LSRFixup &, const (anonymous namespace)::LSRUse &, llvm::SCEVExpander &) const: Assertion `!isa<PHINode>(LowestIP) && !LowestIP->isEHPad() && !isa<DbgInfoIntrinsic>(LowestIP) && "Insertion point must be a normal instruction"' failed.
```
This is fully analogous to the previous commit,
with the pointer constant replaced to be something non-null.

The comparison here can be strength-reduced,
but the second operand of the comparison happens to be identical
to the constant pointer in the `catch` case of `landingpad`.

While LSRInstance::CollectLoopInvariantFixupsAndFormulae()
already gave up on uses in blocks ending up with EH pads,
it didn't consider this case.

Eventually, `LSRInstance::AdjustInsertPositionForExpand()`
will be called, but the original insertion point it will get
is the user instruction itself, and it doesn't want to
deal with EH pads, and asserts as much.

It would seem that this basically never happens in-the-wild,
otherwise it would have been reported already,
so it seems safe to take the cautious approach,
and just not deal with such users.
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
llvm/test/Transforms/LoopStrengthReduce/X86/eh-insertion-point-2.ll [new file with mode: 0644]