1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 20:23:11 +01:00

[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
This commit is contained in:
Eli Friedman 2021-07-15 13:49:13 -07:00
parent f675df37ba
commit b7cade9437
2 changed files with 48 additions and 0 deletions

View File

@ -3553,6 +3553,16 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
const SCEV *DstSCEV = SE->getSCEV(DstPtr); const SCEV *DstSCEV = SE->getSCEV(DstPtr);
LLVM_DEBUG(dbgs() << " SrcSCEV = " << *SrcSCEV << "\n"); LLVM_DEBUG(dbgs() << " SrcSCEV = " << *SrcSCEV << "\n");
LLVM_DEBUG(dbgs() << " DstSCEV = " << *DstSCEV << "\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].Src = SrcSCEV;
Pair[0].Dst = DstSCEV; Pair[0].Dst = DstSCEV;

View File

@ -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
}