aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2023-05-29 15:44:35 +0100
committerFlorian Hahn <flo@fhahn.com>2023-05-29 15:44:37 +0100
commitcd2fc73b49851540b06f91e89a42bdc5affa7e49 (patch)
treee0be6d048d1c106ddc4e0365563e986f13997219 /llvm/lib/Analysis/ValueTracking.cpp
parentab05d9134d18db34501985a01fbfc02609767587 (diff)
downloadllvm-cd2fc73b49851540b06f91e89a42bdc5affa7e49.zip
llvm-cd2fc73b49851540b06f91e89a42bdc5affa7e49.tar.gz
llvm-cd2fc73b49851540b06f91e89a42bdc5affa7e49.tar.bz2
Revert "[ValueTracking][InstCombine] Add a new API to allow to ignore poison generating flags or metadatas when implying poison"
This reverts commit 754f3ae65518331b7175d7a9b4a124523ebe6eac. Unfortunately the change can cause regressions due to dropping flags from instructions (like nuw,nsw,inbounds), prevent further optimizations depending on those flags. A simple example is the IR below, where `inbounds` is dropped with the patch and the phase-ordering test added in 7c91d82ab912fae8b. define i1 @test(ptr %base, i64 noundef %len, ptr %p2) { bb: %gep = getelementptr inbounds i32, ptr %base, i64 %len %c.1 = icmp uge ptr %p2, %base %c.2 = icmp ult ptr %p2, %gep %select = select i1 %c.1, i1 %c.2, i1 false ret i1 %select } For more discussion, see D149404.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp34
1 files changed, 10 insertions, 24 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 7ec34cd..fc15fb8 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -6599,9 +6599,8 @@ static bool directlyImpliesPoison(const Value *ValAssumedPoison,
return false;
}
-static bool
-impliesPoison(Value *ValAssumedPoison, const Value *V, unsigned Depth,
- SmallVectorImpl<Instruction *> *IgnoredInsts = nullptr) {
+static bool impliesPoison(const Value *ValAssumedPoison, const Value *V,
+ unsigned Depth) {
if (isGuaranteedNotToBePoison(ValAssumedPoison))
return true;
@@ -6612,30 +6611,17 @@ impliesPoison(Value *ValAssumedPoison, const Value *V, unsigned Depth,
if (Depth >= MaxDepth)
return false;
- auto *I = dyn_cast<Instruction>(ValAssumedPoison);
- if (!I || canCreatePoison(cast<Operator>(I),
- /*ConsiderFlagsAndMetadata*/ !IgnoredInsts))
- return false;
-
- for (Value *Op : I->operands())
- if (!impliesPoison(Op, V, Depth + 1, IgnoredInsts))
- return false;
-
- if (IgnoredInsts && I->hasPoisonGeneratingFlagsOrMetadata())
- IgnoredInsts->push_back(I);
-
- return true;
+ const auto *I = dyn_cast<Instruction>(ValAssumedPoison);
+ if (I && !canCreatePoison(cast<Operator>(I))) {
+ return all_of(I->operands(), [=](const Value *Op) {
+ return impliesPoison(Op, V, Depth + 1);
+ });
+ }
+ return false;
}
bool llvm::impliesPoison(const Value *ValAssumedPoison, const Value *V) {
- return ::impliesPoison(const_cast<Value *>(ValAssumedPoison), V,
- /* Depth */ 0);
-}
-
-bool llvm::impliesPoisonIgnoreFlagsOrMetadata(
- Value *ValAssumedPoison, const Value *V,
- SmallVectorImpl<Instruction *> &IgnoredInsts) {
- return ::impliesPoison(ValAssumedPoison, V, /* Depth */ 0, &IgnoredInsts);
+ return ::impliesPoison(ValAssumedPoison, V, /* Depth */ 0);
}
static bool programUndefinedIfUndefOrPoison(const Value *V,