[llvm] [DA] Dependence analysis does not handle array accesses of different sizes (PR #116630)
Sebastian Pop via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 18 06:26:27 PST 2024
https://github.com/sebpop created https://github.com/llvm/llvm-project/pull/116630
This fixes bug https://github.com/llvm/llvm-project/issues/16183 where the elements of a same array are accesses as i32 and i64. This is not handled by the array dependence analysis.
>From 4a15a582885e3aed68dccf97ea9449c2f3d8ccec Mon Sep 17 00:00:00 2001
From: Sebastian Pop <spop at nvidia.com>
Date: Thu, 14 Nov 2024 18:17:04 +0000
Subject: [PATCH] [DA] Dependence analysis does not handle array accesses of
different sizes
This fixes bug https://github.com/llvm/llvm-project/issues/16183
where the elements of a same array are accesses as i32 and i64.
This is not handled by the array dependence analysis.
---
llvm/lib/Analysis/DependenceAnalysis.cpp | 8 +++++++-
.../DependenceAnalysis/DifferentAccessSize.ll | 15 +++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/Analysis/DependenceAnalysis/DifferentAccessSize.ll
diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp
index a4a98ea0bae146..c1028effcfc1bc 100644
--- a/llvm/lib/Analysis/DependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -730,8 +730,14 @@ static AliasResult underlyingObjectsAlias(AAResults *AA,
const Value *BObj = getUnderlyingObject(LocB.Ptr);
// If the underlying objects are the same, they must alias
- if (AObj == BObj)
+ if (AObj == BObj) {
+ // The dependence test gets confused if the size of the memory accesses
+ // differ.
+ if (LocA.Size != LocB.Size)
+ return AliasResult::MayAlias;
+
return AliasResult::MustAlias;
+ }
// We may have hit the recursion limit for underlying objects, or have
// underlying objects where we don't know they will alias.
diff --git a/llvm/test/Analysis/DependenceAnalysis/DifferentAccessSize.ll b/llvm/test/Analysis/DependenceAnalysis/DifferentAccessSize.ll
new file mode 100644
index 00000000000000..4d5da005ea437b
--- /dev/null
+++ b/llvm/test/Analysis/DependenceAnalysis/DifferentAccessSize.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -disable-output "-passes=print<da>" -aa-pipeline=basic-aa 2>&1 \
+; RUN: | FileCheck %s
+
+; The dependence test does not handle array accesses of different sizes: i32 and i64.
+; Bug 16183 - https://github.com/llvm/llvm-project/issues/16183
+; CHECK-LABEL: bug16183_alias
+; CHECK: da analyze - confused!
+
+define i64 @bug16183_alias(i32* nocapture %A) {
+entry:
+ %arrayidx = getelementptr inbounds i32, ptr %A, i64 1
+ store i32 2, ptr %arrayidx, align 4
+ %0 = load i64, ptr %A, align 8
+ ret i64 %0
+}
More information about the llvm-commits
mailing list