Skip to content

Commit b5743d4

Browse files
committed
[ValueTracking] Remove by-ref computeKnownBits() overloads (NFC)
Remove the old overloads that accept KnownBits by reference, in favor of those that return it by value.
1 parent 3b23704 commit b5743d4

File tree

12 files changed

+48
-105
lines changed

12 files changed

+48
-105
lines changed

llvm/include/llvm/Analysis/ValueTracking.h

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,43 +46,26 @@ class Value;
4646

4747
constexpr unsigned MaxAnalysisRecursionDepth = 6;
4848

49-
/// Determine which bits of V are known to be either zero or one and return
50-
/// them in the KnownZero/KnownOne bit sets.
49+
/// Determine which bits of V are known to be either zero or one.
5150
///
5251
/// This function is defined on values with integer type, values with pointer
5352
/// type, and vectors of integers. In the case
5453
/// where V is a vector, the known zero and known one values are the
5554
/// same width as the vector element, and the bit is set only if it is true
5655
/// for all of the elements in the vector.
57-
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL,
58-
unsigned Depth = 0, AssumptionCache *AC = nullptr,
59-
const Instruction *CxtI = nullptr,
60-
const DominatorTree *DT = nullptr,
61-
bool UseInstrInfo = true);
62-
63-
/// Determine which bits of V are known to be either zero or one and return
64-
/// them in the KnownZero/KnownOne bit sets.
65-
///
66-
/// This function is defined on values with integer type, values with pointer
67-
/// type, and vectors of integers. In the case
68-
/// where V is a vector, the known zero and known one values are the
69-
/// same width as the vector element, and the bit is set only if it is true
70-
/// for all of the demanded elements in the vector.
71-
void computeKnownBits(const Value *V, const APInt &DemandedElts,
72-
KnownBits &Known, const DataLayout &DL,
73-
unsigned Depth = 0, AssumptionCache *AC = nullptr,
74-
const Instruction *CxtI = nullptr,
75-
const DominatorTree *DT = nullptr,
76-
bool UseInstrInfo = true);
77-
78-
/// Returns the known bits rather than passing by reference.
7956
KnownBits computeKnownBits(const Value *V, const DataLayout &DL,
8057
unsigned Depth = 0, AssumptionCache *AC = nullptr,
8158
const Instruction *CxtI = nullptr,
8259
const DominatorTree *DT = nullptr,
8360
bool UseInstrInfo = true);
8461

