[PATCH] D133567: [AA] Improve the BasicAA analysis capability

Allen zhong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 9 03:39:10 PDT 2022


Allen created this revision.
Allen added reviewers: nikic, asbirlea, fhahn.
Herald added subscribers: jeroen.dobbelaere, hiraditya.
Herald added a project: All.
Allen requested review of this revision.
Herald added subscribers: llvm-commits, alextsao1999.
Herald added a project: LLVM.

According https://discourse.llvm.org/t/memoryssa-does-the-accessedbetween-support-scalable-vector-pointer/65052,
scalable vector support in BasicAA is currently essentially limited,
and should be improved effectively for a constant offset GEP.


https://reviews.llvm.org/D133567

Files:
  llvm/lib/Analysis/BasicAliasAnalysis.cpp
  llvm/test/Transforms/GVN/vscale.ll


Index: llvm/test/Transforms/GVN/vscale.ll
===================================================================
--- llvm/test/Transforms/GVN/vscale.ll
+++ llvm/test/Transforms/GVN/vscale.ll
@@ -164,7 +164,7 @@
 
 define i32 @store_clobber_load() {
 ; CHECK-LABEL: @store_clobber_load(
-; CHECK-NEXT:    [[ALLOC:%.*]] = alloca <vscale x 4 x i32>
+; CHECK-NEXT:    [[ALLOC:%.*]] = alloca <vscale x 4 x i32>, align 16
 ; CHECK-NEXT:    store <vscale x 4 x i32> undef, <vscale x 4 x i32>* [[ALLOC]], align 16
 ; CHECK-NEXT:    [[PTR:%.*]] = getelementptr <vscale x 4 x i32>, <vscale x 4 x i32>* [[ALLOC]], i32 0, i32 1
 ; CHECK-NEXT:    [[LOAD:%.*]] = load i32, i32* [[PTR]], align 4
@@ -230,7 +230,7 @@
 define <vscale x 4 x i32>* @load_from_alloc_replaced_with_undef() {
 ; CHECK-LABEL: @load_from_alloc_replaced_with_undef(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:    [[A:%.*]] = alloca <vscale x 4 x i32>
+; CHECK-NEXT:    [[A:%.*]] = alloca <vscale x 4 x i32>, align 16
 ; CHECK-NEXT:    br i1 undef, label [[IF_END:%.*]], label [[IF_THEN:%.*]]
 ; CHECK:       if.then:
 ; CHECK-NEXT:    store <vscale x 4 x i32> zeroinitializer, <vscale x 4 x i32>* [[A]], align 16
@@ -281,7 +281,7 @@
   ret i32 %result
 }
 
-; TODO: BasicAA return MayAlias for %gep1,%gep2, could improve as NoAlias.
+; BasicAA return MayAlias for %gep1,%gep2, could improve as NoAlias.
 define void @redundant_load_elimination_2(i1 %c, <vscale x 4 x i32>* %p, i32* %q, <vscale x 4 x i32> %v) {
 ; CHECK-LABEL: @redundant_load_elimination_2(
 ; CHECK-NEXT:  entry:
@@ -291,8 +291,7 @@
 ; CHECK-NEXT:    store i32 1, i32* [[GEP2]], align 4
 ; CHECK-NEXT:    br i1 [[C:%.*]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]
 ; CHECK:       if.then:
-; CHECK-NEXT:    [[T:%.*]] = load i32, i32* [[GEP1]], align 4
-; CHECK-NEXT:    store i32 [[T]], i32* [[Q:%.*]], align 4
+; CHECK-NEXT:    store i32 0, i32* [[Q:%.*]], align 4
 ; CHECK-NEXT:    ret void
 ; CHECK:       if.else:
 ; CHECK-NEXT:    ret void
Index: llvm/lib/Analysis/BasicAliasAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1107,8 +1107,18 @@
   DecomposedGEP DecompGEP2 = DecomposeGEPExpression(V2, DL, &AC, DT);
 
   // Bail if we were not able to decompose anything.
-  if (DecompGEP1.Base == GEP1 && DecompGEP2.Base == V2)
-    return AliasResult::MayAlias;
+  if (DecompGEP1.Base == GEP1 && DecompGEP2.Base == V2) {
+    // Check to see if this V1 is to a constant offset from the V2 ptr.
+    if (!isa<GEPOperator>(V2))
+      return AliasResult::MayAlias;
+
+    auto *EltTy1 = GEP1->getResultElementType();
+    auto *EltTy2 = cast<GEPOperator>(V2)->getResultElementType();
+    Optional<int64_t> Offset = isPointerOffset(GEP1, V2, DL);
+    if ((EltTy1 != EltTy2) || !Offset ||
+        DL.getTypeStoreSize(EltTy1).isScalable())
+      return AliasResult::MayAlias;
+  }
 
   // Subtract the GEP2 pointer from the GEP1 pointer to find out their
   // symbolic difference.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133567.459008.patch
Type: text/x-patch
Size: 3032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220909/c9f0a37b/attachment.bin>


More information about the llvm-commits mailing list