Skip to content

Commit b13e942

Browse files
committed
[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.
1 parent 55448ab commit b13e942

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,24 @@ static const Instruction *safeCxtI(const Value *V, const Instruction *CxtI) {
161161
return nullptr;
162162
}
163163

164+
static const Instruction *safeCxtI(const Value *V1, const Value *V2, const Instruction *CxtI) {
165+
// If we've been provided with a context instruction, then use that (provided
166+
// it has been inserted).
167+
if (CxtI && CxtI->getParent())
168+
return CxtI;
169+
170+
// If the value is really an already-inserted instruction, then use that.
171+
CxtI = dyn_cast<Instruction>(V1);
172+
if (CxtI && CxtI->getParent())
173+
return CxtI;
174+
175+
CxtI = dyn_cast<Instruction>(V2);
176+
if (CxtI && CxtI->getParent())
177+
return CxtI;
178+
179+
return nullptr;
180+
}
181+
164182
static bool getShuffleDemandedElts(const ShuffleVectorInst *Shuf,
165183
const APInt &DemandedElts,
166184
APInt &DemandedLHS, APInt &DemandedRHS) {
@@ -358,7 +376,7 @@ bool llvm::isKnownNonEqual(const Value *V1, const Value *V2,
358376
const Instruction *CxtI, const DominatorTree *DT,
359377
bool UseInstrInfo) {
360378
return ::isKnownNonEqual(V1, V2, 0,
361-
Query(DL, AC, safeCxtI(V1, safeCxtI(V2, CxtI)), DT,
379+
Query(DL, AC, safeCxtI(V2, V1, CxtI), DT,
362380
UseInstrInfo, /*ORE=*/nullptr));
363381
}
364382

0 commit comments

Comments
 (0)