aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
diff options
context:
space:
mode:
authorRyotaro Kasuga <kasuga.ryotaro@fujitsu.com>2025-01-29 19:30:54 +0900
committerGitHub <noreply@github.com>2025-01-29 19:30:54 +0900
commit690f251063d64a59c0c8065dce7023f1916af17c (patch)
treec1299b3ffb87412000843c578ebda2f7b753feb6 /llvm/lib/Transforms/Scalar/LoopInterchange.cpp
parent89ca3e72ca03efbbfb5ae9b1c71d81f2d1753521 (diff)
downloadllvm-690f251063d64a59c0c8065dce7023f1916af17c.zip
llvm-690f251063d64a59c0c8065dce7023f1916af17c.tar.gz
llvm-690f251063d64a59c0c8065dce7023f1916af17c.tar.bz2
[LoopInterchange] Handle LE and GE correctly (#124901)
LoopInterchange have converted `DVEntry::LE` and `DVEntry::GE` in direction vectors to '<' and '>' respectively. This handling is incorrect because the information about the '=' it lost. This leads to miscompilation in some cases. To resolve this issue, convert them to '*' instead. Resolve #123920
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopInterchange.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopInterchange.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index 38fc682..ca125d2 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -160,11 +160,16 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
unsigned Levels = D->getLevels();
char Direction;
for (unsigned II = 1; II <= Levels; ++II) {
+ // `DVEntry::LE` is converted to `*`. This is because `LE` means `<`
+ // or `=`, for which we don't have an equivalent representation, so
+ // that the conservative approximation is necessary. The same goes for
+ // `DVEntry::GE`.
+ // TODO: Use of fine-grained expressions allows for more accurate
+ // analysis.
unsigned Dir = D->getDirection(II);
- if (Dir == Dependence::DVEntry::LT || Dir == Dependence::DVEntry::LE)
+ if (Dir == Dependence::DVEntry::LT)
Direction = '<';
- else if (Dir == Dependence::DVEntry::GT ||
- Dir == Dependence::DVEntry::GE)
+ else if (Dir == Dependence::DVEntry::GT)
Direction = '>';
else if (Dir == Dependence::DVEntry::EQ)
Direction = '=';