This is an archive of the discontinued LLVM Phabricator instance.

[SCCP] Fix crash when trying to constant-fold terminators multiple times.
ClosedPublic

Authored by fhahn on Apr 30 2019, 3:28 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

fhahn created this revision.Apr 30 2019, 3:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 30 2019, 3:28 AM
Herald added a subscriber: hiraditya. · View Herald Transcript

Do we need to "repair" the folded branch or could we also determine earlier that the current block is dead (it will have an unconditional branch to a dead block, right?) and avoid folding?
It might make sense to fold due to the DT update though.

llvm/lib/Transforms/Scalar/SCCP.cpp
2087 ↗(On Diff #197284)

now BB

fhahn marked an inline comment as done.May 7 2019, 10:03 AM

Do we need to "repair" the folded branch or could we also determine earlier that the current block is dead (it will have an unconditional branch to a dead block, right?) and avoid folding?
It might make sense to fold due to the DT update though.

We could skip calling forceIndeterminateEdge and ConstantFoldTerminator, if all successors are not executable. But I think it is better to keep the current structure, because the assertion that we managed to fold the terminator has been helpful in catching inconsistencies in the past and it is probably also quicker e.g. if you have switch statements with a large number of successors.

llvm/lib/Transforms/Scalar/SCCP.cpp
2087 ↗(On Diff #197284)

Do you mean omitting the * with auto? There's no reason to use auto here, I'll change it to BasicBlock.

jdoerfert accepted this revision.May 7 2019, 10:20 AM

Do we need to "repair" the folded branch or could we also determine earlier that the current block is dead (it will have an unconditional branch to a dead block, right?) and avoid folding?
It might make sense to fold due to the DT update though.

We could skip calling forceIndeterminateEdge and ConstantFoldTerminator, if all successors are not executable. But I think it is better to keep the current structure, because the assertion that we managed to fold the terminator has been helpful in catching inconsistencies in the past and it is probably also quicker e.g. if you have switch statements with a large number of successors.

Now that we thought about it, I think it's fine to do it this way :)

See the comment but otherwise LGTM

llvm/lib/Transforms/Scalar/SCCP.cpp
2087 ↗(On Diff #197284)

I mean I->getParent() in 2087 should now be BB. Also, BasicBlock seems reasonable.

This revision is now accepted and ready to land.May 7 2019, 10:20 AM
fhahn updated this revision to Diff 198509.May 7 2019, 12:30 PM

Use InstBB instead of I->getParent(). Thanks, I was looking at the wrong line :)

This revision was automatically updated to reflect the committed changes.