Skip to content

Commit 7ef2c68

Browse files
committed
[InstSimplify] improve efficiency for detecting non-zero value
Stepping through callstacks in the example from D99759 reveals this potential compile-time improvement. The savings come from avoiding ValueTracking's computing known bits if we have already dealt with special-case patterns. Further improvements in this direction seem possible. This makes a degenerate test based on PR49785 about 40x faster (25 sec -> 0.6 sec), but it does not address the larger question of how to limit computeKnownBitsFromAssume(). Ie, the original test there is still infinite-time for all practical purposes. Differential Revision: https://reviews.llvm.org/D100408
1 parent 5ae5d25 commit 7ef2c68

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3432,6 +3432,8 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
34323432
if (Value *V = simplifyICmpOfBools(Pred, LHS, RHS, Q))
34333433
return V;
34343434

3435+
// TODO: Sink/common this with other potentially expensive calls that use
3436+
// ValueTracking? See comment below for isKnownNonEqual().
34353437
if (Value *V = simplifyICmpWithZero(Pred, LHS, RHS, Q))
34363438
return V;
34373439

@@ -3637,7 +3639,9 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
36373639
}
36383640

36393641
// icmp eq|ne X, Y -> false|true if X != Y
3640-
if (ICmpInst::isEquality(Pred) &&
3642+
// This is potentially expensive, and we have already computedKnownBits for
3643+
// compares with 0 above here, so only try this for a non-zero compare.
3644+
if (ICmpInst::isEquality(Pred) && !match(RHS, m_Zero()) &&
36413645
isKnownNonEqual(LHS, RHS, Q.DL, Q.AC, Q.CxtI, Q.DT, Q.IIQ.UseInstrInfo)) {
36423646
return Pred == ICmpInst::ICMP_NE ? getTrue(ITy) : getFalse(ITy);
36433647
}

0 commit comments

Comments
 (0)