85-
/// Returns the known bits rather than passing by reference.
62+
/// Determine which bits of V are known to be either zero or one.
63+
///
64+
/// This function is defined on values with integer type, values with pointer
65+
/// type, and vectors of integers. In the case
66+
/// where V is a vector, the known zero and known one values are the
67+
/// same width as the vector element, and the bit is set only if it is true
68+
/// for all of the demanded elements in the vector.
8669
KnownBits computeKnownBits(const Value *V, const APInt &DemandedElts,
8770
const DataLayout &DL, unsigned Depth = 0,
8871
AssumptionCache *AC = nullptr,

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,6 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
466466
/// methods should return the value returned by this function.
467467
virtual Instruction *eraseInstFromFunction(Instruction &I) = 0;
468468

469-
void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth,
470-
const Instruction *CxtI) const {
471-
llvm::computeKnownBits(V, Known, DL, Depth, &AC, CxtI, &DT);
472-
}
473-
474469
KnownBits computeKnownBits(const Value *V, unsigned Depth,
475470
const Instruction *CxtI) const {
476471
return llvm::computeKnownBits(V, DL, Depth, &AC, CxtI, &DT);

llvm/lib/Analysis/DemandedBits.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,10 @@ void DemandedBits::determineLiveOperandBits(
7070
KnownBitsComputed = true;
7171

7272
const DataLayout &DL = UserI->getModule()->getDataLayout();
73-
Known = KnownBits(BitWidth);
74-
computeKnownBits(V1, Known, DL, 0, &AC, UserI, &DT);
73+
Known = computeKnownBits(V1, DL, 0, &AC, UserI, &DT);
7574

76-
if (V2) {
77-
Known2 = KnownBits(BitWidth);
78-
computeKnownBits(V2, Known2, DL, 0, &AC, UserI, &DT);
79-
}
75+
if (V2)
76+
Known2 = computeKnownBits(V2, DL, 0, &AC, UserI, &DT);
8077
};
8178

8279
switch (UserI->getOpcode()) {

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7722,9 +7722,8 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
77227722
unsigned LZ = A.countl_zero();
77237723
unsigned TZ = A.countr_zero();
77247724
unsigned BitWidth = A.getBitWidth();
7725-
KnownBits Known(BitWidth);
7726-
computeKnownBits(BO->LHS, Known, getDataLayout(),
7727-
0, &AC, nullptr, &DT);
7725+
KnownBits Known =
7726+
computeKnownBits(BO->LHS, getDataLayout(), 0, &AC, nullptr, &DT);
77287727

77297728
APInt EffectiveMask =
77307729
APInt::getLowBitsSet(BitWidth, BitWidth - LZ - TZ).shl(TZ);

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,6 @@ static void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth,
159159
computeKnownBits(V, DemandedElts, Known, Depth, Q);
160160
}
161161

162-
void llvm::computeKnownBits(const Value *V, KnownBits &Known,
163-
const DataLayout &DL, unsigned Depth,
164-
AssumptionCache *AC, const Instruction *CxtI,
165-
const DominatorTree *DT, bool UseInstrInfo) {
166-
::computeKnownBits(
167-
V, Known, Depth,
168-
SimplifyQuery(DL, DT, AC, safeCxtI(V, CxtI), UseInstrInfo));
169-
}
170-
171-
void llvm::computeKnownBits(const Value *V, const APInt &DemandedElts,
172-
KnownBits &Known, const DataLayout &DL,
173-
unsigned Depth, AssumptionCache *AC,
174-
const Instruction *CxtI, const DominatorTree *DT,
175-
bool UseInstrInfo) {
176-
::computeKnownBits(
177-
V, DemandedElts, Known, Depth,
178-
SimplifyQuery(DL, DT, AC, safeCxtI(V, CxtI), UseInstrInfo));
179-
}
180-
181162
static KnownBits computeKnownBits(const Value *V, const APInt &DemandedElts,
182163
unsigned Depth, const SimplifyQuery &Q);
183164

@@ -250,11 +231,9 @@ bool llvm::haveNoCommonBitsSet(const Value *LHS, const Value *RHS,
250231
match(LHS, m_Not(m_c_Or(m_Specific(A), m_Specific(B)))))
251232
return true;
252233
}
253-
IntegerType *IT = cast<IntegerType>(LHS->getType()->getScalarType());
254-
KnownBits LHSKnown(IT->getBitWidth());
255-
KnownBits RHSKnown(IT->getBitWidth());
256-
::computeKnownBits(LHS, LHSKnown, 0, SQ);
257-
::computeKnownBits(RHS, RHSKnown, 0, SQ);
234+
235+
KnownBits LHSKnown = ::computeKnownBits(LHS, 0, SQ);
236+
KnownBits RHSKnown = ::computeKnownBits(RHS, 0, SQ);
258237
return KnownBits::haveNoCommonBitsSet(LHSKnown, RHSKnown);
259238
}
260239

