aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/BasicAliasAnalysis.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-10-27 14:58:34 +0200
committerNikita Popov <nikita.ppv@gmail.com>2021-10-27 20:56:03 +0200
commit665060ea4583fa1773a900d81b71c489aaf3e8e4 (patch)
treedd93f11de660f89f3d68fde203c23a6b385f9500 /llvm/lib/Analysis/BasicAliasAnalysis.cpp
parent3eb9e6536a6a40f116655240b264292efabdc928 (diff)
downloadllvm-665060ea4583fa1773a900d81b71c489aaf3e8e4.zip
llvm-665060ea4583fa1773a900d81b71c489aaf3e8e4.tar.gz
llvm-665060ea4583fa1773a900d81b71c489aaf3e8e4.tar.bz2
[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
Diffstat (limited to 'llvm/lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/BasicAliasAnalysis.cpp19
1 files changed, 2 insertions, 17 deletions
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 8cf947c..ea02110 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -657,23 +657,8 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
// The GEP index scale ("Scale") scales C1*V+C2, yielding (C1*V+C2)*Scale.
// This gives us an aggregate computation of (C1*Scale)*V + C2*Scale.
-
- // It can be the case that, even through C1*V+C2 does not overflow for
- // relevant values of V, (C2*Scale) can overflow. In that case, we cannot
- // decompose the expression in this way.
- //
- // FIXME: C1*Scale and the other operations in the decomposed
- // (C1*Scale)*V+C2*Scale can also overflow. We should check for this
- // possibility.
- bool Overflow;
- APInt ScaledOffset = LE.Offset.sextOrTrunc(MaxPointerSize)
- .smul_ov(Scale, Overflow);
- if (Overflow) {
- LE = LinearExpression(CastedValue(Index, 0, SExtBits, TruncBits));
- } else {
- Decomposed.Offset += ScaledOffset;
- Scale *= LE.Scale.sextOrTrunc(MaxPointerSize);
- }
+ Decomposed.Offset += LE.Offset.sextOrTrunc(MaxPointerSize) * Scale;
+ Scale *= LE.Scale.sextOrTrunc(MaxPointerSize);
// If we already had an occurrence of this index variable, merge this
// scale into it. For example, we want to handle: