@@ -1229,6 +1229,10 @@ AliasResult BasicAAResult::aliasGEP(
1229
1229
return AliasResult::NoAlias;
1230
1230
}
1231
1231
1232
+ // We need to know both acess sizes for all the following heuristics.
1233
+ if (!V1Size.hasValue () || !V2Size.hasValue ())
1234
+ return AliasResult::MayAlias;
1235
+
1232
1236
APInt GCD;
1233
1237
ConstantRange OffsetRange = ConstantRange (DecompGEP1.Offset );
1234
1238
for (unsigned i = 0 , e = DecompGEP1.VarIndices .size (); i != e; ++i) {
@@ -1270,58 +1274,53 @@ AliasResult BasicAAResult::aliasGEP(
1270
1274
APInt ModOffset = DecompGEP1.Offset .srem (GCD);
1271
1275
if (ModOffset.isNegative ())
1272
1276
ModOffset += GCD; // We want mod, not rem.
1273
- if (V1Size.hasValue () && V2Size.hasValue () &&
1274
- ModOffset.uge (V2Size.getValue ()) &&
1277
+ if (ModOffset.uge (V2Size.getValue ()) &&
1275
1278
(GCD - ModOffset).uge (V1Size.getValue ()))
1276
1279
return AliasResult::NoAlias;
1277
1280
1278
- if (V1Size.hasValue () && V2Size.hasValue ()) {
1279
- // Compute ranges of potentially accessed bytes for both accesses. If the
1280
- // interseciton is empty, there can be no overlap.
1281
- unsigned BW = OffsetRange.getBitWidth ();
1282
- ConstantRange Range1 = OffsetRange.add (
1283
- ConstantRange (APInt (BW, 0 ), APInt (BW, V1Size.getValue ())));
1284
- ConstantRange Range2 =
1285
- ConstantRange (APInt (BW, 0 ), APInt (BW, V2Size.getValue ()));
1286
- if (Range1.intersectWith (Range2).isEmptySet ())
1287
- return AliasResult::NoAlias;
1288
- }
1281
+ // Compute ranges of potentially accessed bytes for both accesses. If the
1282
+ // interseciton is empty, there can be no overlap.
1283
+ unsigned BW = OffsetRange.getBitWidth ();
1284
+ ConstantRange Range1 = OffsetRange.add (
1285
+ ConstantRange (APInt (BW, 0 ), APInt (BW, V1Size.getValue ())));
1286
+ ConstantRange Range2 =
1287
+ ConstantRange (APInt (BW, 0 ), APInt (BW, V2Size.getValue ()));
1288
+ if (Range1.intersectWith (Range2).isEmptySet ())
1289
+ return AliasResult::NoAlias;
1289
1290
1290
- if (V1Size.hasValue () && V2Size.hasValue ()) {
1291
- // Try to determine the range of values for VarIndex such that
1292
- // VarIndex <= -MinAbsVarIndex || MinAbsVarIndex <= VarIndex.
1293
- Optional<APInt> MinAbsVarIndex;
1294
- if (DecompGEP1.VarIndices .size () == 1 ) {
1295
- // VarIndex = Scale*V.
1296
- const VariableGEPIndex &Var = DecompGEP1.VarIndices [0 ];
1297
- if (Var.Val .TruncBits == 0 &&
1298
- isKnownNonZero (Var.Val .V , DL, 0 , &AC, Var.CxtI , DT)) {
1299
- // If V != 0 then abs(VarIndex) >= abs(Scale).
1300
- MinAbsVarIndex = Var.Scale .abs ();
1301
- }
1302
- } else if (DecompGEP1.VarIndices .size () == 2 ) {
1303
- // VarIndex = Scale*V0 + (-Scale)*V1.
1304
- // If V0 != V1 then abs(VarIndex) >= abs(Scale).
1305
- // Check that VisitedPhiBBs is empty, to avoid reasoning about
1306
- // inequality of values across loop iterations.
1307
- const VariableGEPIndex &Var0 = DecompGEP1.VarIndices [0 ];
1308
- const VariableGEPIndex &Var1 = DecompGEP1.VarIndices [1 ];
1309
- if (Var0.Scale == -Var1.Scale && Var0.Val .TruncBits == 0 &&
1310
- Var0.Val .hasSameCastsAs (Var1.Val ) && VisitedPhiBBs.empty () &&
1311
- isKnownNonEqual (Var0.Val .V , Var1.Val .V , DL, &AC, /* CxtI */ nullptr ,
1312
- DT))
1313
- MinAbsVarIndex = Var0.Scale .abs ();
1291
+ // Try to determine the range of values for VarIndex such that
1292
+ // VarIndex <= -MinAbsVarIndex || MinAbsVarIndex <= VarIndex.
1293
+ Optional<APInt> MinAbsVarIndex;
1294
+ if (DecompGEP1.VarIndices .size () == 1 ) {
1295
+ // VarIndex = Scale*V.
1296
+ const VariableGEPIndex &Var = DecompGEP1.VarIndices [0 ];
1297
+ if (Var.Val .TruncBits == 0 &&
1298
+ isKnownNonZero (Var.Val .V , DL, 0 , &AC, Var.CxtI , DT)) {
1299
+ // If V != 0 then abs(VarIndex) >= abs(Scale).
1300
+ MinAbsVarIndex = Var.Scale .abs ();
1314
1301
}
1302
+ } else if (DecompGEP1.VarIndices .size () == 2 ) {
1303
+ // VarIndex = Scale*V0 + (-Scale)*V1.
1304
+ // If V0 != V1 then abs(VarIndex) >= abs(Scale).
1305
+ // Check that VisitedPhiBBs is empty, to avoid reasoning about
1306
+ // inequality of values across loop iterations.
1307
+ const VariableGEPIndex &Var0 = DecompGEP1.VarIndices [0 ];
1308
+ const VariableGEPIndex &Var1 = DecompGEP1.VarIndices [1 ];
1309
+ if (Var0.Scale == -Var1.Scale && Var0.Val .TruncBits == 0 &&
1310
+ Var0.Val .hasSameCastsAs (Var1.Val ) && VisitedPhiBBs.empty () &&
1311
+ isKnownNonEqual (Var0.Val .V , Var1.Val .V , DL, &AC, /* CxtI */ nullptr ,
1312
+ DT))
1313
+ MinAbsVarIndex = Var0.Scale .abs ();
1314
+ }
1315
1315
1316
- if (MinAbsVarIndex) {
1317
- // The constant offset will have added at least +/-MinAbsVarIndex to it.
1318
- APInt OffsetLo = DecompGEP1.Offset - *MinAbsVarIndex;
1319
- APInt OffsetHi = DecompGEP1.Offset + *MinAbsVarIndex;
1320
- // We know that Offset <= OffsetLo || Offset >= OffsetHi
1321
- if (OffsetLo.isNegative () && (-OffsetLo).uge (V1Size.getValue ()) &&
1322
- OffsetHi.isNonNegative () && OffsetHi.uge (V2Size.getValue ()))
1323
- return AliasResult::NoAlias;
1324
- }
1316
+ if (MinAbsVarIndex) {
1317
+ // The constant offset will have added at least +/-MinAbsVarIndex to it.
1318
+ APInt OffsetLo = DecompGEP1.Offset - *MinAbsVarIndex;
1319
+ APInt OffsetHi = DecompGEP1.Offset + *MinAbsVarIndex;
1320
+ // We know that Offset <= OffsetLo || Offset >= OffsetHi
1321
+ if (OffsetLo.isNegative () && (-OffsetLo).uge (V1Size.getValue ()) &&
1322
+ OffsetHi.isNonNegative () && OffsetHi.uge (V2Size.getValue ()))
1323
+ return AliasResult::NoAlias;
1325
1324
}
1326
1325
1327
1326
if (constantOffsetHeuristic (DecompGEP1, V1Size, V2Size, &AC, DT))
0 commit comments