[PATCH] D106099: [DependenceAnalysis] Guard analysis using getPointerBase()
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 15 14:57:55 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5d5b08761f94: [DependenceAnalysis] Guard analysis using getPointerBase(). (authored by efriedma).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D106099/new/
https://reviews.llvm.org/D106099
Files:
llvm/lib/Analysis/DependenceAnalysis.cpp
llvm/test/Analysis/DependenceAnalysis/lcssa.ll
Index: llvm/test/Analysis/DependenceAnalysis/lcssa.ll
===================================================================
--- /dev/null
+++ llvm/test/Analysis/DependenceAnalysis/lcssa.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -disable-output "-passes=print<da>" \
+; RUN: "-aa-pipeline=basic-aa,tbaa" 2>&1 | FileCheck %s
+; RUN: opt < %s -analyze -enable-new-pm=0 -basic-aa -tbaa -da | FileCheck %s
+
+; CHECK: Src: %v = load i32, i32* %arrayidx1, align 4 --> Dst: store i32 %add, i32* %a.lcssa, align 4
+; CHECK-NEXT: da analyze - confused!
+
+define void @f(i32 *%a, i32 %n, i64 %n2) {
+entry:
+ br label %while.body
+
+while.body:
+ %n.addr = phi i32 [ %mul, %while.body ], [ %n, %entry ]
+ %inc.phi = phi i32 [ %inc, %while.body ], [ 0, %entry ]
+ %mul = mul i32 %n.addr, 3
+ %div = udiv i32 %mul, 2
+ %inc = add i32 %inc.phi, 1
+ %incdec.ptr = getelementptr inbounds i32, i32* %a, i32 %inc
+ %cmp.not = icmp eq i32 %div, 1
+ br i1 %cmp.not, label %while.end, label %while.body
+
+while.end:
+ %a.lcssa = phi i32* [ %incdec.ptr, %while.body ]
+ br label %for.body
+
+for.body:
+ %indvars.iv = phi i64 [ 1, %while.end ], [ %indvars.iv.next, %for.body ]
+ %arrayidx1 = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
+ %v = load i32, i32* %arrayidx1, align 4
+ %add = add nsw i32 %v, 1
+ store i32 %add, i32* %a.lcssa, align 4
+ %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+ %exitcond.not = icmp eq i64 %indvars.iv.next, %n2
+ br i1 %exitcond.not, label %ret, label %for.body
+
+ret:
+ ret void
+}
Index: llvm/lib/Analysis/DependenceAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/DependenceAnalysis.cpp
+++ llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -3553,6 +3553,16 @@
const SCEV *DstSCEV = SE->getSCEV(DstPtr);
LLVM_DEBUG(dbgs() << " SrcSCEV = " << *SrcSCEV << "\n");
LLVM_DEBUG(dbgs() << " DstSCEV = " << *DstSCEV << "\n");
+ if (SE->getPointerBase(SrcSCEV) != SE->getPointerBase(DstSCEV)) {
+ // If two pointers have different bases, trying to analyze indexes won't
+ // work; we can't compare them to each other. This can happen, for example,
+ // if one is produced by an LCSSA PHI node.
+ //
+ // We check this upfront so we don't crash in cases where getMinusSCEV()
+ // returns a SCEVCouldNotCompute.
+ LLVM_DEBUG(dbgs() << "can't analyze SCEV with different pointer base\n");
+ return std::make_unique<Dependence>(Src, Dst);
+ }
Pair[0].Src = SrcSCEV;
Pair[0].Dst = DstSCEV;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106099.359139.patch
Type: text/x-patch
Size: 2553 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210715/bb7dde8e/attachment.bin>
More information about the llvm-commits
mailing list