@@ -979,25 +979,22 @@ static void computeKnownBitsFromAssume(const Value *V, KnownBits &Known,
979
979
// / Compute known bits from a shift operator, including those with a
980
980
// / non-constant shift amount. Known is the output of this function. Known2 is a
981
981
// / pre-allocated temporary with the same bit width as Known and on return
982
- // / contains the known bit of the shift value source. KZF and KOF are
983
- // / operator-specific functions that, given the known-zero or known-one bits
984
- // / respectively, and a shift amount, compute the implied known-zero or
985
- // / known-one bits of the shift operator's result respectively for that shift
986
- // / amount. The results from calling KZF and KOF are conservatively combined for
987
- // / all permitted shift amounts.
982
+ // / contains the known bit of the shift value source. KF is an
983
+ // / operator-specific function that, given the known-bits and a shift amount,
984
+ // / compute the implied known-bits of the shift operator's result respectively
985
+ // / for that shift amount. The results from calling KF are conservatively
986
+ // / combined for all permitted shift amounts.
988
987
static void computeKnownBitsFromShiftOperator (
989
988
const Operator *I, const APInt &DemandedElts, KnownBits &Known,
990
989
KnownBits &Known2, unsigned Depth, const Query &Q,
991
- function_ref<APInt(const APInt &, unsigned )> KZF,
992
- function_ref<APInt(const APInt &, unsigned )> KOF) {
990
+ function_ref<KnownBits(const KnownBits &, unsigned )> KF) {
993
991
unsigned BitWidth = Known.getBitWidth ();
994
992
computeKnownBits (I->getOperand (0 ), DemandedElts, Known2, Depth + 1 , Q);
995
993
computeKnownBits (I->getOperand (1 ), DemandedElts, Known, Depth + 1 , Q);
996
994
997
995
if (Known.isConstant ()) {
998
996
unsigned ShiftAmt = Known.getConstant ().getLimitedValue (BitWidth - 1 );
999
- Known.Zero = KZF (Known2.Zero , ShiftAmt);
1000
- Known.One = KOF (Known2.One , ShiftAmt);
997
+ Known = KF (Known2, ShiftAmt);
1001
998
1002
999
// If the known bits conflict, this must be an overflowing left shift, so
1003
1000
// the shift result is poison. We can return anything we want. Choose 0 for
@@ -1061,8 +1058,7 @@ static void computeKnownBitsFromShiftOperator(
1061
1058
continue ;
1062
1059
}
1063
1060
1064
- Known.Zero &= KZF (Known2.Zero , ShiftAmt);
1065
- Known.One &= KOF (Known2.One , ShiftAmt);
1061
+ Known = KnownBits::commonBits (Known, KF (Known2, ShiftAmt));
1066
1062
}
1067
1063
1068
1064
// If the known bits conflict, the result is poison. Return a 0 and hope the
@@ -1227,56 +1223,50 @@ static void computeKnownBitsFromOperator(const Operator *I,
1227
1223
case Instruction::Shl: {
1228
1224
// (shl X, C1) & C2 == 0 iff (X & C2 >>u C1) == 0
1229
1225
bool NSW = Q.IIQ .hasNoSignedWrap (cast<OverflowingBinaryOperator>(I));
1230
- auto KZF = [NSW](const APInt &KnownZero, unsigned ShiftAmt) {
1231
- APInt KZResult = KnownZero << ShiftAmt;
1232
- KZResult.setLowBits (ShiftAmt); // Low bits known 0.
1226
+ auto KF = [NSW](const KnownBits &KnownShiftVal, unsigned ShiftAmt) {
1227
+ KnownBits Result;
1228
+ Result.Zero = KnownShiftVal.Zero << ShiftAmt;
1229
+ Result.One = KnownShiftVal.One << ShiftAmt;
1230
+ // Low bits known zero.
1231
+ Result.Zero .setLowBits (ShiftAmt);
1233
1232
// If this shift has "nsw" keyword, then the result is either a poison
1234
1233
// value or has the same sign bit as the first operand.
1235
- if (NSW && KnownZero.isSignBitSet ())
1236
- KZResult.setSignBit ();
1237
- return KZResult;
1238
- };
1239
-
1240
- auto KOF = [NSW](const APInt &KnownOne, unsigned ShiftAmt) {
1241
- APInt KOResult = KnownOne << ShiftAmt;
1242
- if (NSW && KnownOne.isSignBitSet ())
1243
- KOResult.setSignBit ();
1244
- return KOResult;
1234
+ if (NSW) {
1235
+ if (KnownShiftVal.Zero .isSignBitSet ())
1236
+ Result.Zero .setSignBit ();
1237
+ if (KnownShiftVal.One .isSignBitSet ())
1238
+ Result.One .setSignBit ();
1239
+ }
1240
+ return Result;
1245
1241
};
1246
-
1247
1242
computeKnownBitsFromShiftOperator (I, DemandedElts, Known, Known2, Depth, Q,
1248
- KZF, KOF );
1243
+ KF );
1249
1244
break ;
1250
1245
}
1251
1246
case Instruction::LShr: {
1252
1247
// (lshr X, C1) & C2 == 0 iff (-1 >> C1) & C2 == 0
1253
- auto KZF = [](const APInt &KnownZero, unsigned ShiftAmt) {
1254
- APInt KZResult = KnownZero.lshr (ShiftAmt);
1248
+ auto KF = [](const KnownBits &KnownShiftVal, unsigned ShiftAmt) {
1249
+ KnownBits Result;
1250
+ Result.Zero = KnownShiftVal.Zero .lshr (ShiftAmt);
1251
+ Result.One = KnownShiftVal.One .lshr (ShiftAmt);
1255
1252
// High bits known zero.
1256
- KZResult.setHighBits (ShiftAmt);
1257
- return KZResult;
1258
- };
1259
-
1260
- auto KOF = [](const APInt &KnownOne, unsigned ShiftAmt) {
1261
- return KnownOne.lshr (ShiftAmt);
1253
+ Result.Zero .setHighBits (ShiftAmt);
1254
+ return Result;
1262
1255
};
1263
-
1264
1256
computeKnownBitsFromShiftOperator (I, DemandedElts, Known, Known2, Depth, Q,
1265
- KZF, KOF );
1257
+ KF );
1266
1258
break ;
1267
1259
}
1268
1260
case Instruction::AShr: {
1269
1261
// (ashr X, C1) & C2 == 0 iff (-1 >> C1) & C2 == 0
1270
- auto KZF = [](const APInt &KnownZero, unsigned ShiftAmt) {
1271
- return KnownZero.ashr (ShiftAmt);
1262
+ auto KF = [](const KnownBits &KnownShiftVal, unsigned ShiftAmt) {
1263
+ KnownBits Result;
1264
+ Result.Zero = KnownShiftVal.Zero .ashr (ShiftAmt);
1265
+ Result.One = KnownShiftVal.One .ashr (ShiftAmt);
1266
+ return Result;
1272
1267
};
1273
-
1274
- auto KOF = [](const APInt &KnownOne, unsigned ShiftAmt) {
1275
- return KnownOne.ashr (ShiftAmt);
1276
- };
1277
-
1278
1268
computeKnownBitsFromShiftOperator (I, DemandedElts, Known, Known2, Depth, Q,
1279
- KZF, KOF );
1269
+ KF );
1280
1270
break ;
1281
1271
}
1282
1272
case Instruction::Sub: {
0 commit comments