[llvm] [DA] Remove `DependenceInfo::unifySubscriptType` (PR #181607)
Ryotaro Kasuga via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 15 23:23:34 PST 2026
https://github.com/kasuga-fj created https://github.com/llvm/llvm-project/pull/181607
`DependenceInfo::unifySubscriptType` is a function that takes two subscripts and casts them to the wider type. Using this function can sometimes lead to correctness issues, especially when combined with `DependenceInfo::removeMatchingExtensions`, as in #148435. These two functions are intended to broaden the scope of DA, but they can also introduce correctness issues, mainly due to mishandling of `sext`/`zext` and integer overflows.
To avoid these issues, this patch removes the `unifySubscriptType` function. Currently, it has only one caller, which is part of the validation logic for delinearization. Instead of calling `unifySubscriptType`, this patch adds a type check and bails out if the types do not match. Note that I'm not entirely sure whether there are real cases where the types differ and the check is actually necessary. Also, this patch doesn't include new test cases, as I have not found concrete examples where `unifySubscriptType` itself causes actual issues. That is, this patch may be NFC.
Fix #169807
>From 49b411ed66ce523eb8f6514a409c70e4c69527b6 Mon Sep 17 00:00:00 2001
From: Ryotaro Kasuga <kasuga.ryotaro at fujitsu.com>
Date: Mon, 16 Feb 2026 02:38:43 +0000
Subject: [PATCH] [DA] Remove `DependenceInfo::unifySubscriptType`
---
.../llvm/Analysis/DependenceAnalysis.h | 6 --
llvm/lib/Analysis/DependenceAnalysis.cpp | 57 ++-----------------
2 files changed, 4 insertions(+), 59 deletions(-)
diff --git a/llvm/include/llvm/Analysis/DependenceAnalysis.h b/llvm/include/llvm/Analysis/DependenceAnalysis.h
index 6963914d6a03d..3562f6e70c160 100644
--- a/llvm/include/llvm/Analysis/DependenceAnalysis.h
+++ b/llvm/include/llvm/Analysis/DependenceAnalysis.h
@@ -472,12 +472,6 @@ class DependenceInfo {
/// in LoopNest.
bool isLoopInvariant(const SCEV *Expression, const Loop *LoopNest) const;
- /// Makes sure all subscript pairs share the same integer type by
- /// sign-extending as necessary.
- /// Sign-extending a subscript is safe because getelementptr assumes the
- /// array subscripts are signed.
- void unifySubscriptType(ArrayRef<Subscript *> Pairs);
-
/// removeMatchingExtensions - Examines a subscript pair.
/// If the source and destination are identically sign (or zero)
/// extended, it strips off the extension in an effort to
diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp
index 51d0c32149330..40842fb8af1d5 100644
--- a/llvm/lib/Analysis/DependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -1070,58 +1070,6 @@ void DependenceInfo::collectCommonLoops(const SCEV *Expression,
}
}
-void DependenceInfo::unifySubscriptType(ArrayRef<Subscript *> Pairs) {
-
- unsigned widestWidthSeen = 0;
- Type *widestType;
-
- // Go through each pair and find the widest bit to which we need
- // to extend all of them.
- for (Subscript *Pair : Pairs) {
- const SCEV *Src = Pair->Src;
- const SCEV *Dst = Pair->Dst;
- IntegerType *SrcTy = dyn_cast<IntegerType>(Src->getType());
- IntegerType *DstTy = dyn_cast<IntegerType>(Dst->getType());
- if (SrcTy == nullptr || DstTy == nullptr) {
- assert(SrcTy == DstTy &&
- "This function only unify integer types and "
- "expect Src and Dst share the same type otherwise.");
- continue;
- }
- if (SrcTy->getBitWidth() > widestWidthSeen) {
- widestWidthSeen = SrcTy->getBitWidth();
- widestType = SrcTy;
- }
- if (DstTy->getBitWidth() > widestWidthSeen) {
- widestWidthSeen = DstTy->getBitWidth();
- widestType = DstTy;
- }
- }
-
- assert(widestWidthSeen > 0);
-
- // Now extend each pair to the widest seen.
- for (Subscript *Pair : Pairs) {
- const SCEV *Src = Pair->Src;
- const SCEV *Dst = Pair->Dst;
- IntegerType *SrcTy = dyn_cast<IntegerType>(Src->getType());
- IntegerType *DstTy = dyn_cast<IntegerType>(Dst->getType());
- if (SrcTy == nullptr || DstTy == nullptr) {
- assert(SrcTy == DstTy &&
- "This function only unify integer types and "
- "expect Src and Dst share the same type otherwise.");
- continue;
- }
- if (SrcTy->getBitWidth() < widestWidthSeen)
- // Sign-extend Src to widestType
- Pair->Src = SE->getSignExtendExpr(Src, widestType);
- if (DstTy->getBitWidth() < widestWidthSeen) {
- // Sign-extend Dst to widestType
- Pair->Dst = SE->getSignExtendExpr(Dst, widestType);
- }
- }
-}
-
// removeMatchingExtensions - Examines a subscript pair.
// If the source and destination are identically sign (or zero)
// extended, it strips off the extension in an effect to simplify
@@ -3283,7 +3231,10 @@ bool DependenceInfo::tryDelinearize(Instruction *Src, Instruction *Dst,
for (int I = 0; I < Size; ++I) {
Pair[I].Src = SrcSubscripts[I];
Pair[I].Dst = DstSubscripts[I];
- unifySubscriptType(&Pair[I]);
+
+ // TODO: Is this check necessary?
+ if (Pair[I].Src->getType() != Pair[I].Dst->getType())
+ return false;
if (EnableMonotonicityCheck) {
if (MonChecker.checkMonotonicity(Pair[I].Src, OutermostLoop).isUnknown())
More information about the llvm-commits
mailing list