@@ -8140,9 +8119,8 @@ static bool isTruePredicate(CmpInst::Predicate Pred, const Value *LHS,
81408119
// If X & C == 0 then (X | C) == X +_{nuw} C
81418120
if (match(A, m_Or(m_Value(X), m_APInt(CA))) &&
81428121
match(B, m_Or(m_Specific(X), m_APInt(CB)))) {
8143-
KnownBits Known(CA->getBitWidth());
8144-
computeKnownBits(X, Known, DL, Depth + 1, /*AC*/ nullptr,
8145-
/*CxtI*/ nullptr, /*DT*/ nullptr);
8122+
KnownBits Known = computeKnownBits(X, DL, Depth + 1, /*AC*/ nullptr,
8123+
/*CxtI*/ nullptr, /*DT*/ nullptr);
81468124
if (CA->isSubsetOf(Known.Zero) && CB->isSubsetOf(Known.Zero))
81478125
return true;
81488126
}

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12147,9 +12147,7 @@ MaybeAlign SelectionDAG::InferPtrAlign(SDValue Ptr) const {
1214712147
const GlobalValue *GV = nullptr;
1214812148
int64_t GVOffset = 0;
1214912149
if (TLI->isGAPlusOffset(Ptr.getNode(), GV, GVOffset)) {
12150-
unsigned PtrWidth = getDataLayout().getPointerTypeSizeInBits(GV->getType());
12151-
KnownBits Known(PtrWidth);
12152-
llvm::computeKnownBits(GV, Known, getDataLayout());
12150+
KnownBits Known = llvm::computeKnownBits(GV, getDataLayout());
1215312151
unsigned AlignBits = Known.countMinTrailingZeros();
1215412152
if (AlignBits)
1215512153
return commonAlignment(Align(1ull << std::min(31U, AlignBits)), GVOffset);

llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,8 +1270,7 @@ bool PolynomialMultiplyRecognize::highBitsAreZero(Value *V,
12701270
if (!T)
12711271
return false;
12721272

1273-
KnownBits Known(T->getBitWidth());
1274-
computeKnownBits(V, Known, DL);
1273+
KnownBits Known = computeKnownBits(V, DL);
12751274
return Known.countMinLeadingZeros() >= IterCount;
12761275
}
12771276

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,7 @@ static Instruction *foldCtpop(IntrinsicInst &II, InstCombinerImpl &IC) {
642642
return CastInst::Create(Instruction::ZExt, NarrowPop, Ty);
643643
}
644644

645-
KnownBits Known(BitWidth);
646-
IC.computeKnownBits(Op0, Known, 0, &II);
645+
KnownBits Known = IC.computeKnownBits(Op0, 0, &II);
647646

648647
// If all bits are zero except for exactly one fixed bit, then the result
649648
// must be 0 or 1, and we can get that answer by shifting to LSB:
@@ -2875,8 +2874,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
28752874

28762875
// If there is a dominating assume with the same condition as this one,
28772876
// then this one is redundant, and should be removed.
2878-
KnownBits Known(1);
2879-
computeKnownBits(IIOperand, Known, 0, II);
2877+
KnownBits Known = computeKnownBits(IIOperand, 0, II);
28802878
if (Known.isAllOnes() && isAssumeWithEmptyBundle(cast<AssumeInst>(*II)))
28812879
return eraseInstFromFunction(*II);
28822880

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3749,8 +3749,7 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
37493749
// The motivation for this call into value tracking is to take advantage of
37503750
// the assumption cache, so make sure that is populated.
37513751
if (!CondVal->getType()->isVectorTy() && !AC.assumptions().empty()) {
3752-
KnownBits Known(1);
3753-
computeKnownBits(CondVal, Known, 0, &SI);
3752+
KnownBits Known = computeKnownBits(CondVal, 0, &SI);
37543753
if (Known.One.isOne())
37553754
return replaceInstUsesWith(SI, TrueVal);
37563755
if (Known.Zero.isOne())

llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
119119
"Value *V, DemandedMask and Known must have same BitWidth");
120120

121121
if (isa<Constant>(V)) {
122-
computeKnownBits(V, Known, Depth, CxtI);
122+
Known = computeKnownBits(V, Depth, CxtI);
123123
return nullptr;
124124
}
125125

@@ -132,7 +132,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
132132

133133
Instruction *I = dyn_cast<Instruction>(V);
134134
if (!I) {
135-
computeKnownBits(V, Known, Depth, CxtI);
135+
Known = computeKnownBits(V, Depth, CxtI);
136136
return nullptr; // Only analyze instructions.
137137
}
138138

@@ -184,7 +184,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
184184

185185
switch (I->getOpcode()) {
186186
default:
187-
computeKnownBits(I, Known, Depth, CxtI);
187+
Known = computeKnownBits(I, Depth, CxtI);
188188
break;
189189
case Instruction::And: {
190190
// If either the LHS or the RHS are Zero, the result is zero.
@@ -598,7 +598,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
598598
return InsertNewInstWith(And1, I->getIterator());
599599
}
600600

601-
computeKnownBits(I, Known, Depth, CxtI);
601+
Known = computeKnownBits(I, Depth, CxtI);
602602
break;
603603
}
604604
case Instruction::Shl: {
@@ -660,7 +660,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
660660
return I;
661661
}
662662
}
663-
computeKnownBits(I, Known, Depth, CxtI);
663+
Known = computeKnownBits(I, Depth, CxtI);
664664
}
665665
break;
666666
}
@@ -712,7 +712,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
712712
if (ShiftAmt)
713713
Known.Zero.setHighBits(ShiftAmt); // high bits known zero.
714714
} else {
715-
computeKnownBits(I, Known, Depth, CxtI);
715+
Known = computeKnownBits(I, Depth, CxtI);
716716
}
717717
break;
718718
}
@@ -775,7 +775,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
775775
Known.One |= HighBits;
776776
}
777777
} else {
778-
computeKnownBits(I, Known, Depth, CxtI);
778+
Known = computeKnownBits(I, Depth, CxtI);
779779
}
780780
break;
781781
}
@@ -797,7 +797,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
797797
Known = KnownBits::udiv(LHSKnown, KnownBits::makeConstant(*SA),
798798
cast<BinaryOperator>(I)->isExact());
799799
} else {
800-
computeKnownBits(I, Known, Depth, CxtI);
800+
Known = computeKnownBits(I, Depth, CxtI);
801801
}
802802
break;
803803
}
@@ -837,7 +837,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
837837
}
838838
}
839839

