forked from OSchip/llvm-project
[LAA] Correctly return a half-open range in expandBounds
This is a latent bug that's been hanging around for a while. For a loop-invariant pointer, expandBounds would return the range {Ptr, Ptr}, but this was interpreted as a half-open range, not a closed range. So we ended up planting incorrect bounds checks. Even worse, they were tautological, so we ended up incorrectly executing the optimized loop. llvm-svn: 299526
This commit is contained in:
parent
07d7c42c5d
commit
37dd4d7aaa
|
@ -1939,7 +1939,10 @@ expandBounds(const RuntimePointerChecking::CheckingPtrGroup *CG, Loop *TheLoop,
|
|||
Value *NewPtr = (Inst && TheLoop->contains(Inst))
|
||||
? Exp.expandCodeFor(Sc, PtrArithTy, Loc)
|
||||
: Ptr;
|
||||
return {NewPtr, NewPtr};
|
||||
// We must return a half-open range, which means incrementing Sc.
|
||||
const SCEV *ScPlusOne = SE->getAddExpr(Sc, SE->getOne(PtrArithTy));
|
||||
Value *NewPtrPlusOne = Exp.expandCodeFor(ScPlusOne, PtrArithTy, Loc);
|
||||
return {NewPtr, NewPtrPlusOne};
|
||||
} else {
|
||||
Value *Start = nullptr, *End = nullptr;
|
||||
DEBUG(dbgs() << "LAA: Adding RT check for range:\n");
|
||||
|
|
|
@ -8,12 +8,13 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
|||
%Partials.215 = type { [2 x %Dual.213] }
|
||||
|
||||
; Function Attrs: sspreq
|
||||
define void @"julia_axpy!_65480"(%Dual.212*) {
|
||||
define void @"julia_axpy!_65480"(%Dual.212*, %Dual.212* %other) {
|
||||
top:
|
||||
br label %if24
|
||||
|
||||
; CHECK-NOT: %bc = bitcast i64* %v2.sroa.0.0..sroa_cast
|
||||
; CHECK: %bound0
|
||||
; CHECK: %bound0 = icmp ult i8* %[[x:[a-z0-9]+]], %[[y:[a-z0-9]+]]
|
||||
; CHECK-NOT: %bound1 = icmp ult i8* %[[y]], %[[x]]
|
||||
|
||||
if24: ; preds = %if24, %top
|
||||
%"#temp#1.sroa.3.02" = phi i64 [ undef, %top ], [ %2, %if24 ]
|
||||
|
@ -24,7 +25,7 @@ if24: ; preds = %if24, %top
|
|||
%v2.sroa.0.0..sroa_cast = bitcast %Dual.212* %0 to i64*
|
||||
%v2.sroa.0.0.copyload = load i64, i64* %v2.sroa.0.0..sroa_cast, align 1
|
||||
%3 = add i64 %"#temp#1.sroa.0.01", -1
|
||||
%4 = getelementptr inbounds %Dual.212, %Dual.212* undef, i64 %3, i32 1, i32 0, i64 0, i32 1, i32 0, i64 0
|
||||
%4 = getelementptr inbounds %Dual.212, %Dual.212* %other, i64 0, i32 1, i32 0, i64 0, i32 1, i32 0, i64 0
|
||||
%5 = bitcast double* %4 to i64*
|
||||
store i64 undef, i64* %5, align 8
|
||||
%notlhs27 = icmp eq i64 %2, undef
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
; CHECK-NEXT: %add8 = add nsw i32 %[[induction]], %add
|
||||
; CHECK-NEXT: %inc = add nuw i32 %j.113, 1
|
||||
; CHECK-NEXT: %cmp2 = icmp ult i32 %inc, %itr
|
||||
; CHECK-NEXT: br i1 %cmp2, label %for.body3, label %for.inc11.loopexit.loopexit6, !llvm.loop !5
|
||||
; CHECK-NEXT: br i1 %cmp2, label %for.body3, label %for.inc11.loopexit.loopexit7, !llvm.loop !5
|
||||
define i32 @foo(i32* nocapture %var1, i32* nocapture readnone %var2, i32* nocapture %var3, i32 %itr) #0 {
|
||||
entry:
|
||||
%cmp14 = icmp eq i32 %itr, 0
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
; CHECK: Loop: Loop at depth 2 containing: %for.body3.us<header><latch><exiting>
|
||||
; CHECK-NEXT: Loop Versioning found to be beneficial
|
||||
;
|
||||
; CHECK: for.cond1.for.inc17_crit_edge.us.loopexit5: ; preds = %for.body3.us
|
||||
; CHECK: for.cond1.for.inc17_crit_edge.us.loopexit6: ; preds = %for.body3.us
|
||||
; CHECK-NEXT: %add14.us.lcssa = phi float [ %add14.us, %for.body3.us ]
|
||||
; CHECK-NEXT: store float %add14.us.lcssa, float* %arrayidx.us, align 4, !alias.scope !0, !noalias !0
|
||||
; CHECK-NEXT: br label %for.cond1.for.inc17_crit_edge.us
|
||||
|
|
Loading…
Reference in New Issue