[llvm] Take poison-generating attributes into account (PR #89138)
Andreas Jonson via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 17 23:09:43 PDT 2024
https://github.com/andjo403 updated https://github.com/llvm/llvm-project/pull/89138
>From d4bb53f641539997ddeab49e824bdd67ea473b12 Mon Sep 17 00:00:00 2001
From: Andreas Jonson <andjo403 at hotmail.com>
Date: Wed, 17 Apr 2024 21:52:14 +0200
Subject: [PATCH 1/4] [NFC] rename functions to more generic name.
---
llvm/include/llvm/IR/Instruction.h | 4 ++--
llvm/include/llvm/IR/Operator.h | 2 +-
llvm/lib/Analysis/InstructionSimplify.cpp | 2 +-
llvm/lib/Analysis/ScalarEvolution.cpp | 2 +-
llvm/lib/Analysis/ValueTracking.cpp | 2 +-
llvm/lib/IR/Operator.cpp | 2 +-
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 2 +-
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 4 ++--
llvm/lib/Transforms/Scalar/BDCE.cpp | 2 +-
llvm/lib/Transforms/Scalar/GuardWidening.cpp | 2 +-
llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp | 2 +-
llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | 2 +-
12 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h
index 6e0874c5b04f29..c8ad547706c553 100644
--- a/llvm/include/llvm/IR/Instruction.h
+++ b/llvm/include/llvm/IR/Instruction.h
@@ -497,12 +497,12 @@ class Instruction : public User,
void dropPoisonGeneratingMetadata();
/// Return true if this instruction has poison-generating flags or metadata.
- bool hasPoisonGeneratingFlagsOrMetadata() const {
+ bool hasPoisonGeneratingAnnotations() const {
return hasPoisonGeneratingFlags() || hasPoisonGeneratingMetadata();
}
/// Drops flags and metadata that may generate poison.
- void dropPoisonGeneratingFlagsAndMetadata() {
+ void dropPoisonGeneratingAnnotations() {
dropPoisonGeneratingFlags();
dropPoisonGeneratingMetadata();
}
diff --git a/llvm/include/llvm/IR/Operator.h b/llvm/include/llvm/IR/Operator.h
index e14a916b474935..2b1598b778d493 100644
--- a/llvm/include/llvm/IR/Operator.h
+++ b/llvm/include/llvm/IR/Operator.h
@@ -66,7 +66,7 @@ class Operator : public User {
/// Return true if this operator has poison-generating flags or metadata.
/// The latter is only possible for instructions.
- bool hasPoisonGeneratingFlagsOrMetadata() const;
+ bool hasPoisonGeneratingAnnotations() const;
};
/// Utility class for integer operators which may exhibit overflow - Add, Sub,
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 06ba5ca4c6b352..431ad37d0a9e86 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4431,7 +4431,7 @@ static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
return nullptr;
}
Constant *Res = ConstantFoldInstOperands(I, ConstOps, Q.DL, Q.TLI);
- if (DropFlags && Res && I->hasPoisonGeneratingFlagsOrMetadata())
+ if (DropFlags && Res && I->hasPoisonGeneratingAnnotations())
DropFlags->push_back(I);
return Res;
}
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 95440dda3b4c0e..93f885c5d5ad8b 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -4239,7 +4239,7 @@ bool ScalarEvolution::canReuseInstruction(
return false;
// If the instruction can't create poison, we can recurse to its operands.
- if (I->hasPoisonGeneratingFlagsOrMetadata())
+ if (I->hasPoisonGeneratingAnnotations())
DropPoisonGeneratingInsts.push_back(I);
for (Value *Op : I->operands())
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index ab2f43e1033fa1..695d0b0b1a2f87 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -6951,7 +6951,7 @@ static bool canCreateUndefOrPoison(const Operator *Op, UndefPoisonKind Kind,
bool ConsiderFlagsAndMetadata) {
if (ConsiderFlagsAndMetadata && includesPoison(Kind) &&
- Op->hasPoisonGeneratingFlagsOrMetadata())
+ Op->hasPoisonGeneratingAnnotations())
return true;
unsigned Opcode = Op->getOpcode();
diff --git a/llvm/lib/IR/Operator.cpp b/llvm/lib/IR/Operator.cpp
index ccc624d854429c..46d645a313c4b3 100644
--- a/llvm/lib/IR/Operator.cpp
+++ b/llvm/lib/IR/Operator.cpp
@@ -56,7 +56,7 @@ bool Operator::hasPoisonGeneratingFlags() const {
}
}
-bool Operator::hasPoisonGeneratingFlagsOrMetadata() const {
+bool Operator::hasPoisonGeneratingAnnotations() const {
if (hasPoisonGeneratingFlags())
return true;
auto *I = dyn_cast<Instruction>(this);
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 2d78fcee1152d7..9f6a4b2f395987 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -1340,7 +1340,7 @@ Instruction *InstCombinerImpl::foldSelectValueEquivalence(SelectInst &Sel,
/* AllowRefinement */ false,
&DropFlags) == TrueVal) {
for (Instruction *I : DropFlags) {
- I->dropPoisonGeneratingFlagsAndMetadata();
+ I->dropPoisonGeneratingAnnotations();
Worklist.add(I);
}
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 5a144cc7378962..e08d0a80e76536 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -4330,7 +4330,7 @@ InstCombinerImpl::pushFreezeToPreventPoisonFromPropagating(FreezeInst &OrigFI) {
return nullptr;
}
- OrigOpInst->dropPoisonGeneratingFlagsAndMetadata();
+ OrigOpInst->dropPoisonGeneratingAnnotations();
// If all operands are guaranteed to be non-poison, we can drop freeze.
if (!MaybePoisonOperand)
@@ -4401,7 +4401,7 @@ Instruction *InstCombinerImpl::foldFreezeIntoRecurrence(FreezeInst &FI,
}
for (Instruction *I : DropFlags)
- I->dropPoisonGeneratingFlagsAndMetadata();
+ I->dropPoisonGeneratingAnnotations();
if (StartNeedsFreeze) {
Builder.SetInsertPoint(StartBB->getTerminator());
diff --git a/llvm/lib/Transforms/Scalar/BDCE.cpp b/llvm/lib/Transforms/Scalar/BDCE.cpp
index 4aa87a84f115a1..d96dbca30fdb15 100644
--- a/llvm/lib/Transforms/Scalar/BDCE.cpp
+++ b/llvm/lib/Transforms/Scalar/BDCE.cpp
@@ -75,7 +75,7 @@ static void clearAssumptionsOfUsers(Instruction *I, DemandedBits &DB) {
Instruction *J = WorkList.pop_back_val();
// NSW, NUW, and exact are based on operands that might have changed.
- J->dropPoisonGeneratingFlagsAndMetadata();
+ J->dropPoisonGeneratingAnnotations();
// We do not have to worry about llvm.assume, because it demands its
// operand, so trivializing can't change it.
diff --git a/llvm/lib/Transforms/Scalar/GuardWidening.cpp b/llvm/lib/Transforms/Scalar/GuardWidening.cpp
index d3787b28347c9e..b6498c4e36963a 100644
--- a/llvm/lib/Transforms/Scalar/GuardWidening.cpp
+++ b/llvm/lib/Transforms/Scalar/GuardWidening.cpp
@@ -699,7 +699,7 @@ Value *GuardWideningImpl::freezeAndPush(Value *Orig,
Worklist.push_back(U.get());
}
for (Instruction *I : DropPoisonFlags)
- I->dropPoisonGeneratingFlagsAndMetadata();
+ I->dropPoisonGeneratingAnnotations();
Value *Result = Orig;
for (Value *V : NeedFreeze) {
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index 74cffbc005c82d..0feea0a4233cd1 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -1522,7 +1522,7 @@ Value *SCEVExpander::expand(const SCEV *S) {
} else {
for (Instruction *I : DropPoisonGeneratingInsts) {
rememberFlags(I);
- I->dropPoisonGeneratingFlagsAndMetadata();
+ I->dropPoisonGeneratingAnnotations();
// See if we can re-infer from first principles any of the flags we just
// dropped.
if (auto *OBO = dyn_cast<OverflowingBinaryOperator>(I))
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index 31be7d62c8d1d8..912c02c2ed3ae5 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -768,7 +768,7 @@ bool SimplifyIndvar::eliminateIdentitySCEV(Instruction *UseInst,
return false;
for (Instruction *I : DropPoisonGeneratingInsts)
- I->dropPoisonGeneratingFlagsAndMetadata();
+ I->dropPoisonGeneratingAnnotations();
}
LLVM_DEBUG(dbgs() << "INDVARS: Eliminated identity: " << *UseInst << '\n');
>From 524c9721ff118949052b30152677af3cf5d79780 Mon Sep 17 00:00:00 2001
From: Andreas Jonson <andjo403 at hotmail.com>
Date: Wed, 17 Apr 2024 22:04:23 +0200
Subject: [PATCH 2/4] [InstCombine] Add tests for freeze with range, align and
nonnull attribute (NFC) These are currently being miscompiled.
---
llvm/test/Transforms/InstCombine/freeze.ll | 41 +++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
diff --git a/llvm/test/Transforms/InstCombine/freeze.ll b/llvm/test/Transforms/InstCombine/freeze.ll
index 668f3033ed4b73..4503b1feab75dd 100644
--- a/llvm/test/Transforms/InstCombine/freeze.ll
+++ b/llvm/test/Transforms/InstCombine/freeze.ll
@@ -1069,7 +1069,7 @@ define ptr @freeze_load_dereferenceable(ptr %ptr) {
define ptr @freeze_load_dereferenceable_or_null(ptr %ptr) {
; CHECK-LABEL: @freeze_load_dereferenceable_or_null(
-; CHECK-NEXT: [[P:%.*]] = load ptr, ptr [[PTR:%.*]], align 8, !dereferenceable_or_null !1
+; CHECK-NEXT: [[P:%.*]] = load ptr, ptr [[PTR:%.*]], align 8, !dereferenceable_or_null [[META1]]
; CHECK-NEXT: ret ptr [[P]]
;
%p = load ptr, ptr %ptr, !dereferenceable_or_null !1
@@ -1160,6 +1160,45 @@ define i32 @propagate_drop_flags_trunc(i64 %arg) {
ret i32 %v1.fr
}
+declare i32 @llvm.umax.i32(i32 %a, i32 %b)
+
+define i32 @freeze_call_with_range_attr(i32 %a) {
+; CHECK-LABEL: @freeze_call_with_range_attr(
+; CHECK-NEXT: [[Y:%.*]] = lshr i32 2047, [[A:%.*]]
+; CHECK-NEXT: [[Y_FR:%.*]] = freeze i32 [[Y]]
+; CHECK-NEXT: [[X:%.*]] = call range(i32 0, 2048) i32 @llvm.umax.i32(i32 [[Y_FR]], i32 50)
+; CHECK-NEXT: ret i32 [[X]]
+;
+ %y = lshr i32 2047, %a
+ %x = call range(i32 0, 2048) i32 @llvm.umax.i32(i32 %y, i32 50)
+ %x.fr = freeze i32 %x
+ ret i32 %x.fr
+}
+
+declare ptr @llvm.ptrmask.p0.i64(ptr, i64)
+
+define ptr @freeze_ptrmask_align(ptr %p, i64 noundef %m) {
+; CHECK-LABEL: @freeze_ptrmask_align(
+; CHECK-NEXT: [[P_FR:%.*]] = freeze ptr [[P:%.*]]
+; CHECK-NEXT: [[MASK:%.*]] = call align 4 ptr @llvm.ptrmask.p0.i64(ptr [[P_FR]], i64 [[M:%.*]])
+; CHECK-NEXT: ret ptr [[MASK]]
+;
+ %mask = call align(4) ptr @llvm.ptrmask.p0.i64(ptr %p, i64 %m)
+ %fr = freeze ptr %mask
+ ret ptr %fr
+}
+
+define ptr @freeze_ptrmask_nonnull(ptr %p, i64 noundef %m) {
+; CHECK-LABEL: @freeze_ptrmask_nonnull(
+; CHECK-NEXT: [[P_FR:%.*]] = freeze ptr [[P:%.*]]
+; CHECK-NEXT: [[MASK:%.*]] = call nonnull ptr @llvm.ptrmask.p0.i64(ptr [[P_FR]], i64 [[M:%.*]])
+; CHECK-NEXT: ret ptr [[MASK]]
+;
+ %mask = call nonnull ptr @llvm.ptrmask.p0.i64(ptr %p, i64 %m)
+ %fr = freeze ptr %mask
+ ret ptr %fr
+}
+
!0 = !{}
!1 = !{i64 4}
!2 = !{i32 0, i32 100}
>From 928d480f16a51bc22376af1f53dddb24e399112b Mon Sep 17 00:00:00 2001
From: Andreas Jonson <andjo403 at hotmail.com>
Date: Wed, 17 Apr 2024 22:30:02 +0200
Subject: [PATCH 3/4] Take poison-generating attributes into account
---
llvm/include/llvm/IR/Instruction.h | 15 +++++++++++---
llvm/include/llvm/IR/Operator.h | 4 ++--
llvm/lib/IR/Instruction.cpp | 23 ++++++++++++++++++++++
llvm/lib/IR/Operator.cpp | 3 ++-
llvm/test/Transforms/InstCombine/freeze.ll | 6 +++---
5 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h
index c8ad547706c553..0c6c16eb61dd3f 100644
--- a/llvm/include/llvm/IR/Instruction.h
+++ b/llvm/include/llvm/IR/Instruction.h
@@ -496,14 +496,23 @@ class Instruction : public User,
/// Drops metadata that may generate poison.
void dropPoisonGeneratingMetadata();
- /// Return true if this instruction has poison-generating flags or metadata.
+ /// Return true if this instruction has poison-generating attribute.
+ bool hasPoisonGeneratingAttribute() const LLVM_READONLY;
+
+ /// Drops attributes that may generate poison.
+ void dropPoisonGeneratingAttribute();
+
+ /// Return true if this instruction has poison-generating flags, attributes or
+ /// metadata.
bool hasPoisonGeneratingAnnotations() const {
- return hasPoisonGeneratingFlags() || hasPoisonGeneratingMetadata();
+ return hasPoisonGeneratingFlags() || hasPoisonGeneratingAttribute() ||
+ hasPoisonGeneratingMetadata();
}
- /// Drops flags and metadata that may generate poison.
+ /// Drops flags, attributes and metadata that may generate poison.
void dropPoisonGeneratingAnnotations() {
dropPoisonGeneratingFlags();
+ dropPoisonGeneratingAttribute();
dropPoisonGeneratingMetadata();
}
diff --git a/llvm/include/llvm/IR/Operator.h b/llvm/include/llvm/IR/Operator.h
index 2b1598b778d493..860f10adab005d 100644
--- a/llvm/include/llvm/IR/Operator.h
+++ b/llvm/include/llvm/IR/Operator.h
@@ -64,8 +64,8 @@ class Operator : public User {
/// to evaluate to poison despite having non-poison inputs.
bool hasPoisonGeneratingFlags() const;
- /// Return true if this operator has poison-generating flags or metadata.
- /// The latter is only possible for instructions.
+ /// Return true if this operator has poison-generating flags, attributes or
+ /// metadata. The latter two is only possible for instructions.
bool hasPoisonGeneratingAnnotations() const;
};
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index b9efe9cdcfe310..4df5ee63ac183c 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -13,7 +13,9 @@
#include "llvm/IR/Instruction.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/IR/AttributeMask.h"
+#include "llvm/IR/Attributes.h"
#include "llvm/IR/Constants.h"
+#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
@@ -472,6 +474,27 @@ void Instruction::dropPoisonGeneratingMetadata() {
eraseMetadata(LLVMContext::MD_align);
}
+bool Instruction::hasPoisonGeneratingAttribute() const {
+ if (const auto *CB = dyn_cast<CallBase>(this)) {
+ AttributeSet RetAttrs = CB->getAttributes().getRetAttrs();
+ return RetAttrs.hasAttribute(Attribute::Range) ||
+ RetAttrs.hasAttribute(Attribute::Alignment) ||
+ RetAttrs.hasAttribute(Attribute::NonNull);
+ }
+ return false;
+}
+
+void Instruction::dropPoisonGeneratingAttribute() {
+ if (auto *CB = dyn_cast<CallBase>(this)) {
+ AttributeMask AM;
+ AM.addAttribute(Attribute::Range);
+ AM.addAttribute(Attribute::Alignment);
+ AM.addAttribute(Attribute::NonNull);
+ CB->removeRetAttrs(AM);
+ }
+ assert(!hasPoisonGeneratingAttribute() && "must be kept in sync");
+}
+
void Instruction::dropUBImplyingAttrsAndUnknownMetadata(
ArrayRef<unsigned> KnownIDs) {
dropUnknownNonDebugMetadata(KnownIDs);
diff --git a/llvm/lib/IR/Operator.cpp b/llvm/lib/IR/Operator.cpp
index 46d645a313c4b3..eeefd4178ce37d 100644
--- a/llvm/lib/IR/Operator.cpp
+++ b/llvm/lib/IR/Operator.cpp
@@ -60,7 +60,8 @@ bool Operator::hasPoisonGeneratingAnnotations() const {
if (hasPoisonGeneratingFlags())
return true;
auto *I = dyn_cast<Instruction>(this);
- return I && I->hasPoisonGeneratingMetadata();
+ return I && (I->hasPoisonGeneratingAttribute() ||
+ I->hasPoisonGeneratingMetadata());
}
Type *GEPOperator::getSourceElementType() const {
diff --git a/llvm/test/Transforms/InstCombine/freeze.ll b/llvm/test/Transforms/InstCombine/freeze.ll
index 4503b1feab75dd..adcf7d50f413be 100644
--- a/llvm/test/Transforms/InstCombine/freeze.ll
+++ b/llvm/test/Transforms/InstCombine/freeze.ll
@@ -1166,7 +1166,7 @@ define i32 @freeze_call_with_range_attr(i32 %a) {
; CHECK-LABEL: @freeze_call_with_range_attr(
; CHECK-NEXT: [[Y:%.*]] = lshr i32 2047, [[A:%.*]]
; CHECK-NEXT: [[Y_FR:%.*]] = freeze i32 [[Y]]
-; CHECK-NEXT: [[X:%.*]] = call range(i32 0, 2048) i32 @llvm.umax.i32(i32 [[Y_FR]], i32 50)
+; CHECK-NEXT: [[X:%.*]] = call i32 @llvm.umax.i32(i32 [[Y_FR]], i32 50)
; CHECK-NEXT: ret i32 [[X]]
;
%y = lshr i32 2047, %a
@@ -1180,7 +1180,7 @@ declare ptr @llvm.ptrmask.p0.i64(ptr, i64)
define ptr @freeze_ptrmask_align(ptr %p, i64 noundef %m) {
; CHECK-LABEL: @freeze_ptrmask_align(
; CHECK-NEXT: [[P_FR:%.*]] = freeze ptr [[P:%.*]]
-; CHECK-NEXT: [[MASK:%.*]] = call align 4 ptr @llvm.ptrmask.p0.i64(ptr [[P_FR]], i64 [[M:%.*]])
+; CHECK-NEXT: [[MASK:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P_FR]], i64 [[M:%.*]])
; CHECK-NEXT: ret ptr [[MASK]]
;
%mask = call align(4) ptr @llvm.ptrmask.p0.i64(ptr %p, i64 %m)
@@ -1191,7 +1191,7 @@ define ptr @freeze_ptrmask_align(ptr %p, i64 noundef %m) {
define ptr @freeze_ptrmask_nonnull(ptr %p, i64 noundef %m) {
; CHECK-LABEL: @freeze_ptrmask_nonnull(
; CHECK-NEXT: [[P_FR:%.*]] = freeze ptr [[P:%.*]]
-; CHECK-NEXT: [[MASK:%.*]] = call nonnull ptr @llvm.ptrmask.p0.i64(ptr [[P_FR]], i64 [[M:%.*]])
+; CHECK-NEXT: [[MASK:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P_FR]], i64 [[M:%.*]])
; CHECK-NEXT: ret ptr [[MASK]]
;
%mask = call nonnull ptr @llvm.ptrmask.p0.i64(ptr %p, i64 %m)
>From a434905b8f86e0b19f28117e2d1823d1a96e67e3 Mon Sep 17 00:00:00 2001
From: Andreas Jonson <andjo403 at hotmail.com>
Date: Thu, 18 Apr 2024 07:58:17 +0200
Subject: [PATCH 4/4] fixup! Take poison-generating attributes into account
---
llvm/include/llvm/IR/Instruction.h | 17 +++++++++--------
llvm/include/llvm/IR/Operator.h | 5 +++--
llvm/lib/IR/Instruction.cpp | 6 +++---
llvm/lib/IR/Operator.cpp | 2 +-
4 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h
index 0c6c16eb61dd3f..249be2799fa93d 100644
--- a/llvm/include/llvm/IR/Instruction.h
+++ b/llvm/include/llvm/IR/Instruction.h
@@ -497,22 +497,23 @@ class Instruction : public User,
void dropPoisonGeneratingMetadata();
/// Return true if this instruction has poison-generating attribute.
- bool hasPoisonGeneratingAttribute() const LLVM_READONLY;
+ bool hasPoisonGeneratingReturnAttributes() const LLVM_READONLY;
- /// Drops attributes that may generate poison.
- void dropPoisonGeneratingAttribute();
+ /// Drops return attributes that may generate poison.
+ void dropPoisonGeneratingReturnAttributes();
- /// Return true if this instruction has poison-generating flags, attributes or
- /// metadata.
+ /// Return true if this instruction has poison-generating flags,
+ /// return attributes or metadata.
bool hasPoisonGeneratingAnnotations() const {
- return hasPoisonGeneratingFlags() || hasPoisonGeneratingAttribute() ||
+ return hasPoisonGeneratingFlags() ||
+ hasPoisonGeneratingReturnAttributes() ||
hasPoisonGeneratingMetadata();
}
- /// Drops flags, attributes and metadata that may generate poison.
+ /// Drops flags, return attributes and metadata that may generate poison.
void dropPoisonGeneratingAnnotations() {
dropPoisonGeneratingFlags();
- dropPoisonGeneratingAttribute();
+ dropPoisonGeneratingReturnAttributes();
dropPoisonGeneratingMetadata();
}
diff --git a/llvm/include/llvm/IR/Operator.h b/llvm/include/llvm/IR/Operator.h
index 860f10adab005d..b2307948bbbc4f 100644
--- a/llvm/include/llvm/IR/Operator.h
+++ b/llvm/include/llvm/IR/Operator.h
@@ -64,8 +64,9 @@ class Operator : public User {
/// to evaluate to poison despite having non-poison inputs.
bool hasPoisonGeneratingFlags() const;
- /// Return true if this operator has poison-generating flags, attributes or
- /// metadata. The latter two is only possible for instructions.
+ /// Return true if this operator has poison-generating flags,
+ /// return attributes or metadata. The latter two is only possible for
+ /// instructions.
bool hasPoisonGeneratingAnnotations() const;
};
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index 4df5ee63ac183c..6cab3c15124162 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -474,7 +474,7 @@ void Instruction::dropPoisonGeneratingMetadata() {
eraseMetadata(LLVMContext::MD_align);
}
-bool Instruction::hasPoisonGeneratingAttribute() const {
+bool Instruction::hasPoisonGeneratingReturnAttributes() const {
if (const auto *CB = dyn_cast<CallBase>(this)) {
AttributeSet RetAttrs = CB->getAttributes().getRetAttrs();
return RetAttrs.hasAttribute(Attribute::Range) ||
@@ -484,7 +484,7 @@ bool Instruction::hasPoisonGeneratingAttribute() const {
return false;
}
-void Instruction::dropPoisonGeneratingAttribute() {
+void Instruction::dropPoisonGeneratingReturnAttributes() {
if (auto *CB = dyn_cast<CallBase>(this)) {
AttributeMask AM;
AM.addAttribute(Attribute::Range);
@@ -492,7 +492,7 @@ void Instruction::dropPoisonGeneratingAttribute() {
AM.addAttribute(Attribute::NonNull);
CB->removeRetAttrs(AM);
}
- assert(!hasPoisonGeneratingAttribute() && "must be kept in sync");
+ assert(!hasPoisonGeneratingReturnAttributes() && "must be kept in sync");
}
void Instruction::dropUBImplyingAttrsAndUnknownMetadata(
diff --git a/llvm/lib/IR/Operator.cpp b/llvm/lib/IR/Operator.cpp
index eeefd4178ce37d..29620ef716f25f 100644
--- a/llvm/lib/IR/Operator.cpp
+++ b/llvm/lib/IR/Operator.cpp
@@ -60,7 +60,7 @@ bool Operator::hasPoisonGeneratingAnnotations() const {
if (hasPoisonGeneratingFlags())
return true;
auto *I = dyn_cast<Instruction>(this);
- return I && (I->hasPoisonGeneratingAttribute() ||
+ return I && (I->hasPoisonGeneratingReturnAttributes() ||
I->hasPoisonGeneratingMetadata());
}
More information about the llvm-commits
mailing list