[llvm] [BasicAA] Handle disjoint or as add in DecomposeGEP. (PR #78209)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 15 12:42:57 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: David Green (davemgreen)

<details>
<summary>Changes</summary>

This removes the MaskedValueIsZero check in decomposing geps in BasicAA, using the isDisjoint flags instead. This relies on the disjoint flags being present. The other alternative is to keep the old MaskedValueIsZero check too.

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


2 Files Affected:

- (modified) llvm/lib/Analysis/BasicAliasAnalysis.cpp (+2-4) 
- (modified) llvm/test/Analysis/BasicAA/gep-alias.ll (+16-1) 


``````````diff
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index a4a0846df7af15..ab1ab106659e7e 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -393,10 +393,8 @@ static LinearExpression GetLinearExpression(
         // further.
         return Val;
       case Instruction::Or:
-        // X|C == X+C if all the bits in C are unset in X.  Otherwise we can't
-        // analyze it.
-        if (!MaskedValueIsZero(BOp->getOperand(0), RHSC->getValue(),
-                               SimplifyQuery(DL, DT, AC, BOp)))
+        // X|C == X+C if it is disjoint.  Otherwise we can't analyze it.
+        if (!cast<PossiblyDisjointInst>(BOp)->isDisjoint())
           return Val;
 
         [[fallthrough]];
diff --git a/llvm/test/Analysis/BasicAA/gep-alias.ll b/llvm/test/Analysis/BasicAA/gep-alias.ll
index 30298625426641..132cc496b8f7d9 100644
--- a/llvm/test/Analysis/BasicAA/gep-alias.ll
+++ b/llvm/test/Analysis/BasicAA/gep-alias.ll
@@ -114,7 +114,7 @@ define i32 @test5_as1_same_size(ptr addrspace(1) %p, i16 %i) {
 define i32 @test6(ptr %p, i64 %i1) {
   %i = shl i64 %i1, 2
   %pi = getelementptr i32, ptr %p, i64 %i
-  %i.next = or i64 %i, 1
+  %i.next = or disjoint i64 %i, 1
   %pi.next = getelementptr i32, ptr %p, i64 %i.next
   %x = load i32, ptr %pi
   store i32 42, ptr %pi.next
@@ -125,6 +125,21 @@ define i32 @test6(ptr %p, i64 %i1) {
 ; CHECK: ret i32 0
 }
 
+; P[i] != p[(i*4)|2048] with disjoint or
+define i32 @test6_higheror(ptr %p, i64 %i1) {
+  %i = shl nuw nsw i64 %i1, 2
+  %pi = getelementptr i32, ptr %p, i64 %i
+  %i.next = or disjoint i64 %i, 2048
+  %pi.next = getelementptr i32, ptr %p, i64 %i.next
+  %x = load i32, ptr %pi
+  store i32 42, ptr %pi.next
+  %y = load i32, ptr %pi
+  %z = sub i32 %x, %y
+  ret i32 %z
+; CHECK-LABEL: @test6_higheror(
+; CHECK: ret i32 0
+}
+
 ; P[1] != P[i*4]
 define i32 @test7(ptr %p, i64 %i) {
   %pi = getelementptr i32, ptr %p, i64 1

``````````

</details>


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


More information about the llvm-commits mailing list