@@ -1042,12 +1042,12 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
1042
1042
1043
1043
Value *Op0 = I.getOperand (0 ), *Op1 = I.getOperand (1 );
1044
1044
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 ();
1048
1048
unsigned BitWidth = Ty->getScalarSizeInBits ();
1049
1049
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 &&
1051
1051
(II->getIntrinsicID () == Intrinsic::ctlz ||
1052
1052
II->getIntrinsicID () == Intrinsic::cttz ||
1053
1053
II->getIntrinsicID () == Intrinsic::ctpop)) {
@@ -1061,56 +1061,56 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
1061
1061
}
1062
1062
1063
1063
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 );
1069
1069
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)
1071
1071
auto *NewLShr = BinaryOperator::CreateLShr (X, ShiftDiff);
1072
1072
NewLShr->setIsExact (I.isExact ());
1073
1073
return NewLShr;
1074
1074
}
1075
- // (X << C1) >>u C2 --> (X >>u (C2 - C1)) & (-1 >> C2 )
1075
+ // (X << C1) >>u C --> (X >>u (C - C1)) & (-1 >> C )
1076
1076
Value *NewLShr = Builder.CreateLShr (X, ShiftDiff, " " , I.isExact ());
1077
- APInt Mask (APInt::getLowBitsSet (BitWidth, BitWidth - ShAmt ));
1077
+ APInt Mask (APInt::getLowBitsSet (BitWidth, BitWidth - ShAmtC ));
1078
1078
return BinaryOperator::CreateAnd (NewLShr, ConstantInt::get (Ty, Mask));
1079
1079
}
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 );
1083
1083
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 )
1085
1085
auto *NewShl = BinaryOperator::CreateShl (X, ShiftDiff);
1086
1086
NewShl->setHasNoUnsignedWrap (true );
1087
1087
return NewShl;
1088
1088
}
1089
- // (X << C1) >>u C2 --> X << (C1 - C2 ) & (-1 >> C2 )
1089
+ // (X << C1) >>u C --> X << (C1 - C ) & (-1 >> C )
1090
1090
Value *NewShl = Builder.CreateShl (X, ShiftDiff);
1091
- APInt Mask (APInt::getLowBitsSet (BitWidth, BitWidth - ShAmt ));
1091
+ APInt Mask (APInt::getLowBitsSet (BitWidth, BitWidth - ShAmtC ));
1092
1092
return BinaryOperator::CreateAnd (NewShl, ConstantInt::get (Ty, Mask));
1093
1093
}
1094
- assert (*ShOp1 == ShAmt );
1094
+ assert (*C1 == ShAmtC );
1095
1095
// (X << C) >>u C --> X & (-1 >>u C)
1096
- APInt Mask (APInt::getLowBitsSet (BitWidth, BitWidth - ShAmt ));
1096
+ APInt Mask (APInt::getLowBitsSet (BitWidth, BitWidth - ShAmtC ));
1097
1097
return BinaryOperator::CreateAnd (X, ConstantInt::get (Ty, Mask));
1098
1098
}
1099
1099
1100
1100
if (match (Op0, m_OneUse (m_ZExt (m_Value (X)))) &&
1101
1101
(!Ty->isIntegerTy () || shouldChangeType (Ty, X->getType ()))) {
1102
- assert (ShAmt < X->getType ()->getScalarSizeInBits () &&
1102
+ assert (ShAmtC < X->getType ()->getScalarSizeInBits () &&
1103
1103
" Big shift not simplified to zero?" );
1104
1104
// 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 );
1106
1106
return new ZExtInst (NewLShr, Ty);
1107
1107
}
1108
1108
1109
1109
if (match (Op0, m_SExt (m_Value (X))) &&
1110
1110
(!Ty->isIntegerTy () || shouldChangeType (Ty, X->getType ()))) {
1111
1111
// Are we moving the sign bit to the low bit and widening with high zeros?
1112
1112
unsigned SrcTyBitWidth = X->getType ()->getScalarSizeInBits ();
1113
- if (ShAmt == BitWidth - 1 ) {
1113
+ if (ShAmtC == BitWidth - 1 ) {
1114
1114
// lshr (sext i1 X to iN), N-1 --> zext X to iN
1115
1115
if (SrcTyBitWidth == 1 )
1116
1116
return new ZExtInst (X, Ty);
@@ -1123,16 +1123,16 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
1123
1123
}
1124
1124
1125
1125
// 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 ()) {
1127
1127
// 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 );
1129
1129
Value *AShr = Builder.CreateAShr (X, NewShAmt);
1130
1130
return new ZExtInst (AShr, Ty);
1131
1131
}
1132
1132
}
1133
1133
1134
1134
Value *Y;
1135
- if (ShAmt == BitWidth - 1 ) {
1135
+ if (ShAmtC == BitWidth - 1 ) {
1136
1136
// lshr i32 or(X,-X), 31 --> zext (X != 0)
1137
1137
if (match (Op0, m_OneUse (m_c_Or (m_Neg (m_Value (X)), m_Deferred (X)))))
1138
1138
return new ZExtInst (Builder.CreateIsNotNull (X), Ty);
@@ -1144,16 +1144,16 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
1144
1144
// Check if a number is negative and odd:
1145
1145
// lshr i32 (srem X, 2), 31 --> and (X >> 31), X
1146
1146
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 );
1148
1148
return BinaryOperator::CreateAnd (Signbit, X);
1149
1149
}
1150
1150
}
1151
1151
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 ();
1154
1154
// Oversized shifts are simplified to zero in InstSimplify.
1155
1155
if (AmtSum < BitWidth)
1156
- // (X >>u C1) >>u C2 --> X >>u (C1 + C2 )
1156
+ // (X >>u C1) >>u C --> X >>u (C1 + C )
1157
1157
return BinaryOperator::CreateLShr (X, ConstantInt::get (Ty, AmtSum));
1158
1158
}
1159
1159
@@ -1163,13 +1163,13 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
1163
1163
// TODO: Generalize to allow more than just half-width shifts?
1164
1164
const APInt *MulC;
1165
1165
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 )
1168
1168
return BinaryOperator::CreateAnd (X, ConstantInt::get (Ty, *MulC - 2 ));
1169
1169
1170
1170
// If the shifted-out value is known-zero, then this is an exact shift.
1171
1171
if (!I.isExact () &&
1172
- MaskedValueIsZero (Op0, APInt::getLowBitsSet (BitWidth, ShAmt ), 0 , &I)) {
1172
+ MaskedValueIsZero (Op0, APInt::getLowBitsSet (BitWidth, ShAmtC ), 0 , &I)) {
1173
1173
I.setIsExact ();
1174
1174
return &I;
1175
1175
}
0 commit comments