Skip to content

Commit 29c09c7

Browse files
committed
[InstCombine] match variable names and code comments; NFC
1 parent b5bfbb4 commit 29c09c7

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,12 +1042,12 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
10421042

10431043
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
10441044
Type *Ty = I.getType();
1045-
const APInt *ShAmtAPInt;
1046-
if (match(Op1, m_APInt(ShAmtAPInt))) {
1047-
unsigned ShAmt = ShAmtAPInt->getZExtValue();
1045+
const APInt *C;
1046+
if (match(Op1, m_APInt(C))) {
1047+
unsigned ShAmtC = C->getZExtValue();
10481048
unsigned BitWidth = Ty->getScalarSizeInBits();
10491049
auto *II = dyn_cast<IntrinsicInst>(Op0);
1050-
if (II && isPowerOf2_32(BitWidth) && Log2_32(BitWidth) == ShAmt &&
1050+
if (II && isPowerOf2_32(BitWidth) && Log2_32(BitWidth) == ShAmtC &&
10511051
(II->getIntrinsicID() == Intrinsic::ctlz ||
10521052
II->getIntrinsicID() == Intrinsic::cttz ||
10531053
II->getIntrinsicID() == Intrinsic::ctpop)) {
@@ -1061,56 +1061,56 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
10611061
}
10621062

10631063
Value *X;
1064-
const APInt *ShOp1;
1065-
if (match(Op0, m_Shl(m_Value(X), m_APInt(ShOp1))) && ShOp1->ult(BitWidth)) {
1066-
if (ShOp1->ult(ShAmt)) {
1067-
unsigned ShlAmt = ShOp1->getZExtValue();
1068-
Constant *ShiftDiff = ConstantInt::get(Ty, ShAmt - ShlAmt);
1064+
const APInt *C1;
1065+
if (match(Op0, m_Shl(m_Value(X), m_APInt(C1))) && C1->ult(BitWidth)) {
1066+
if (C1->ult(ShAmtC)) {
1067+
unsigned ShlAmtC = C1->getZExtValue();
1068+
Constant *ShiftDiff = ConstantInt::get(Ty, ShAmtC - ShlAmtC);
10691069
if (cast<BinaryOperator>(Op0)->hasNoUnsignedWrap()) {
1070-
// (X <<nuw C1) >>u C2 --> X >>u (C2 - C1)
1070+
// (X <<nuw C1) >>u C --> X >>u (C - C1)
10711071
auto *NewLShr = BinaryOperator::CreateLShr(X, ShiftDiff);
10721072
NewLShr->setIsExact(I.isExact());
10731073
return NewLShr;
10741074
}
1075-
// (X << C1) >>u C2 --> (X >>u (C2 - C1)) & (-1 >> C2)
1075+
// (X << C1) >>u C --> (X >>u (C - C1)) & (-1 >> C)
10761076
Value *NewLShr = Builder.CreateLShr(X, ShiftDiff, "", I.isExact());
1077-
APInt Mask(APInt::getLowBitsSet(BitWidth, BitWidth - ShAmt));
1077+
APInt Mask(APInt::getLowBitsSet(BitWidth, BitWidth - ShAmtC));
10781078
return BinaryOperator::CreateAnd(NewLShr, ConstantInt::get(Ty, Mask));
10791079
}
1080-
if (ShOp1->ugt(ShAmt)) {
1081-
unsigned ShlAmt = ShOp1->getZExtValue();
1082-
Constant *ShiftDiff = ConstantInt::get(Ty, ShlAmt - ShAmt);
1080+
if (C1->ugt(ShAmtC)) {
1081+
unsigned ShlAmtC = C1->getZExtValue();
1082+
Constant *ShiftDiff = ConstantInt::get(Ty, ShlAmtC - ShAmtC);
10831083
if (cast<BinaryOperator>(Op0)->hasNoUnsignedWrap()) {
1084-
// (X <<nuw C1) >>u C2 --> X <<nuw (C1 - C2)
1084+
// (X <<nuw C1) >>u C --> X <<nuw (C1 - C)
10851085
auto *NewShl = BinaryOperator::CreateShl(X, ShiftDiff);
10861086
NewShl->setHasNoUnsignedWrap(true);
10871087
return NewShl;
10881088
}
1089-
// (X << C1) >>u C2 --> X << (C1 - C2) & (-1 >> C2)
1089+
// (X << C1) >>u C --> X << (C1 - C) & (-1 >> C)
10901090
Value *NewShl = Builder.CreateShl(X, ShiftDiff);
1091-
APInt Mask(APInt::getLowBitsSet(BitWidth, BitWidth - ShAmt));
1091+
APInt Mask(APInt::getLowBitsSet(BitWidth, BitWidth - ShAmtC));
10921092
return BinaryOperator::CreateAnd(NewShl, ConstantInt::get(Ty, Mask));
10931093
}
1094-
assert(*ShOp1 == ShAmt);
1094+
assert(*C1 == ShAmtC);
10951095
// (X << C) >>u C --> X & (-1 >>u C)
1096-
APInt Mask(APInt::getLowBitsSet(BitWidth, BitWidth - ShAmt));
1096+
APInt Mask(APInt::getLowBitsSet(BitWidth, BitWidth - ShAmtC));
10971097
return BinaryOperator::CreateAnd(X, ConstantInt::get(Ty, Mask));
10981098
}
10991099

11001100
if (match(Op0, m_OneUse(m_ZExt(m_Value(X)))) &&
11011101
(!Ty->isIntegerTy() || shouldChangeType(Ty, X->getType()))) {
1102-
assert(ShAmt < X->getType()->getScalarSizeInBits() &&
1102+
assert(ShAmtC < X->getType()->getScalarSizeInBits() &&
11031103
"Big shift not simplified to zero?");
11041104
// lshr (zext iM X to iN), C --> zext (lshr X, C) to iN
1105-
Value *NewLShr = Builder.CreateLShr(X, ShAmt);
1105+
Value *NewLShr = Builder.CreateLShr(X, ShAmtC);
11061106
return new ZExtInst(NewLShr, Ty);
11071107
}
11081108

11091109
if (match(Op0, m_SExt(m_Value(X))) &&
11101110
(!Ty->isIntegerTy() || shouldChangeType(Ty, X->getType()))) {
11111111
// Are we moving the sign bit to the low bit and widening with high zeros?
11121112
unsigned SrcTyBitWidth = X->getType()->getScalarSizeInBits();
1113-
if (ShAmt == BitWidth - 1) {
1113+
if (ShAmtC == BitWidth - 1) {
11141114
// lshr (sext i1 X to iN), N-1 --> zext X to iN
11151115
if (SrcTyBitWidth == 1)
11161116
return new ZExtInst(X, Ty);
@@ -1123,16 +1123,16 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
11231123
}
11241124

11251125
// lshr (sext iM X to iN), N-M --> zext (ashr X, min(N-M, M-1)) to iN
1126-
if (ShAmt == BitWidth - SrcTyBitWidth && Op0->hasOneUse()) {
1126+
if (ShAmtC == BitWidth - SrcTyBitWidth && Op0->hasOneUse()) {
11271127
// The new shift amount can't be more than the narrow source type.
1128-
unsigned NewShAmt = std::min(ShAmt, SrcTyBitWidth - 1);
1128+
unsigned NewShAmt = std::min(ShAmtC, SrcTyBitWidth - 1);
11291129
Value *AShr = Builder.CreateAShr(X, NewShAmt);
11301130
return new ZExtInst(AShr, Ty);
11311131
}
11321132
}
11331133

11341134
Value *Y;
1135-
if (ShAmt == BitWidth - 1) {
1135+
if (ShAmtC == BitWidth - 1) {
11361136
// lshr i32 or(X,-X), 31 --> zext (X != 0)
11371137
if (match(Op0, m_OneUse(m_c_Or(m_Neg(m_Value(X)), m_Deferred(X)))))
11381138
return new ZExtInst(Builder.CreateIsNotNull(X), Ty);
@@ -1144,16 +1144,16 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
11441144
// Check if a number is negative and odd:
11451145
// lshr i32 (srem X, 2), 31 --> and (X >> 31), X
11461146
if (match(Op0, m_OneUse(m_SRem(m_Value(X), m_SpecificInt(2))))) {
1147-
Value *Signbit = Builder.CreateLShr(X, ShAmt);
1147+
Value *Signbit = Builder.CreateLShr(X, ShAmtC);
11481148
return BinaryOperator::CreateAnd(Signbit, X);
11491149
}
11501150
}
11511151

1152-
if (match(Op0, m_LShr(m_Value(X), m_APInt(ShOp1)))) {
1153-
unsigned AmtSum = ShAmt + ShOp1->getZExtValue();
1152+
if (match(Op0, m_LShr(m_Value(X), m_APInt(C1)))) {
1153+
unsigned AmtSum = ShAmtC + C1->getZExtValue();
11541154
// Oversized shifts are simplified to zero in InstSimplify.
11551155
if (AmtSum < BitWidth)
1156-
// (X >>u C1) >>u C2 --> X >>u (C1 + C2)
1156+
// (X >>u C1) >>u C --> X >>u (C1 + C)
11571157
return BinaryOperator::CreateLShr(X, ConstantInt::get(Ty, AmtSum));
11581158
}
11591159

@@ -1163,13 +1163,13 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
11631163
// TODO: Generalize to allow more than just half-width shifts?
11641164
const APInt *MulC;
11651165
if (match(Op0, m_NUWMul(m_Value(X), m_APInt(MulC))) &&
1166-
ShAmt * 2 == BitWidth && (*MulC - 1).isPowerOf2() &&
1167-
MulC->logBase2() == ShAmt)
1166+
ShAmtC * 2 == BitWidth && (*MulC - 1).isPowerOf2() &&
1167+
MulC->logBase2() == ShAmtC)
11681168
return BinaryOperator::CreateAnd(X, ConstantInt::get(Ty, *MulC - 2));
11691169

11701170
// If the shifted-out value is known-zero, then this is an exact shift.
11711171
if (!I.isExact() &&
1172-
MaskedValueIsZero(Op0, APInt::getLowBitsSet(BitWidth, ShAmt), 0, &I)) {
1172+
MaskedValueIsZero(Op0, APInt::getLowBitsSet(BitWidth, ShAmtC), 0, &I)) {
11731173
I.setIsExact();
11741174
return &I;
11751175
}

0 commit comments

Comments
 (0)