@@ -314,6 +314,22 @@ struct ExtendedValue {
314
314
return N;
315
315
}
316
316
317
+ KnownBits evaluateWith (KnownBits N) const {
318
+ assert (N.getBitWidth () == V->getType ()->getPrimitiveSizeInBits () &&
319
+ " Incompatible bit width" );
320
+ if (SExtBits) N = N.sext (N.getBitWidth () + SExtBits);
321
+ if (ZExtBits) N = N.zext (N.getBitWidth () + ZExtBits);
322
+ return N;
323
+ }
324
+
325
+ ConstantRange evaluateWith (ConstantRange N) const {
326
+ assert (N.getBitWidth () == V->getType ()->getPrimitiveSizeInBits () &&
327
+ " Incompatible bit width" );
328
+ if (SExtBits) N = N.signExtend (N.getBitWidth () + SExtBits);
329
+ if (ZExtBits) N = N.zeroExtend (N.getBitWidth () + ZExtBits);
330
+ return N;
331
+ }
332
+
317
333
bool canDistributeOver (bool NUW, bool NSW) const {
318
334
// zext(x op<nuw> y) == zext(x) op<nuw> zext(y)
319
335
// sext(x op<nsw> y) == sext(x) op<nsw> sext(y)
@@ -1247,9 +1263,10 @@ AliasResult BasicAAResult::aliasGEP(
1247
1263
bool AllNonNegative = DecompGEP1.Offset .isNonNegative ();
1248
1264
bool AllNonPositive = DecompGEP1.Offset .isNonPositive ();
1249
1265
for (unsigned i = 0 , e = DecompGEP1.VarIndices .size (); i != e; ++i) {
1250
- APInt Scale = DecompGEP1.VarIndices [i].Scale ;
1251
- APInt ScaleForGCD = DecompGEP1.VarIndices [i].Scale ;
1252
- if (!DecompGEP1.VarIndices [i].IsNSW )
1266
+ const VariableGEPIndex &Index = DecompGEP1.VarIndices [i];
1267
+ const APInt &Scale = Index.Scale ;
1268
+ APInt ScaleForGCD = Scale;
1269
+ if (!Index.IsNSW )
1253
1270
ScaleForGCD = APInt::getOneBitSet (Scale.getBitWidth (),
1254
1271
Scale.countTrailingZeros ());
1255
1272
@@ -1259,23 +1276,11 @@ AliasResult BasicAAResult::aliasGEP(
1259
1276
GCD = APIntOps::GreatestCommonDivisor (GCD, ScaleForGCD.abs ());
1260
1277
1261
1278
if (AllNonNegative || AllNonPositive) {
1262
- // If the Value could change between cycles, then any reasoning about
1263
- // the Value this cycle may not hold in the next cycle. We'll just
1264
- // give up if we can't determine conditions that hold for every cycle:
1265
- const Value *V = DecompGEP1.VarIndices [i].Val .V ;
1266
- const Instruction *CxtI = DecompGEP1.VarIndices [i].CxtI ;
1267
-
1268
- KnownBits Known = computeKnownBits (V, DL, 0 , &AC, CxtI, DT);
1279
+ KnownBits Known = Index.Val .evaluateWith (
1280
+ computeKnownBits (Index.Val .V , DL, 0 , &AC, Index.CxtI , DT));
1281
+ // TODO: Account for implicit trunc.
1269
1282
bool SignKnownZero = Known.isNonNegative ();
1270
1283
bool SignKnownOne = Known.isNegative ();
1271
-
1272
- // Zero-extension widens the variable, and so forces the sign
1273
- // bit to zero.
1274
- bool IsZExt =
1275
- DecompGEP1.VarIndices [i].Val .ZExtBits > 0 || isa<ZExtInst>(V);
1276
- SignKnownZero |= IsZExt;
1277
- SignKnownOne &= !IsZExt;
1278
-
1279
1284
AllNonNegative &= (SignKnownZero && Scale.isNonNegative ()) ||
1280
1285
(SignKnownOne && Scale.isNonPositive ());
1281
1286
AllNonPositive &= (SignKnownZero && Scale.isNonPositive ()) ||
@@ -1326,15 +1331,11 @@ AliasResult BasicAAResult::aliasGEP(
1326
1331
// If V != 0 then abs(VarIndex) >= abs(Scale).
1327
1332
MinAbsVarIndex = Var.Scale .abs ();
1328
1333
}
1329
- ConstantRange R = computeConstantRange (Var.Val .V , true , &AC, Var.CxtI );
1330
- if (!R.isFullSet () && !R.isEmptySet ()) {
1331
- if (Var.Val .SExtBits )
1332
- R = R.signExtend (R.getBitWidth () + Var.Val .SExtBits );
1333
- if (Var.Val .ZExtBits )
1334
- R = R.zeroExtend (R.getBitWidth () + Var.Val .ZExtBits );
1334
+ ConstantRange R = Var.Val .evaluateWith (
1335
+ computeConstantRange (Var.Val .V , true , &AC, Var.CxtI ));
1336
+ if (!R.isFullSet () && !R.isEmptySet ())
1335
1337
VarIndexRange = R.sextOrTrunc (Var.Scale .getBitWidth ())
1336
1338
.multiply (ConstantRange (Var.Scale ));
1337
- }
1338
1339
} else if (DecompGEP1.VarIndices .size () == 2 ) {
1339
1340
// VarIndex = Scale*V0 + (-Scale)*V1.
1340
1341
// If V0 != V1 then abs(VarIndex) >= abs(Scale).
0 commit comments