aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2011-12-21 05:52:02 +0000
committerNick Lewycky <nicholas@mxc.ca>2011-12-21 05:52:02 +0000
commit8369687576b062be74c941a4a90dbabb0828e028 (patch)
tree6b4fb2abcbf46abecd95f8b509252a8dd8e7e093 /lib/Analysis/ValueTracking.cpp
parent1e33e8b715299dd014931be388cf593d6a55dc69 (diff)
downloadexternal_llvm-8369687576b062be74c941a4a90dbabb0828e028.zip
external_llvm-8369687576b062be74c941a4a90dbabb0828e028.tar.gz
external_llvm-8369687576b062be74c941a4a90dbabb0828e028.tar.bz2
Make some intrinsics safe to speculatively execute.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147036 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ValueTracking.cpp')
-rw-r--r--lib/Analysis/ValueTracking.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp
index ef19e06..4739d1b 100644
--- a/lib/Analysis/ValueTracking.cpp
+++ b/lib/Analysis/ValueTracking.cpp
@@ -1912,11 +1912,31 @@ bool llvm::isSafeToSpeculativelyExecute(const Instruction *Inst,
return false;
return LI->getPointerOperand()->isDereferenceablePointer();
}
- case Instruction::Call:
+ case Instruction::Call: {
+ if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) {
+ switch (II->getIntrinsicID()) {
+ case Intrinsic::bswap:
+ case Intrinsic::ctlz:
+ case Intrinsic::ctpop:
+ case Intrinsic::cttz:
+ case Intrinsic::objectsize:
+ case Intrinsic::sadd_with_overflow:
+ case Intrinsic::smul_with_overflow:
+ case Intrinsic::ssub_with_overflow:
+ case Intrinsic::uadd_with_overflow:
+ case Intrinsic::umul_with_overflow:
+ case Intrinsic::usub_with_overflow:
+ return true;
+ // TODO: some fp intrinsics are marked as having the same error handling
+ // as libm. They're safe to speculate when they won't error.
+ // TODO: are convert_{from,to}_fp16 safe?
+ // TODO: can we list target-specific intrinsics here?
+ default: break;
+ }
+ }
return false; // The called function could have undefined behavior or
- // side-effects.
- // FIXME: We should special-case some intrinsics (bswap,
- // overflow-checking arithmetic, etc.)
+ // side-effects, even if marked readnone nounwind.
+ }
case Instruction::VAArg:
case Instruction::Alloca:
case Instruction::Invoke: