Add a testcase for:
authorChris Lattner <sabre@nondot.org>
Sun, 29 Nov 2009 01:15:43 +0000 (01:15 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 29 Nov 2009 01:15:43 +0000 (01:15 +0000)
void test(int N, double* G) {
  long j;
  for (j = 1; j < N - 1; j++)
      G[j] = G[j] + G[j+1] + G[j-1];
}

which we now compile to one load in the loop:

LBB1_2:                                                     ## %bb
movsd 16(%rsi,%rax,8), %xmm2
incq %rdx
addsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movapd %xmm2, %xmm1
movsd %xmm0, 8(%rsi,%rax,8)
incq %rax
cmpq %rcx, %rax
jne LBB1_2

instead of:

LBB1_2:                                                     ## %bb
movsd 8(%rsi,%rax,8), %xmm0
addsd 16(%rsi,%rax,8), %xmm0
addsd (%rsi,%rax,8), %xmm0
movsd %xmm0, 8(%rsi,%rax,8)
incq %rax
cmpq %rcx, %rax
jne LBB1_2

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90048 91177308-0d34-0410-b5e6-96231b3b80d8

test/Transforms/GVN/pre-load.ll

index d904e9532c68e70eb2d7ca61c5ebe07b41ff30a3..2e9c247bc60abadbc5d7ab5e5723946239050662 100644 (file)
@@ -314,3 +314,50 @@ return:
   ret void
 }
 
+;void test10(int N, double* G) {
+;  long j;
+;  for (j = 1; j < N - 1; j++)
+;      G[j] = G[j] + G[j+1] + G[j-1];
+;}
+
+define void @test10(i32 %N, double* nocapture %G) nounwind ssp {
+entry:
+  %0 = add i32 %N, -1
+  %1 = icmp sgt i32 %0, 1
+  br i1 %1, label %bb.nph, label %return
+
+bb.nph:
+  %tmp = sext i32 %0 to i64
+  %tmp8 = add i64 %tmp, -1
+  br label %bb
+; CHECK: bb.nph:
+; CHECK:   load double*
+; CHECK:   load double*
+; CHECK:   br label %bb
+
+
+bb:
+  %indvar = phi i64 [ 0, %bb.nph ], [ %tmp11, %bb ]
+  %scevgep = getelementptr double* %G, i64 %indvar
+  %tmp9 = add i64 %indvar, 2
+  %scevgep10 = getelementptr double* %G, i64 %tmp9
+  %tmp11 = add i64 %indvar, 1
+  %scevgep12 = getelementptr double* %G, i64 %tmp11
+  %2 = load double* %scevgep12, align 8
+  %3 = load double* %scevgep10, align 8
+  %4 = fadd double %2, %3
+  %5 = load double* %scevgep, align 8
+  %6 = fadd double %4, %5
+  store double %6, double* %scevgep12, align 8
+  %exitcond = icmp eq i64 %tmp11, %tmp8
+  br i1 %exitcond, label %return, label %bb
+
+; Should only be one load in the loop.
+; CHECK: bb:
+; CHECK: load double*
+; CHECK-NOT: load double*
+; CHECK: br i1 %exitcond
+
+return:
+  ret void
+}