[llvm] [DA] Add overflow check before calculating absolute value (PR #201964)
Sjoerd Meijer via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 6 02:53:46 PDT 2026
================
@@ -1190,13 +1190,17 @@ bool DependenceInfo::weakCrossingSIVtest(const SCEVAddRecExpr *Src,
//
// We don't use OverflowSafeSignedAPInt here because it's known that this
// algorithm doesn't overflow.
-static bool findGCD(unsigned Bits, const APInt &AM, const APInt &BM,
- const APInt &Delta, APInt &G, APInt &X, APInt &Y) {
+static std::optional<bool> findGCD(unsigned Bits, const APInt &AM,
+ const APInt &BM, const APInt &Delta,
+ APInt &G, APInt &X, APInt &Y) {
LLVM_DEBUG(dbgs() << "\t AM = " << AM << "\n");
LLVM_DEBUG(dbgs() << "\t BM = " << BM << "\n");
LLVM_DEBUG(dbgs() << "\t Delta = " << Delta << "\n");
APInt A0(Bits, 1, true), A1(Bits, 0, true);
APInt B0(Bits, 0, true), B1(Bits, 1, true);
+ if (AM.isMinSignedValue() || BM.isMinSignedValue())
+ // APInt::abs will overflow.
----------------
sjoerdmeijer wrote:
Nit: for single statement ifs without curly brackets I would prefer the comment to be above the if, something like:
// comment
if (C)
return something;
same for the ifs below.
https://github.com/llvm/llvm-project/pull/201964
More information about the llvm-commits
mailing list