If we fold a branch/switch to an unconditional branch to another dead block we
replace the branch with unreachable, to avoid attempting to fold the
unconditional branch.
Details
- Reviewers
davide efriedma mssimpso jdoerfert - Commits
- rZORG37fab499bd2c: [SCCP] Fix crash when trying to constant-fold terminators multiple times.
rZORG26cae0d3547e: [SCCP] Fix crash when trying to constant-fold terminators multiple times.
rG37fab499bd2c: [SCCP] Fix crash when trying to constant-fold terminators multiple times.
rG26cae0d3547e: [SCCP] Fix crash when trying to constant-fold terminators multiple times.
rG3c696b3e7c21: [SCCP] Fix crash when trying to constant-fold terminators multiple times.
rL360232: [SCCP] Fix crash when trying to constant-fold terminators multiple times.
Diff Detail
- Repository
- rL LLVM
Event Timeline
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 |
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. |
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. |