[llvm] 5d5b087 - [DependenceAnalysis] Guard analysis using getPointerBase().
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 15 14:57:46 PDT 2021
Author: Eli Friedman
Date: 2021-07-15T14:57:32-07:00
New Revision: 5d5b08761f944d5b9822d582378333cc4b36a0a7
URL: https://github.com/llvm/llvm-project/commit/5d5b08761f944d5b9822d582378333cc4b36a0a7
DIFF: https://github.com/llvm/llvm-project/commit/5d5b08761f944d5b9822d582378333cc4b36a0a7.diff
LOG: [DependenceAnalysis] Guard analysis using getPointerBase().
D104806 broke some uses of getMinusSCEV() in DependenceAnalysis:
subtraction with different pointer bases returns a SCEVCouldNotCompute.
Make sure we avoid cases involving such subtractions.
Differential Revision: https://reviews.llvm.org/D106099
Added:
llvm/test/Analysis/DependenceAnalysis/lcssa.ll
Modified:
llvm/lib/Analysis/DependenceAnalysis.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp
index f11cce38406ad..9564cfb2aa454 100644
--- a/llvm/lib/Analysis/DependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -3553,6 +3553,16 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
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
diff erent 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
diff erent pointer base\n");
+ return std::make_unique<Dependence>(Src, Dst);
+ }
Pair[0].Src = SrcSCEV;
Pair[0].Dst = DstSCEV;
diff --git a/llvm/test/Analysis/DependenceAnalysis/lcssa.ll b/llvm/test/Analysis/DependenceAnalysis/lcssa.ll
new file mode 100644
index 0000000000000..a42295cbe30eb
--- /dev/null
+++ b/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
+}
More information about the llvm-commits
mailing list