[DA] refactor bounds inference in exactSIVtest and exactRDIVtest (NFC) (#185719)

Replaces the `SmallVector`-based approach for computing the min/max of
affine domain bounds with `GetMaxOrMin` lambda returning `std::optional`
for better readability.
Previously, the code allocated a `SmallVector` to collect valid bounds
and relied on `smax(front(), back())` to handle the single-element case,
which may cause misunderstanding.

---------

Signed-off-by: Ruoyu Qiu <cabbaken@outlook.com>
This commit is contained in:
Ruoyu Qiu 2026-03-11 15:43:43 +08:00 committed by GitHub
parent 16e639189c
commit 8a9c6a346c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1703,26 +1703,28 @@ bool DependenceInfo::exactSIVtest(const SCEV *SrcCoeff, const SCEV *DstCoeff,
auto [TL0, TU0] = inferDomainOfAffine(TB, TX, UM);
auto [TL1, TU1] = inferDomainOfAffine(TA, TY, UM);
auto CreateVec = [](const OverflowSafeSignedAPInt &V0,
const OverflowSafeSignedAPInt &V1) {
SmallVector<APInt, 2> Vec;
auto GetMaxOrMin = [](const OverflowSafeSignedAPInt &V0,
const OverflowSafeSignedAPInt &V1,
bool IsMin) -> std::optional<APInt> {
if (V0 && V1)
return IsMin ? APIntOps::smin(*V0, *V1) : APIntOps::smax(*V0, *V1);
if (V0)
Vec.push_back(*V0);
return *V0;
if (V1)
Vec.push_back(*V1);
return Vec;
return *V1;
return std::nullopt;
};
SmallVector<APInt, 2> TLVec = CreateVec(TL0, TL1);
SmallVector<APInt, 2> TUVec = CreateVec(TU0, TU1);
LLVM_DEBUG(dbgs() << "\t TA = " << TA << "\n");
LLVM_DEBUG(dbgs() << "\t TB = " << TB << "\n");
if (TLVec.empty() || TUVec.empty())
std::optional<APInt> OptTL = GetMaxOrMin(TL0, TL1, false);
std::optional<APInt> OptTU = GetMaxOrMin(TU0, TU1, true);
if (!OptTL || !OptTU)
return false;
TL = APIntOps::smax(TLVec.front(), TLVec.back());
TU = APIntOps::smin(TUVec.front(), TUVec.back());
TL = std::move(*OptTL);
TU = std::move(*OptTU);
LLVM_DEBUG(dbgs() << "\t TL = " << TL << "\n");
LLVM_DEBUG(dbgs() << "\t TU = " << TU << "\n");
@ -2088,23 +2090,25 @@ bool DependenceInfo::exactRDIVtest(const SCEV *SrcCoeff, const SCEV *DstCoeff,
LLVM_DEBUG(dbgs() << "\t TA = " << TA << "\n");
LLVM_DEBUG(dbgs() << "\t TB = " << TB << "\n");
auto CreateVec = [](const OverflowSafeSignedAPInt &V0,
const OverflowSafeSignedAPInt &V1) {
SmallVector<APInt, 2> Vec;
auto GetMaxOrMin = [](const OverflowSafeSignedAPInt &V0,
const OverflowSafeSignedAPInt &V1,
bool IsMin) -> std::optional<APInt> {
if (V0 && V1)
return IsMin ? APIntOps::smin(*V0, *V1) : APIntOps::smax(*V0, *V1);
if (V0)
Vec.push_back(*V0);
return *V0;
if (V1)
Vec.push_back(*V1);
return Vec;
return *V1;
return std::nullopt;
};
SmallVector<APInt, 2> TLVec = CreateVec(TL0, TL1);
SmallVector<APInt, 2> TUVec = CreateVec(TU0, TU1);
if (TLVec.empty() || TUVec.empty())
std::optional<APInt> OptTL = GetMaxOrMin(TL0, TL1, false);
std::optional<APInt> OptTU = GetMaxOrMin(TU0, TU1, true);
if (!OptTL || !OptTU)
return false;
TL = APIntOps::smax(TLVec.front(), TLVec.back());
TU = APIntOps::smin(TUVec.front(), TUVec.back());
TL = std::move(*OptTL);
TU = std::move(*OptTU);
LLVM_DEBUG(dbgs() << "\t TL = " << TL << "\n");
LLVM_DEBUG(dbgs() << "\t TU = " << TU << "\n");