Skip to content

Commit c5aacb0

Browse files
committed
[ValueTracking] Add fast path to avoid second recursive call in isKnownPositive; NFC
Just a simple compile time improvement. This function isn't used much, however, so its not particularly impactful. Closes llvm#83638
1 parent a6c8407 commit c5aacb0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,11 @@ bool llvm::isKnownPositive(const Value *V, const SimplifyQuery &SQ,
294294
if (auto *CI = dyn_cast<ConstantInt>(V))
295295
return CI->getValue().isStrictlyPositive();
296296

297-
// TODO: We'd doing two recursive queries here. We should factor this such
298-
// that only a single query is needed.
299-
return isKnownNonNegative(V, SQ, Depth) && ::isKnownNonZero(V, Depth, SQ);
297+
// If `isKnownNonNegative` ever becomes more sophisticated, make sure to keep
298+
// this updated.
299+
KnownBits Known = computeKnownBits(V, Depth, SQ);
300+
return Known.isNonNegative() &&
301+
(Known.isNonZero() || ::isKnownNonZero(V, Depth, SQ));
300302
}
301303

302304
bool llvm::isKnownNegative(const Value *V, const SimplifyQuery &SQ,

0 commit comments

Comments
 (0)