840-
computeKnownBits(I, Known, Depth, CxtI);
840+
Known = computeKnownBits(I, Depth, CxtI);
841841
break;
842842
}
843843
case Instruction::URem: {
@@ -977,7 +977,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
977977
}
978978

979979
if (!KnownBitsComputed)
980-
computeKnownBits(V, Known, Depth, CxtI);
980+
Known = computeKnownBits(V, Depth, CxtI);
981981
break;
982982
}
983983
}
@@ -1007,8 +1007,8 @@ Value *InstCombinerImpl::SimplifyMultipleUseDemandedBits(
10071007
// this instruction has a simpler value in that context.
10081008
switch (I->getOpcode()) {
10091009
case Instruction::And: {
1010-
computeKnownBits(I->getOperand(1), RHSKnown, Depth + 1, CxtI);
1011-
computeKnownBits(I->getOperand(0), LHSKnown, Depth + 1, CxtI);
1010+
RHSKnown = computeKnownBits(I->getOperand(1), Depth + 1, CxtI);
1011+
LHSKnown = computeKnownBits(I->getOperand(0), Depth + 1, CxtI);
10121012
Known = LHSKnown & RHSKnown;
10131013
computeKnownBitsFromAssume(I, Known, Depth, SQ.getWithInstruction(CxtI));
10141014

@@ -1027,8 +1027,8 @@ Value *InstCombinerImpl::SimplifyMultipleUseDemandedBits(
10271027
break;
10281028
}
10291029
case Instruction::Or: {
1030-
computeKnownBits(I->getOperand(1), RHSKnown, Depth + 1, CxtI);
1031-
computeKnownBits(I->getOperand(0), LHSKnown, Depth + 1, CxtI);
1030+
RHSKnown = computeKnownBits(I->getOperand(1), Depth + 1, CxtI);
1031+
LHSKnown = computeKnownBits(I->getOperand(0), Depth + 1, CxtI);
10321032
Known = LHSKnown | RHSKnown;
10331033
computeKnownBitsFromAssume(I, Known, Depth, SQ.getWithInstruction(CxtI));
10341034

@@ -1049,8 +1049,8 @@ Value *InstCombinerImpl::SimplifyMultipleUseDemandedBits(
10491049
break;
10501050
}
10511051
case Instruction::Xor: {
1052-
computeKnownBits(I->getOperand(1), RHSKnown, Depth + 1, CxtI);
1053-
computeKnownBits(I->getOperand(0), LHSKnown, Depth + 1, CxtI);
1052+
RHSKnown = computeKnownBits(I->getOperand(1), Depth + 1, CxtI);
1053+
LHSKnown = computeKnownBits(I->getOperand(0), Depth + 1, CxtI);
10541054
Known = LHSKnown ^ RHSKnown;
10551055
computeKnownBitsFromAssume(I, Known, Depth, SQ.getWithInstruction(CxtI));
10561056

@@ -1075,11 +1075,11 @@ Value *InstCombinerImpl::SimplifyMultipleUseDemandedBits(
10751075

10761076
// If an operand adds zeros to every bit below the highest demanded bit,
10771077
// that operand doesn't change the result. Return the other side.
1078-
computeKnownBits(I->getOperand(1), RHSKnown, Depth + 1, CxtI);
1078+
RHSKnown = computeKnownBits(I->getOperand(1), Depth + 1, CxtI);
10791079
if (DemandedFromOps.isSubsetOf(RHSKnown.Zero))
10801080
return I->getOperand(0);
10811081

1082-
computeKnownBits(I->getOperand(0), LHSKnown, Depth + 1, CxtI);
1082+
LHSKnown = computeKnownBits(I->getOperand(0), Depth + 1, CxtI);
10831083
if (DemandedFromOps.isSubsetOf(LHSKnown.Zero))
10841084
return I->getOperand(1);
10851085

@@ -1094,19 +1094,19 @@ Value *InstCombinerImpl::SimplifyMultipleUseDemandedBits(
10941094

10951095
// If an operand subtracts zeros from every bit below the highest demanded
10961096
// bit, that operand doesn't change the result. Return the other side.
1097-
computeKnownBits(I->getOperand(1), RHSKnown, Depth + 1, CxtI);
1097+
RHSKnown = computeKnownBits(I->getOperand(1), Depth + 1, CxtI);
10981098
if (DemandedFromOps.isSubsetOf(RHSKnown.Zero))
10991099
return I->getOperand(0);
11001100

11011101
bool NSW = cast<OverflowingBinaryOperator>(I)->hasNoSignedWrap();
1102-
computeKnownBits(I->getOperand(0), LHSKnown, Depth + 1, CxtI);
1102+
LHSKnown = computeKnownBits(I->getOperand(0), Depth + 1, CxtI);
11031103
Known = KnownBits::computeForAddSub(/*Add*/ false, NSW, LHSKnown, RHSKnown);
11041104
computeKnownBitsFromAssume(I, Known, Depth, SQ.getWithInstruction(CxtI));
11051105
break;
11061106
}
11071107
case Instruction::AShr: {
11081108
// Compute the Known bits to simplify things downstream.
1109-
computeKnownBits(I, Known, Depth, CxtI);
1109+
Known = computeKnownBits(I, Depth, CxtI);
11101110

11111111
// If this user is only demanding bits that we know, return the known
11121112
// constant.
@@ -1133,7 +1133,7 @@ Value *InstCombinerImpl::SimplifyMultipleUseDemandedBits(
11331133
}
11341134
default:
11351135
// Compute the Known bits to simplify things downstream.
1136-
computeKnownBits(I, Known, Depth, CxtI);
1136+
Known = computeKnownBits(I, Depth, CxtI);
11371137

11381138
// If this user is only demanding bits that we know, return the known
11391139
// constant.

llvm/lib/Transforms/Utils/BypassSlowDivision.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,7 @@ ValueRange FastDivInsertionTask::getValueRange(Value *V,
234234
unsigned HiBits = LongLen - ShortLen;
235235

236236
const DataLayout &DL = SlowDivOrRem->getModule()->getDataLayout();
237-
KnownBits Known(LongLen);
238-
239-
computeKnownBits(V, Known, DL);
237+
KnownBits Known = computeKnownBits(V, DL);
240238

241239
if (Known.countMinLeadingZeros() >= HiBits)
242240
return VALRNG_KNOWN_SHORT;

llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,9 +1262,8 @@ std::optional<APInt> Vectorizer::getConstantOffsetComplexAddrs(
12621262
if (!Safe) {
12631263
// When computing known bits, use the GEPs as context instructions, since
12641264
// they likely are in the same BB as the load/store.
1265-
KnownBits Known(BitWidth);
1266-
computeKnownBits((IdxDiff.sge(0) ? ValA : OpB), Known, DL, 0, &AC,
1267-
ContextInst, &DT);
1265+
KnownBits Known = computeKnownBits((IdxDiff.sge(0) ? ValA : OpB), DL, 0,
1266+
&AC, ContextInst, &DT);
12681267
APInt BitsAllowedToBeSet = Known.Zero.zext(IdxDiff.getBitWidth());
12691268
if (Signed)
12701269
BitsAllowedToBeSet.clearBit(BitWidth - 1);

0 commit comments

Comments
 (0)