[llvm] [LVI][ValueTracking] Take UB-implying attributes into account in `isSafeToSpeculativelyExecute` (PR #137604)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 28 07:20:04 PDT 2025
================
@@ -7287,7 +7286,20 @@ bool llvm::isSafeToSpeculativelyExecuteWithOpcode(
// The called function could have undefined behavior or side-effects, even
// if marked readnone nounwind.
- return Callee && Callee->isSpeculatable();
+ if (!Callee || !Callee->isSpeculatable())
+ return false;
+ // Since the operands may be changed after hoisting, undefined behavior may
+ // be triggered by some UB-implying attributes.
+ if (!AllowRefinement) {
+ if (CI->hasRetAttr(Attribute::NoUndef) ||
+ CI->getRetDereferenceableBytes() > 0 ||
+ CI->getRetDereferenceableOrNullBytes() > 0 ||
----------------
nikic wrote:
I think we should have a has() query for dropUBImplyingAttrsAndMetadata similar to how we have hasPoisonGeneratingAnnotations and dropPoisonGeneratingAnnotations, so we can keep these things in sync.
https://github.com/llvm/llvm-project/pull/137604
More information about the llvm-commits
mailing list