[llvm] b13e942 - [ValueTracking] Add a two argument form of safeCtxI [NFC]
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 19 14:52:59 PST 2021
Author: Philip Reames
Date: 2021-02-19T14:52:51-08:00
New Revision: b13e9422242df04c3b33a307ac50faad15d9b7e3
URL: https://github.com/llvm/llvm-project/commit/b13e9422242df04c3b33a307ac50faad15d9b7e3
DIFF: https://github.com/llvm/llvm-project/commit/b13e9422242df04c3b33a307ac50faad15d9b7e3.diff
LOG: [ValueTracking] Add a two argument form of safeCtxI [NFC]
The existing implementation was relying on order of evaluation to achieve a particular result. This got really confusing when wanting to change the handling for arguments in a later patch.
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index edf165c1a582..600509fa40b8 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -161,6 +161,24 @@ static const Instruction *safeCxtI(const Value *V, const Instruction *CxtI) {
return nullptr;
}
+static const Instruction *safeCxtI(const Value *V1, const Value *V2, const Instruction *CxtI) {
+ // If we've been provided with a context instruction, then use that (provided
+ // it has been inserted).
+ if (CxtI && CxtI->getParent())
+ return CxtI;
+
+ // If the value is really an already-inserted instruction, then use that.
+ CxtI = dyn_cast<Instruction>(V1);
+ if (CxtI && CxtI->getParent())
+ return CxtI;
+
+ CxtI = dyn_cast<Instruction>(V2);
+ if (CxtI && CxtI->getParent())
+ return CxtI;
+
+ return nullptr;
+}
+
static bool getShuffleDemandedElts(const ShuffleVectorInst *Shuf,
const APInt &DemandedElts,
APInt &DemandedLHS, APInt &DemandedRHS) {
@@ -358,7 +376,7 @@ bool llvm::isKnownNonEqual(const Value *V1, const Value *V2,
const Instruction *CxtI, const DominatorTree *DT,
bool UseInstrInfo) {
return ::isKnownNonEqual(V1, V2, 0,
- Query(DL, AC, safeCxtI(V1, safeCxtI(V2, CxtI)), DT,
+ Query(DL, AC, safeCxtI(V2, V1, CxtI), DT,
UseInstrInfo, /*ORE=*/nullptr));
}
More information about the llvm-commits
mailing list