This is an archive of the discontinued LLVM Phabricator instance.

[DSE] Don't remove nounwind invokes
ClosedPublic

Authored by aheejin on Jun 20 2022, 2:03 PM.

Details

Summary

For non-mem-intrinsic and non-lifetime CallBases, the current
isRemovable function only checks if the CallBase 1. has no uses 2.
will return 3. does not throw:
https://github.com/llvm/llvm-project/blob/80fb7823367c1d105fcbc8f21b69205a0d68c859/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp#L1017

But we should also exclude invokes even in case they don't throw,
because they are terminators and thus cannot be removed. While it
doesn't seem to make much sense for invokes to have an nounwind
target, this kind of code can be generated and is also valid bitcode.

Diff Detail

Event Timeline

aheejin created this revision.Jun 20 2022, 2:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 20 2022, 2:03 PM
aheejin requested review of this revision.Jun 20 2022, 2:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 20 2022, 2:03 PM
nikic accepted this revision.Jun 21 2022, 12:34 AM

LG

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
1019

I'd probably go for a CB->isTerminator() check here, rather than checking specifically for invokes (though i doubt this can happen with callbr in practice).

llvm/test/Transforms/DeadStoreElimination/nounwind-invoke.ll
2

Please always use update_test_checks.py for middle-end tests.

5

Datalayout and triple are likely not relevant.

This revision is now accepted and ready to land.Jun 21 2022, 12:34 AM
aheejin updated this revision to Diff 438786.Jun 21 2022, 11:48 AM
aheejin marked 2 inline comments as done.

Address comments

aheejin marked an inline comment as done.Jun 21 2022, 11:48 AM
aheejin added inline comments.
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
1019

OK. Then I'll merge the CB->isTerminator check into the bottom line here:

return CB->use_empty() && CB->willReturn() && CB->doesNotThrow();

And I don't think we need a separate comment for that, because it is kind of clear that we can't remove terminators.

llvm/test/Transforms/DeadStoreElimination/nounwind-invoke.ll
5

Removed.

aheejin updated this revision to Diff 438787.Jun 21 2022, 11:49 AM

clang-format

Also changed ptr to integer pointers because it requires an additional arguments in the opt command line.

This revision was landed with ongoing or failed builds.Jun 21 2022, 11:54 AM
This revision was automatically updated to reflect the committed changes.