@@ -1285,24 +1285,27 @@ AliasResult BasicAAResult::aliasGEP(
1285
1285
(-DecompGEP1.Offset ).uge (V1Size.getValue ()))
1286
1286
return NoAlias;
1287
1287
1288
- // Try to determine whether the variable part of the GEP is non-zero, in
1289
- // which case we can add/subtract a minimum scale from the offset.
1290
- // TODO: Currently this handles the case of Scale*V0-Scale*V1 where V0!=V1.
1291
- // We could also handle Scale*V0 where V0!=0.
1292
- if (V1Size.hasValue () && V2Size.hasValue () &&
1293
- DecompGEP1.VarIndices .size () == 2 ) {
1294
- const VariableGEPIndex &Var0 = DecompGEP1.VarIndices [0 ];
1295
- const VariableGEPIndex &Var1 = DecompGEP1.VarIndices [1 ];
1296
- // Check that VisitedPhiBBs is empty, to avoid reasoning about inequality
1297
- // of values across loop iterations.
1298
- if (Var0.Scale == -Var1.Scale && Var0.ZExtBits == Var1.ZExtBits &&
1299
- Var0.SExtBits == Var1.SExtBits && VisitedPhiBBs.empty () &&
1300
- isKnownNonEqual (Var0.V , Var1.V , DL)) {
1301
- // If the indexes are not equal, the actual offset will have at least
1302
- // Scale or -Scale added to it.
1303
- APInt Scale = Var0.Scale .abs ();
1304
- APInt OffsetLo = DecompGEP1.Offset - Scale;
1305
- APInt OffsetHi = DecompGEP1.Offset + Scale;
1288
+ if (V1Size.hasValue () && V2Size.hasValue ()) {
1289
+ // Try to determine whether abs(VarIndex) > 0.
1290
+ Optional<APInt> MinAbsVarIndex;
1291
+ // TODO: Could handle single non-zero index as well.
1292
+ if (DecompGEP1.VarIndices .size () == 2 ) {
1293
+ // VarIndex = Scale*V0 + (-Scale)*V1.
1294
+ // If V0 != V1 then abs(VarIndex) >= abs(Scale).
1295
+ // Check that VisitedPhiBBs is empty, to avoid reasoning about
1296
+ // inequality of values across loop iterations.
1297
+ const VariableGEPIndex &Var0 = DecompGEP1.VarIndices [0 ];
1298
+ const VariableGEPIndex &Var1 = DecompGEP1.VarIndices [1 ];
1299
+ if (Var0.Scale == -Var1.Scale && Var0.ZExtBits == Var1.ZExtBits &&
1300
+ Var0.SExtBits == Var1.SExtBits && VisitedPhiBBs.empty () &&
1301
+ isKnownNonEqual (Var0.V , Var1.V , DL))
1302
+ MinAbsVarIndex = Var0.Scale .abs ();
1303
+ }
1304
+
1305
+ if (MinAbsVarIndex) {
1306
+ // The constant offset will have added at least +/-MinAbsVarIndex to it.
1307
+ APInt OffsetLo = DecompGEP1.Offset - *MinAbsVarIndex;
1308
+ APInt OffsetHi = DecompGEP1.Offset + *MinAbsVarIndex;
1306
1309
// Check that an access at OffsetLo or lower, and an access at OffsetHi
1307
1310
// or higher both do not alias.
1308
1311
if (OffsetLo.isNegative () && (-OffsetLo).uge (V1Size.getValue ()) &&
0 commit comments