Skip to content

Commit d6e8f3b

Browse files
committed
[ValueTracking] Convert isKnownPositive() to use SimplifyQuery (NFC)
1 parent 52b4b35 commit d6e8f3b

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

llvm/include/llvm/Analysis/ValueTracking.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,8 @@ bool isKnownNonNegative(const Value *V, const SimplifyQuery &SQ,
143143

144144
/// Returns true if the given value is known be positive (i.e. non-negative
145145
/// and non-zero).
146-
bool isKnownPositive(const Value *V, const DataLayout &DL, unsigned Depth = 0,
147-
AssumptionCache *AC = nullptr,
148-
const Instruction *CxtI = nullptr,
149-
const DominatorTree *DT = nullptr,
150-
bool UseInstrInfo = true);
146+
bool isKnownPositive(const Value *V, const SimplifyQuery &SQ,
147+
unsigned Depth = 0);
151148

152149
/// Returns true if the given value is known be negative (i.e. non-positive
153150
/// and non-zero).

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,14 @@ bool llvm::isKnownNonNegative(const Value *V, const SimplifyQuery &SQ,
281281
return computeKnownBits(V, Depth, SQ).isNonNegative();
282282
}
283283

284-
bool llvm::isKnownPositive(const Value *V, const DataLayout &DL, unsigned Depth,
285-
AssumptionCache *AC, const Instruction *CxtI,
286-
const DominatorTree *DT, bool UseInstrInfo) {
284+
bool llvm::isKnownPositive(const Value *V, const SimplifyQuery &SQ,
285+
unsigned Depth) {
287286
if (auto *CI = dyn_cast<ConstantInt>(V))
288287
return CI->getValue().isStrictlyPositive();
289288

290289
// TODO: We'd doing two recursive queries here. We should factor this such
291290
// that only a single query is needed.
292-
return isKnownNonNegative(V, SimplifyQuery(DL, DT, AC, CxtI, UseInstrInfo),
293-
Depth) &&
294-
isKnownNonZero(V, DL, Depth, AC, CxtI, DT, UseInstrInfo);
291+
return isKnownNonNegative(V, SQ, Depth) && ::isKnownNonZero(V, Depth, SQ);
295292
}
296293

297294
bool llvm::isKnownNegative(const Value *V, const DataLayout &DL, unsigned Depth,

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,9 +1202,9 @@ Instruction *InstCombinerImpl::foldICmpWithZero(ICmpInst &Cmp) {
12021202
if (Pred == ICmpInst::ICMP_SGT) {
12031203
Value *A, *B;
12041204
if (match(Cmp.getOperand(0), m_SMin(m_Value(A), m_Value(B)))) {
1205-
if (isKnownPositive(A, DL, 0, &AC, &Cmp, &DT))
1205+
if (isKnownPositive(A, SQ.getWithInstruction(&Cmp)))
12061206
return new ICmpInst(Pred, B, Cmp.getOperand(1));
1207-
if (isKnownPositive(B, DL, 0, &AC, &Cmp, &DT))
1207+
if (isKnownPositive(B, SQ.getWithInstruction(&Cmp)))
12081208
return new ICmpInst(Pred, A, Cmp.getOperand(1));
12091209
}
12101210
}

0 commit comments

Comments
 (0)