Skip to content

Commit 665060e

Browse files
committed
[BasicAA] Remove misleading overflow check
GEP decomposition currently checks whether the multiplication of the linear expression offset and GEP scale overflows. However, if everything else works correctly, this overflow check is both unnecessary and dangerously misleading. While it will avoid an overflow in Scale * Offset in particular, other parts of the calculation (including those on dynamic values) may still overflow. The code working on the decomposed GEPs is responsible for ensuring that it remains correct in the presence of overflow. D112611 fixes the last issue of that kind that I'm aware of (in fact, the overflow check was originally introduced to work around precisely that issue). Differential Revision: https://reviews.llvm.org/D112618
1 parent 3eb9e65 commit 665060e

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -657,23 +657,8 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
657657

658658
// The GEP index scale ("Scale") scales C1*V+C2, yielding (C1*V+C2)*Scale.
659659
// This gives us an aggregate computation of (C1*Scale)*V + C2*Scale.
660-
661-
// It can be the case that, even through C1*V+C2 does not overflow for
662-
// relevant values of V, (C2*Scale) can overflow. In that case, we cannot
663-
// decompose the expression in this way.
664-
//
665-
// FIXME: C1*Scale and the other operations in the decomposed
666-
// (C1*Scale)*V+C2*Scale can also overflow. We should check for this
667-
// possibility.
668-
bool Overflow;
669-
APInt ScaledOffset = LE.Offset.sextOrTrunc(MaxPointerSize)
670-
.smul_ov(Scale, Overflow);
671-
if (Overflow) {
672-
LE = LinearExpression(CastedValue(Index, 0, SExtBits, TruncBits));
673-
} else {
674-
Decomposed.Offset += ScaledOffset;
675-
Scale *= LE.Scale.sextOrTrunc(MaxPointerSize);
676-
}
660+
Decomposed.Offset += LE.Offset.sextOrTrunc(MaxPointerSize) * Scale;
661+
Scale *= LE.Scale.sextOrTrunc(MaxPointerSize);
677662

678663
// If we already had an occurrence of this index variable, merge this
679664
// scale into it. For example, we want to handle:

0 commit comments

Comments
 (0)