[llvm] [DA] Dependence analysis does not handle array accesses of different sizes (PR #116630)

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 18 06:27:05 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Sebastian Pop (sebpop)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/116630.diff


2 Files Affected:

- (modified) llvm/lib/Analysis/DependenceAnalysis.cpp (+7-1) 
- (added) llvm/test/Analysis/DependenceAnalysis/DifferentAccessSize.ll (+15) 


``````````diff
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
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/116630


More information about the llvm-commits mailing list