diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2021-07-03 10:45:44 +0300 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2021-07-03 10:45:44 +0300 |
commit | fc150cecd7484e47328fc78d4a3d597e2791b0fe (patch) | |
tree | 89ede0575e781412d82ac27dfd7479ad2be831d7 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | fbc329efbdba3edad78a1651148b340bcc7bf032 (diff) | |
download | llvm-fc150cecd7484e47328fc78d4a3d597e2791b0fe.zip llvm-fc150cecd7484e47328fc78d4a3d597e2791b0fe.tar.gz llvm-fc150cecd7484e47328fc78d4a3d597e2791b0fe.tar.bz2 |
[SimplifyCFG] simplifyUnreachable(): erase instructions iff they are guaranteed to transfer execution to unreachable
This replaces the current ad-hoc implementation,
by syncing the code from InstCombine's implementation in `InstCombinerImpl::visitUnreachableInst()`,
with one exception that here in SimplifyCFG we are allowed to remove EH instructions.
Effectively, this now allows SimplifyCFG to remove calls (iff they won't throw and will return),
arithmetic/logic operations, etc.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D105374
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index e877fb1..f5e320e 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -26,6 +26,7 @@ #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/AssumeBundleQueries.h" #include "llvm/Analysis/AssumptionCache.h" +#include "llvm/Analysis/EHPersonalities.h" #include "llvm/Analysis/GuardUtils.h" #include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/Loads.h" @@ -5273,6 +5274,18 @@ bool llvm::isGuaranteedToTransferExecutionToSuccessor(const Instruction *I) { if (isa<UnreachableInst>(I)) return false; + if (isa<CatchPadInst>(I)) { + switch (classifyEHPersonality(I->getFunction()->getPersonalityFn())) { + default: + // A catchpad may invoke exception object constructors and such, which + // in some languages can be arbitrary code, so be conservative by default. + return false; + case EHPersonality::CoreCLR: + // For CoreCLR, it just involves a type test. + return true; + } + } + // An instruction that returns without throwing must transfer control flow // to a successor. return !I->mayThrow() && I->willReturn(); |