Skip to content

Commit 2ce17ba

Browse files
authored
[InstCombine][CmpInstAnalysis] Use consistent spelling and function names. NFC. (#171645)
Both `decomposeBitTestICmp` and `decomposeBitTest` have a parameter called `lookThroughTrunc`. This was spelled in full (i.e. `lookThroughTrunc`) in the header. However, in the implementation, it's written as `lookThruTrunc`. I opted to convert all instances of `lookThruTrunc` into `lookThroughTrunc` to reduce surprise while reading the code and for conformity. --- The other change in this PR is the renaming of the wrapper around `decomposeBitTest()`. Even though it was a wrapper around `CmpInstAnalysis.h`'s `decomposeBitTest`, the function was called `decomposeBitTestICmp`. This is quite confusing because such a function _also_ exists in `CmpInstAnalysis.h`, but it is _not_ the one actually being used in `InstCombineAndOrXor.cpp`.
1 parent 39a723e commit 2ce17ba

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

llvm/lib/Analysis/CmpInstAnalysis.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Constant *llvm::getPredForFCmpCode(unsigned Code, Type *OpTy,
7575

7676
std::optional<DecomposedBitTest>
7777
llvm::decomposeBitTestICmp(Value *LHS, Value *RHS, CmpInst::Predicate Pred,
78-
bool LookThruTrunc, bool AllowNonZeroC,
78+
bool LookThroughTrunc, bool AllowNonZeroC,
7979
bool DecomposeAnd) {
8080
using namespace PatternMatch;
8181

@@ -173,7 +173,7 @@ llvm::decomposeBitTestICmp(Value *LHS, Value *RHS, CmpInst::Predicate Pred,
173173
Result.Pred = ICmpInst::getInversePredicate(Result.Pred);
174174

175175
Value *X;
176-
if (LookThruTrunc && match(LHS, m_Trunc(m_Value(X)))) {
176+
if (LookThroughTrunc && match(LHS, m_Trunc(m_Value(X)))) {
177177
Result.X = X;
178178
Result.Mask = Result.Mask.zext(X->getType()->getScalarSizeInBits());
179179
Result.C = Result.C.zext(X->getType()->getScalarSizeInBits());
@@ -185,7 +185,7 @@ llvm::decomposeBitTestICmp(Value *LHS, Value *RHS, CmpInst::Predicate Pred,
185185
}
186186

187187
std::optional<DecomposedBitTest> llvm::decomposeBitTest(Value *Cond,
188-
bool LookThruTrunc,
188+
bool LookThroughTrunc,
189189
bool AllowNonZeroC,
190190
bool DecomposeAnd) {
191191
using namespace PatternMatch;
@@ -194,7 +194,7 @@ std::optional<DecomposedBitTest> llvm::decomposeBitTest(Value *Cond,
194194
if (!ICmp->getOperand(0)->getType()->isIntOrIntVectorTy())
195195
return std::nullopt;
196196
return decomposeBitTestICmp(ICmp->getOperand(0), ICmp->getOperand(1),
197-
ICmp->getPredicate(), LookThruTrunc,
197+
ICmp->getPredicate(), LookThroughTrunc,
198198
AllowNonZeroC, DecomposeAnd);
199199
}
200200
Value *X;

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ static unsigned conjugateICmpMask(unsigned Mask) {
186186
return NewMask;
187187
}
188188

189-
// Adapts the external decomposeBitTestICmp for local use.
190-
static bool decomposeBitTestICmp(Value *Cond, CmpInst::Predicate &Pred,
191-
Value *&X, Value *&Y, Value *&Z) {
189+
// Adapts the external decomposeBitTest for local use.
190+
static bool decomposeBitTest(Value *Cond, CmpInst::Predicate &Pred, Value *&X,
191+
Value *&Y, Value *&Z) {
192192
auto Res = llvm::decomposeBitTest(Cond, /*LookThroughTrunc=*/true,
193193
/*AllowNonZeroC=*/true);
194194
if (!Res)
@@ -220,7 +220,7 @@ getMaskedTypeForICmpPair(Value *&A, Value *&B, Value *&C, Value *&D, Value *&E,
220220

221221
// Check whether the icmp can be decomposed into a bit test.
222222
Value *L1, *L11, *L12, *L2, *L21, *L22;
223-
if (decomposeBitTestICmp(LHS, PredL, L11, L12, L2)) {
223+
if (decomposeBitTest(LHS, PredL, L11, L12, L2)) {
224224
L21 = L22 = L1 = nullptr;
225225
} else {
226226
auto *LHSCMP = dyn_cast<ICmpInst>(LHS);
@@ -253,7 +253,7 @@ getMaskedTypeForICmpPair(Value *&A, Value *&B, Value *&C, Value *&D, Value *&E,
253253
return std::nullopt;
254254

255255
Value *R11, *R12, *R2;
256-
if (decomposeBitTestICmp(RHS, PredR, R11, R12, R2)) {
256+
if (decomposeBitTest(RHS, PredR, R11, R12, R2)) {
257257
if (R11 == L11 || R11 == L12 || R11 == L21 || R11 == L22) {
258258
A = R11;
259259
D = R12;
@@ -3890,7 +3890,7 @@ static std::optional<DecomposedBitMaskMul> matchBitmaskMul(Value *V) {
38903890
// Decompose ((A & N) ? 0 : N * C) into BitMaskMul
38913891
if (match(Op, m_Select(m_Value(Cond), m_APInt(EqZero), m_APInt(NeZero)))) {
38923892
auto ICmpDecompose =
3893-
decomposeBitTest(Cond, /*LookThruTrunc=*/true,
3893+
decomposeBitTest(Cond, /*LookThroughTrunc=*/true,
38943894
/*AllowNonZeroC=*/false, /*DecomposeBitMask=*/true);
38953895
if (!ICmpDecompose.has_value())
38963896
return std::nullopt;

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6290,7 +6290,7 @@ Instruction *InstCombinerImpl::foldICmpWithTrunc(ICmpInst &ICmp) {
62906290

62916291
// This matches patterns corresponding to tests of the signbit as well as:
62926292
// (trunc X) pred C2 --> (X & Mask) == C
6293-
if (auto Res = decomposeBitTestICmp(Op0, Op1, Pred, /*WithTrunc=*/true,
6293+
if (auto Res = decomposeBitTestICmp(Op0, Op1, Pred, /*LookThroughTrunc=*/true,
62946294
/*AllowNonZeroC=*/true)) {
62956295
Value *And = Builder.CreateAnd(Res->X, Res->Mask);
62966296
Constant *C = ConstantInt::get(Res->X->getType(), Res->C);

0 commit comments

Comments
 (0)