[llvm] r299526 - [LAA] Correctly return a half-open range in expandBounds
James Molloy via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 5 02:24:26 PDT 2017
Author: jamesm
Date: Wed Apr 5 04:24:26 2017
New Revision: 299526
URL: http://llvm.org/viewvc/llvm-project?rev=299526&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp
llvm/trunk/test/Transforms/LoopVersioning/loop-invariant-bound.ll
llvm/trunk/test/Transforms/LoopVersioningLICM/loopversioningLICM1.ll
llvm/trunk/test/Transforms/LoopVersioningLICM/loopversioningLICM2.ll
Modified: llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp?rev=299526&r1=299525&r2=299526&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp Wed Apr 5 04:24:26 2017
@@ -1939,7 +1939,10 @@ expandBounds(const RuntimePointerCheckin
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");
Modified: llvm/trunk/test/Transforms/LoopVersioning/loop-invariant-bound.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopVersioning/loop-invariant-bound.ll?rev=299526&r1=299525&r2=299526&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopVersioning/loop-invariant-bound.ll (original)
+++ llvm/trunk/test/Transforms/LoopVersioning/loop-invariant-bound.ll Wed Apr 5 04:24:26 2017
@@ -8,12 +8,13 @@ target datalayout = "e-m:e-i64:64-f80:12
%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:
%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
Modified: llvm/trunk/test/Transforms/LoopVersioningLICM/loopversioningLICM1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopVersioningLICM/loopversioningLICM1.ll?rev=299526&r1=299525&r2=299526&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopVersioningLICM/loopversioningLICM1.ll (original)
+++ llvm/trunk/test/Transforms/LoopVersioningLICM/loopversioningLICM1.ll Wed Apr 5 04:24:26 2017
@@ -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
Modified: llvm/trunk/test/Transforms/LoopVersioningLICM/loopversioningLICM2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopVersioningLICM/loopversioningLICM2.ll?rev=299526&r1=299525&r2=299526&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopVersioningLICM/loopversioningLICM2.ll (original)
+++ llvm/trunk/test/Transforms/LoopVersioningLICM/loopversioningLICM2.ll Wed Apr 5 04:24:26 2017
@@ -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
More information about the llvm-commits
mailing list