diff options
author | Juneyoung Lee <aqjune@gmail.com> | 2020-07-20 09:21:28 +0900 |
---|---|---|
committer | Juneyoung Lee <aqjune@gmail.com> | 2020-07-20 09:21:39 +0900 |
commit | 30201d3b611f034214e6e1bc8c8faae7d1246ec8 (patch) | |
tree | 0d884998bd0cadc766e032c0aa7b4c4edb773877 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | cf1105069648446d58adfb7a6cc590013d6886ba (diff) | |
download | llvm-30201d3b611f034214e6e1bc8c8faae7d1246ec8.zip llvm-30201d3b611f034214e6e1bc8c8faae7d1246ec8.tar.gz llvm-30201d3b611f034214e6e1bc8c8faae7d1246ec8.tar.bz2 |
[ValueTracking] Let isGuaranteedNotToBeUndefOrPoison use canCreateUndefOrPoison
This patch adds support more operations.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D83926
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 55 |
1 files changed, 18 insertions, 37 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 380022c..ed22718 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -4779,23 +4779,13 @@ bool llvm::isGuaranteedNotToBeUndefOrPoison(const Value *V, if (Depth >= MaxDepth) return false; - // If the value is a freeze instruction, then it can never - // be undef or poison. - if (isa<FreezeInst>(V)) - return true; - // TODO: Some instructions are guaranteed to return neither undef - // nor poison if their arguments are not poison/undef. - - if (auto *A = dyn_cast<Argument>(V)) { - // NoUndef does not guarantee that paddings are not undef. + if (const auto *A = dyn_cast<Argument>(V)) { if (A->hasAttribute(Attribute::NoUndef)) return true; } if (auto *C = dyn_cast<Constant>(V)) { - // TODO: We can analyze ConstExpr by opcode to determine if there is any - // possibility of poison. - if (isa<UndefValue>(C) || isa<ConstantExpr>(C)) + if (isa<UndefValue>(C)) return false; if (isa<ConstantInt>(C) || isa<GlobalVariable>(C) || isa<ConstantFP>(V) || @@ -4804,9 +4794,6 @@ bool llvm::isGuaranteedNotToBeUndefOrPoison(const Value *V, if (C->getType()->isVectorTy()) return !C->containsUndefElement() && !C->containsConstantExpression(); - - // TODO: Recursively analyze aggregates or other constants. - return false; } // Strip cast operations from a pointer value. @@ -4826,31 +4813,25 @@ bool llvm::isGuaranteedNotToBeUndefOrPoison(const Value *V, return isGuaranteedNotToBeUndefOrPoison(V, CtxI, DT, Depth + 1); }; - if (auto *I = dyn_cast<Instruction>(V)) { - switch (I->getOpcode()) { - case Instruction::GetElementPtr: { - auto *GEPI = dyn_cast<GetElementPtrInst>(I); - if (!GEPI->isInBounds() && llvm::all_of(GEPI->operands(), OpCheck)) - return true; - break; - } - case Instruction::FCmp: { - auto *FI = dyn_cast<FCmpInst>(I); - if (FI->getFastMathFlags().none() && - llvm::all_of(FI->operands(), OpCheck)) - return true; - break; - } - case Instruction::BitCast: - case Instruction::PHI: - case Instruction::ICmp: - if (llvm::all_of(I->operands(), OpCheck)) + if (auto *Opr = dyn_cast<Operator>(V)) { + // If the value is a freeze instruction, then it can never + // be undef or poison. + if (isa<FreezeInst>(V)) + return true; + + if (const auto *CB = dyn_cast<CallBase>(V)) { + if (CB->hasRetAttr(Attribute::NoUndef)) return true; - break; - default: - break; } + if (canCreateUndefOrPoison(Opr)) + return false; + + if (all_of(Opr->operands(), OpCheck)) + return true; + } + + if (auto *I = dyn_cast<Instruction>(V)) { if (programUndefinedIfPoison(I) && I->getType()->isIntegerTy(1)) // Note: once we have an agreement that poison is a value-wise concept, // we can remove the isIntegerTy(1) constraint. |