Skip to content

Commit 626c231

Browse files
authored
[ValueTracking] Use SimplifyQuery in isKnownNonEqual (#124942)
It is needed by #117442.
1 parent 83cad68 commit 626c231

File tree

6 files changed

+11
-20
lines changed

6 files changed

+11
-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 &SQ,
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,8 +1349,10 @@ AliasResult BasicAAResult::aliasGEP(
13491349
const VariableGEPIndex &Var1 = DecompGEP1.VarIndices[1];
13501350
if (Var0.hasNegatedScaleOf(Var1) && Var0.Val.TruncBits == 0 &&
13511351
Var0.Val.hasSameCastsAs(Var1.Val) && !AAQI.MayBeCrossIteration &&
1352-
isKnownNonEqual(Var0.Val.V, Var1.Val.V, DL, &AC, /* CxtI */ nullptr,
1353-
DT))
1352+
isKnownNonEqual(Var0.Val.V, Var1.Val.V,
1353+
SimplifyQuery(DL, DT, &AC, /*CxtI=*/Var0.CxtI
1354+
? Var0.CxtI
1355+
: Var1.CxtI)))
13541356
MinAbsVarIndex = Var0.Scale.abs();
13551357
}
13561358

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3994,7 +3994,7 @@ static Value *simplifyICmpInst(CmpPredicate Pred, Value *LHS, Value *RHS,
39943994
// This is potentially expensive, and we have already computedKnownBits for
39953995
// compares with 0 above here, so only try this for a non-zero compare.
39963996
if (ICmpInst::isEquality(Pred) && !match(RHS, m_Zero()) &&
3997-
isKnownNonEqual(LHS, RHS, Q.DL, Q.AC, Q.CxtI, Q.DT, Q.IIQ.UseInstrInfo)) {
3997+
isKnownNonEqual(LHS, RHS, Q)) {
39983998
return Pred == ICmpInst::ICMP_NE ? getTrue(ITy) : getFalse(ITy);
39993999
}
40004000

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,18 +316,14 @@ static bool isKnownNonEqual(const Value *V1, const Value *V2,
316316
const SimplifyQuery &Q);
317317

318318
bool llvm::isKnownNonEqual(const Value *V1, const Value *V2,
319-
const DataLayout &DL, AssumptionCache *AC,
320-
const Instruction *CxtI, const DominatorTree *DT,
321-
bool UseInstrInfo) {
319+
const SimplifyQuery &Q, unsigned Depth) {
322320
// We don't support looking through casts.
323321
if (V1 == V2 || V1->getType() != V2->getType())
324322
return false;
325323
auto *FVTy = dyn_cast<FixedVectorType>(V1->getType());
326324
APInt DemandedElts =
327325
FVTy ? APInt::getAllOnes(FVTy->getNumElements()) : APInt(1, 1);
328-
return ::isKnownNonEqual(
329-
V1, V2, DemandedElts, 0,
330-
SimplifyQuery(DL, DT, AC, safeCxtI(V2, V1, CxtI), UseInstrInfo));
326+
return ::isKnownNonEqual(V1, V2, DemandedElts, Depth, Q);
331327
}
332328

333329
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
@@ -5411,7 +5411,7 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
54115411
if (ICmpInst::isEquality(Pred)) {
54125412
// If X != Y, fold (X *nw Z) eq/ne (Y *nw Z) -> Z eq/ne 0
54135413
if (((Op0HasNSW && Op1HasNSW) || (Op0HasNUW && Op1HasNUW)) &&
5414-
isKnownNonEqual(X, Y, DL, &AC, &I, &DT))
5414+
isKnownNonEqual(X, Y, SQ))
54155415
return new ICmpInst(Pred, Z, Constant::getNullValue(Z->getType()));
54165416

54175417
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)