Skip to content

Commit 8f3cf20

Browse files
committed
[ValueTracking] Convert isKnownNonEqual to use SimplifyQuery
1 parent d6fad59 commit 8f3cf20

File tree

6 files changed

+10
-20
lines changed

6 files changed

+10
-20
lines changed

llvm/include/llvm/Analysis/ValueTracking.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,8 @@ bool isKnownNegative(const Value *V, const SimplifyQuery &DL,
164164

165165
/// Return true if the given values are known to be non-equal when defined.
166166
/// Supports scalar integer types only.
167-
bool isKnownNonEqual(const Value *V1, const Value *V2, const DataLayout &DL,
168-
AssumptionCache *AC = nullptr,
169-
const Instruction *CxtI = nullptr,
170-
const DominatorTree *DT = nullptr,
171-
bool UseInstrInfo = true);
167+
bool isKnownNonEqual(const Value *V1, const Value *V2, const SimplifyQuery &SQ,
168+
unsigned Depth = 0);
172169

173170
/// Return true if 'V & Mask' is known to be zero. We use this predicate to
174171
/// simplify operations downstream. Mask is known to be zero for bits that V

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,8 +1369,8 @@ AliasResult BasicAAResult::aliasGEP(
13691369
const VariableGEPIndex &Var1 = DecompGEP1.VarIndices[1];
13701370
if (Var0.hasNegatedScaleOf(Var1) && Var0.Val.TruncBits == 0 &&
13711371
Var0.Val.hasSameCastsAs(Var1.Val) && !AAQI.MayBeCrossIteration &&
1372-
isKnownNonEqual(Var0.Val.V, Var1.Val.V, DL, &AC, /* CxtI */ nullptr,
1373-
DT))
1372+
isKnownNonEqual(Var0.Val.V, Var1.Val.V,
1373+
SimplifyQuery(DL, DT, &AC, /*CxtI=*/nullptr)))
13741374
MinAbsVarIndex = Var0.Scale.abs();
13751375
}
13761376

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4014,7 +4014,7 @@ static Value *simplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
40144014
// This is potentially expensive, and we have already computedKnownBits for
40154015
// compares with 0 above here, so only try this for a non-zero compare.
40164016
if (ICmpInst::isEquality(Pred) && !match(RHS, m_Zero()) &&
4017-
isKnownNonEqual(LHS, RHS, Q.DL, Q.AC, Q.CxtI, Q.DT, Q.IIQ.UseInstrInfo)) {
4017+
isKnownNonEqual(LHS, RHS, Q)) {
40184018
return Pred == ICmpInst::ICMP_NE ? getTrue(ITy) : getFalse(ITy);
40194019
}
40204020

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,18 +303,15 @@ static bool isKnownNonEqual(const Value *V1, const Value *V2,
303303
const SimplifyQuery &Q);
304304

305305
bool llvm::isKnownNonEqual(const Value *V1, const Value *V2,
306-
const DataLayout &DL, AssumptionCache *AC,
307-
const Instruction *CxtI, const DominatorTree *DT,
308-
bool UseInstrInfo) {
306+
const SimplifyQuery &Q, unsigned Depth) {
309307
// We don't support looking through casts.
310308
if (V1 == V2 || V1->getType() != V2->getType())
311309
return false;
312310
auto *FVTy = dyn_cast<FixedVectorType>(V1->getType());
313311
APInt DemandedElts =
314312
FVTy ? APInt::getAllOnes(FVTy->getNumElements()) : APInt(1, 1);
315-
return ::isKnownNonEqual(
316-
V1, V2, DemandedElts, 0,
317-
SimplifyQuery(DL, DT, AC, safeCxtI(V2, V1, CxtI), UseInstrInfo));
313+
return ::isKnownNonEqual(V1, V2, DemandedElts, Depth,
314+
Q.getWithInstruction(safeCxtI(V2, V1, Q.CxtI)));
318315
}
319316

320317
bool llvm::MaskedValueIsZero(const Value *V, const APInt &Mask,

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5343,7 +5343,7 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
53435343
if (ICmpInst::isEquality(Pred)) {
53445344
// If X != Y, fold (X *nw Z) eq/ne (Y *nw Z) -> Z eq/ne 0
53455345
if (((Op0HasNSW && Op1HasNSW) || (Op0HasNUW && Op1HasNUW)) &&
5346-
isKnownNonEqual(X, Y, DL, &AC, &I, &DT))
5346+
isKnownNonEqual(X, Y, SQ))
53475347
return new ICmpInst(Pred, Z, Constant::getNullValue(Z->getType()));
53485348

53495349
KnownBits ZKnown = computeKnownBits(Z, 0, &I);

llvm/test/Transforms/InstCombine/known-bits.ll

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,17 +1609,13 @@ if.else:
16091609
ret i16 0
16101610
}
16111611

1612-
; TODO: %cmp always evaluates to false
1613-
16141612
define i1 @test_simplify_icmp2(double %x) {
16151613
; CHECK-LABEL: @test_simplify_icmp2(
16161614
; CHECK-NEXT: [[ABS:%.*]] = tail call double @llvm.fabs.f64(double [[X:%.*]])
16171615
; CHECK-NEXT: [[COND:%.*]] = fcmp oeq double [[ABS]], 0x7FF0000000000000
16181616
; CHECK-NEXT: br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
16191617
; CHECK: if.then:
1620-
; CHECK-NEXT: [[CAST:%.*]] = bitcast double [[X]] to i64
1621-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[CAST]], 3458764513820540928
1622-
; CHECK-NEXT: ret i1 [[CMP]]
1618+
; CHECK-NEXT: ret i1 false
16231619
; CHECK: if.else:
16241620
; CHECK-NEXT: ret i1 false
16251621
;

0 commit comments

Comments
 (0)