Skip to content

Commit d9e8ae7

Browse files
committed
[ValueTracking] Convert MaskedValueIsZero() to use SimplifyQuery (NFC)
1 parent 42b6c8e commit d9e8ae7

File tree

5 files changed

+12
-36
lines changed

5 files changed

+12
-36
lines changed

llvm/include/llvm/Analysis/ValueTracking.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,8 @@ bool isKnownNonEqual(const Value *V1, const Value *V2, const DataLayout &DL,
168168
/// where V is a vector, the mask, known zero, and known one values are the
169169
/// same width as the vector element, and the bit is set only if it is true
170170
/// for all of the elements in the vector.
171-
bool MaskedValueIsZero(const Value *V, const APInt &Mask, const DataLayout &DL,
172-
unsigned Depth = 0, AssumptionCache *AC = nullptr,
173-
const Instruction *CxtI = nullptr,
174-
const DominatorTree *DT = nullptr,
175-
bool UseInstrInfo = true);
171+
bool MaskedValueIsZero(const Value *V, const APInt &Mask,
172+
const SimplifyQuery &DL, unsigned Depth = 0);
176173

177174
/// Return the number of times the sign bit of the register is replicated into
178175
/// the other bits. We know that at least 1 bit is always equal to the sign

llvm/include/llvm/Transforms/InstCombine/InstCombiner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
480480

481481
bool MaskedValueIsZero(const Value *V, const APInt &Mask, unsigned Depth = 0,
482482
const Instruction *CxtI = nullptr) const {
483-
return llvm::MaskedValueIsZero(V, Mask, DL, Depth, &AC, CxtI, &DT);
483+
return llvm::MaskedValueIsZero(V, Mask, SQ.getWithInstruction(CxtI), Depth);
484484
}
485485

486486
unsigned ComputeNumSignBits(const Value *Op, unsigned Depth = 0,

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ static LinearExpression GetLinearExpression(
395395
case Instruction::Or:
396396
// X|C == X+C if all the bits in C are unset in X. Otherwise we can't
397397
// analyze it.
398-
if (!MaskedValueIsZero(BOp->getOperand(0), RHSC->getValue(), DL, 0, AC,
399-
BOp, DT))
398+
if (!MaskedValueIsZero(BOp->getOperand(0), RHSC->getValue(),
399+
SimplifyQuery(DL, DT, AC, BOp)))
400400
return Val;
401401

402402
[[fallthrough]];

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,13 +2445,13 @@ static Value *simplifyOrInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
24452445
if (C2->isMask() && // C2 == 0+1+
24462446
match(A, m_c_Add(m_Specific(B), m_Value(N)))) {
24472447
// Add commutes, try both ways.
2448-
if (MaskedValueIsZero(N, *C2, Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
2448+
if (MaskedValueIsZero(N, *C2, Q))
24492449
return A;
24502450
}
24512451
// Or commutes, try both ways.
24522452
if (C1->isMask() && match(B, m_c_Add(m_Specific(A), m_Value(N)))) {
24532453
// Add commutes, try both ways.
2454-
if (MaskedValueIsZero(N, *C1, Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
2454+
if (MaskedValueIsZero(N, *C1, Q))
24552455
return B;
24562456
}
24572457
}
@@ -6202,7 +6202,7 @@ static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0,
62026202
// ctpop(and X, 1) --> and X, 1
62036203
unsigned BitWidth = Op0->getType()->getScalarSizeInBits();
62046204
if (MaskedValueIsZero(Op0, APInt::getHighBitsSet(BitWidth, BitWidth - 1),
6205-
Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
6205+
Q))
62066206
return Op0;
62076207
break;
62086208
}

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -308,16 +308,11 @@ bool llvm::isKnownNonEqual(const Value *V1, const Value *V2,
308308
SimplifyQuery(DL, DT, AC, safeCxtI(V2, V1, CxtI), UseInstrInfo));
309309
}
310310

311-
static bool MaskedValueIsZero(const Value *V, const APInt &Mask, unsigned Depth,
312-
const SimplifyQuery &Q);
313-
314311
bool llvm::MaskedValueIsZero(const Value *V, const APInt &Mask,
315-
const DataLayout &DL, unsigned Depth,
316-
AssumptionCache *AC, const Instruction *CxtI,
317-
const DominatorTree *DT, bool UseInstrInfo) {
318-
return ::MaskedValueIsZero(
319-
V, Mask, Depth,
320-
SimplifyQuery(DL, DT, AC, safeCxtI(V, CxtI), UseInstrInfo));
312+
const SimplifyQuery &SQ, unsigned Depth) {
313+
KnownBits Known(Mask.getBitWidth());
314+
computeKnownBits(V, Known, Depth, SQ);
315+
return Mask.isSubsetOf(Known.Zero);
321316
}
322317

323318
static unsigned ComputeNumSignBits(const Value *V, const APInt &DemandedElts,
@@ -3124,22 +3119,6 @@ static bool isKnownNonEqual(const Value *V1, const Value *V2, unsigned Depth,
31243119
return false;
31253120
}
31263121

3127-
/// Return true if 'V & Mask' is known to be zero. We use this predicate to
3128-
/// simplify operations downstream. Mask is known to be zero for bits that V
3129-
/// cannot have.
3130-
///
3131-
/// This function is defined on values with integer type, values with pointer
3132-
/// type, and vectors of integers. In the case
3133-
/// where V is a vector, the mask, known zero, and known one values are the
3134-
/// same width as the vector element, and the bit is set only if it is true
3135-
/// for all of the elements in the vector.
3136-
bool MaskedValueIsZero(const Value *V, const APInt &Mask, unsigned Depth,
3137-
const SimplifyQuery &Q) {
3138-
KnownBits Known(Mask.getBitWidth());
3139-
computeKnownBits(V, Known, Depth, Q);
3140-
return Mask.isSubsetOf(Known.Zero);
3141-
}
3142-
31433122
// Match a signed min+max clamp pattern like smax(smin(In, CHigh), CLow).
31443123
// Returns the input and lower/upper bounds.
31453124
static bool isSignedMinMaxClamp(const Value *Select, const Value *&In,

0 commit comments

Comments
 (0)