diff options
author | Philip Reames <listmail@philipreames.com> | 2018-04-27 20:44:01 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2018-04-27 20:44:01 +0000 |
commit | e4ec473b3ff94ecec6fe2c828770a124b139e1a5 (patch) | |
tree | 2b42b09ac5f8bb08114ac91382d391b236454916 /llvm/lib/Analysis/MustExecute.cpp | |
parent | 201a1086cf3ca3dfa949b26087a5b05610e66f8e (diff) | |
download | bcm5719-llvm-e4ec473b3ff94ecec6fe2c828770a124b139e1a5.tar.gz bcm5719-llvm-e4ec473b3ff94ecec6fe2c828770a124b139e1a5.zip |
[MustExecute/LICM] Special case first instruction in throwing header
We currently have a hard to solve analysis problem around the order of instructions within a potentially throwing block. We can't cheaply determine whether a given instruction is before the first potential throw in the block. While we're working on that in the background, special case the first instruction within the header.
why this particular special case? Well, headers are guaranteed to execute if the loop does, and it turns out we tend to produce this form in practice.
In a follow on patch, I tend to extend LICM with an alternate approach which works for any instruction in the header before the first throw, but this is the best I can come up with other users of the analysis (such as store promotion.)
Note: I can't show the difference in the analysis result since we're ORing in the expensive instruction walk used by SCEV. Using the full walk is not suitable for a general solution.
llvm-svn: 331079
Diffstat (limited to 'llvm/lib/Analysis/MustExecute.cpp')
-rw-r--r-- | llvm/lib/Analysis/MustExecute.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/MustExecute.cpp b/llvm/lib/Analysis/MustExecute.cpp index ece4a1695cf..1e922fd44c4 100644 --- a/llvm/lib/Analysis/MustExecute.cpp +++ b/llvm/lib/Analysis/MustExecute.cpp @@ -109,8 +109,11 @@ bool llvm::isGuaranteedToExecute(const Instruction &Inst, // is a common case, and can save some work, check it now. if (Inst.getParent() == CurLoop->getHeader()) // If there's a throw in the header block, we can't guarantee we'll reach - // Inst. - return !SafetyInfo->HeaderMayThrow; + // Inst unless we can prove that Inst comes before the potential implicit + // exit. At the moment, we use a (cheap) hack for the common case where + // the instruction of interest is the first one in the block. + return !SafetyInfo->HeaderMayThrow || + Inst.getParent()->getFirstNonPHI() == &Inst; // Somewhere in this loop there is an instruction which may throw and make us // exit the loop. |