OSDN Git Service

[Scalarizer] Centralize instruction DCE
authorRoman Lebedev <lebedev.ri@gmail.com>
Mon, 6 Jul 2020 21:25:19 +0000 (00:25 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Mon, 6 Jul 2020 22:12:51 +0000 (01:12 +0300)
commitdb05f2e34a5e9380ddcc199d6687531108d795e4
treef605408438c08b5519ffef11dfc64b14f61d7e34
parentc359c5d534429c96f1cebdf8d845b8120e9c2ef0
[Scalarizer] Centralize instruction DCE

As reported in https://reviews.llvm.org/D83101#2133062
the new visitInsertElementInst()/visitExtractElementInst() functionality
is causing miscompiles (previously-crashing test added)

It is due to the fact how the infra of Scalarizer is dealing with DCE,
it was not updated or was it ready for such scalar value forwarding.
It always assumed that the moment we "scalarized" something,
it can go away, and did so with prejudice.

But that is no longer safe/okay to do.

Instead, let's prevent it from ever shooting itself into foot,
and let's just accumulate the instructions-to-be-deleted
in a vector, and collectively cleanup (those that are *actually* dead)
them all at the end.

All existing tests are not reporting any new garbage leftovers,
but maybe it's test coverage issue.
llvm/lib/Transforms/Scalar/Scalarizer.cpp
llvm/test/Transforms/Scalarizer/basic.ll
llvm/test/Transforms/Scalarizer/crash-bug.ll
llvm/test/Transforms/Scalarizer/phi-unreachable-pred.ll