[llvm] 784937b - [BasicAA] Use smul_ov helper (NFCI)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 7 09:14:57 PST 2020
Author: Nikita Popov
Date: 2020-11-07T18:14:48+01:00
New Revision: 784937b9bbc56ac039ff8d51c47e1ca6743d9297
URL: https://github.com/llvm/llvm-project/commit/784937b9bbc56ac039ff8d51c47e1ca6743d9297
DIFF: https://github.com/llvm/llvm-project/commit/784937b9bbc56ac039ff8d51c47e1ca6743d9297.diff
LOG: [BasicAA] Use smul_ov helper (NFCI)
Instead of performing the multiplication in double the bit width
and using active bits to determine overflow, use the existing
smul_ov() APInt method to detect overflow.
The smul_ov() implementation is not particularly efficient, but
it's still better than doing this a wide, usually 128-bit, type.
Added:
Modified:
llvm/lib/Analysis/BasicAliasAnalysis.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 5de34c57f9a7..8960044e9e31 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -549,9 +549,10 @@ bool BasicAAResult::DecomposeGEPExpression(const Value *V,
// FIXME: C1*Scale and the other operations in the decomposed
// (C1*Scale)*V+C2*Scale can also overflow. We should check for this
// possibility.
- APInt WideScaledOffset = IndexOffset.sextOrTrunc(MaxPointerSize*2) *
- Scale.sext(MaxPointerSize*2);
- if (WideScaledOffset.getMinSignedBits() > MaxPointerSize) {
+ bool Overflow;
+ APInt ScaledOffset = IndexOffset.sextOrTrunc(MaxPointerSize)
+ .smul_ov(Scale, Overflow);
+ if (Overflow) {
Index = OrigIndex;
IndexScale = 1;
IndexOffset = 0;
@@ -560,7 +561,7 @@ bool BasicAAResult::DecomposeGEPExpression(const Value *V,
if (PointerSize > Width)
SExtBits += PointerSize - Width;
} else {
- Decomposed.OtherOffset += IndexOffset.sextOrTrunc(MaxPointerSize) * Scale;
+ Decomposed.OtherOffset += ScaledOffset;
Scale *= IndexScale.sextOrTrunc(MaxPointerSize);
}
More information about the llvm-commits
mailing list