[NFC] [SLSR] clean up some tests

llvm-svn: 235021
This commit is contained in:
Jingyue Wu 2015-04-15 17:14:03 +00:00
parent f3c6aa2c1a
commit b3ec804172
3 changed files with 99 additions and 83 deletions

View File

@ -98,4 +98,4 @@ define void @simple_enough(i32 %b, i32 %s) {
ret void ret void
} }
declare void @foo(i32 %a) declare void @foo(i32)

View File

@ -2,59 +2,91 @@
target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64" target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
define i32 @slsr_gep(i32* %input, i64 %s) { ; foo(input[0]);
; foo(input[s]);
; foo(input[s * 2]);
; =>
; p0 = &input[0];
; foo(*p);
; p1 = p0 + s;
; foo(*p1);
; p2 = p1 + s;
; foo(*p2);
define void @slsr_gep(i32* %input, i64 %s) {
; CHECK-LABEL: @slsr_gep( ; CHECK-LABEL: @slsr_gep(
; v0 = input[0]; ; v0 = input[0];
%p0 = getelementptr inbounds i32, i32* %input, i64 0 %p0 = getelementptr inbounds i32, i32* %input, i64 0
%v0 = load i32, i32* %p0 %v0 = load i32, i32* %p0
call void @foo(i32 %v0)
; v1 = input[s]; ; v1 = input[s];
%p1 = getelementptr inbounds i32, i32* %input, i64 %s %p1 = getelementptr inbounds i32, i32* %input, i64 %s
; CHECK: %p1 = getelementptr inbounds i32, i32* %input, i64 %s ; CHECK: %p1 = getelementptr inbounds i32, i32* %input, i64 %s
%v1 = load i32, i32* %p1 %v1 = load i32, i32* %p1
call void @foo(i32 %v1)
; v2 = input[s * 2]; ; v2 = input[s * 2];
%s2 = shl nsw i64 %s, 1 %s2 = shl nsw i64 %s, 1
%p2 = getelementptr inbounds i32, i32* %input, i64 %s2 %p2 = getelementptr inbounds i32, i32* %input, i64 %s2
; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 %s ; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 %s
%v2 = load i32, i32* %p2 %v2 = load i32, i32* %p2
call void @foo(i32 %v2)
; return v0 + v1 + v2; ret void
%1 = add i32 %v0, %v1
%2 = add i32 %1, %v2
ret i32 %2
} }
define i32 @slsr_gep_sext(i32* %input, i32 %s) { ; foo(input[0]);
; foo(input[(long)s]);
; foo(input[(long)(s * 2)]);
; =>
; p0 = &input[0];
; foo(*p);
; p1 = p0 + (long)s;
; foo(*p1);
; p2 = p1 + (long)s;
; foo(*p2);
define void @slsr_gep_sext(i32* %input, i32 %s) {
; CHECK-LABEL: @slsr_gep_sext( ; CHECK-LABEL: @slsr_gep_sext(
; v0 = input[0]; ; v0 = input[0];
%p0 = getelementptr inbounds i32, i32* %input, i64 0 %p0 = getelementptr inbounds i32, i32* %input, i64 0
%v0 = load i32, i32* %p0 %v0 = load i32, i32* %p0
call void @foo(i32 %v0)
; v1 = input[(long)s]; ; v1 = input[s];
%t = sext i32 %s to i64 %t = sext i32 %s to i64
%p1 = getelementptr inbounds i32, i32* %input, i64 %t %p1 = getelementptr inbounds i32, i32* %input, i64 %t
; CHECK: %p1 = getelementptr inbounds i32, i32* %input, i64 %t ; CHECK: %p1 = getelementptr inbounds i32, i32* %input, i64 %t
%v1 = load i32, i32* %p1 %v1 = load i32, i32* %p1
call void @foo(i32 %v1)
; v2 = input[(long)(s * 2)]; ; v2 = input[s * 2];
%s2 = shl nsw i32 %s, 1 %s2 = shl nsw i32 %s, 1
%t2 = sext i32 %s2 to i64 %t2 = sext i32 %s2 to i64
%p2 = getelementptr inbounds i32, i32* %input, i64 %t2 %p2 = getelementptr inbounds i32, i32* %input, i64 %t2
; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 %t ; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 %t
%v2 = load i32, i32* %p2 %v2 = load i32, i32* %p2
call void @foo(i32 %v2)
; return v0 + v1 + v2; ret void
%1 = add i32 %v0, %v1
%2 = add i32 %1, %v2
ret i32 %2
} }
define i32 @slsr_gep_2d([10 x [5 x i32]]* %input, i64 %s, i64 %t) { ; int input[10][5];
; foo(input[s][t]);
; foo(input[s * 2][t]);
; foo(input[s * 3][t]);
; =>
; p0 = &input[s][t];
; foo(*p0);
; p1 = p0 + 5s;
; foo(*p1);
; p2 = p1 + 5s;
; foo(*p2);
define void @slsr_gep_2d([10 x [5 x i32]]* %input, i64 %s, i64 %t) {
; CHECK-LABEL: @slsr_gep_2d( ; CHECK-LABEL: @slsr_gep_2d(
; v0 = input[s][t]; ; v0 = input[s][t];
%p0 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %input, i64 0, i64 %s, i64 %t %p0 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %input, i64 0, i64 %s, i64 %t
%v0 = load i32, i32* %p0 %v0 = load i32, i32* %p0
call void @foo(i32 %v0)
; v1 = input[s * 2][t]; ; v1 = input[s * 2][t];
%s2 = shl nsw i64 %s, 1 %s2 = shl nsw i64 %s, 1
@ -62,17 +94,16 @@ define i32 @slsr_gep_2d([10 x [5 x i32]]* %input, i64 %s, i64 %t) {
%p1 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %input, i64 0, i64 %s2, i64 %t %p1 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %input, i64 0, i64 %s2, i64 %t
; CHECK: %p1 = getelementptr inbounds i32, i32* %p0, i64 [[BUMP]] ; CHECK: %p1 = getelementptr inbounds i32, i32* %p0, i64 [[BUMP]]
%v1 = load i32, i32* %p1 %v1 = load i32, i32* %p1
call void @foo(i32 %v1)
; v2 = input[s * 3][t]; ; v3 = input[s * 3][t];
%s3 = mul nsw i64 %s, 3 %s3 = mul nsw i64 %s, 3
%p2 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %input, i64 0, i64 %s3, i64 %t %p2 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %input, i64 0, i64 %s3, i64 %t
; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 [[BUMP]] ; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 [[BUMP]]
%v2 = load i32, i32* %p2 %v2 = load i32, i32* %p2
call void @foo(i32 %v2)
; return v0 + v1 + v2; ret void
%1 = add i32 %v0, %v1
%2 = add i32 %1, %v2
ret i32 %2
} }
%struct.S = type <{ i64, i32 }> %struct.S = type <{ i64, i32 }>
@ -83,11 +114,12 @@ define i32 @slsr_gep_2d([10 x [5 x i32]]* %input, i64 %s, i64 %t) {
; which may not be divisible by typeof(input[s][t].f1) = 8. Therefore, we ; which may not be divisible by typeof(input[s][t].f1) = 8. Therefore, we
; rewrite the candidates using byte offset instead of index offset as in ; rewrite the candidates using byte offset instead of index offset as in
; @slsr_gep_2d. ; @slsr_gep_2d.
define i64 @slsr_gep_uglygep([10 x [5 x %struct.S]]* %input, i64 %s, i64 %t) { define void @slsr_gep_uglygep([10 x [5 x %struct.S]]* %input, i64 %s, i64 %t) {
; CHECK-LABEL: @slsr_gep_uglygep( ; CHECK-LABEL: @slsr_gep_uglygep(
; v0 = input[s][t].f1; ; v0 = input[s][t].f1;
%p0 = getelementptr inbounds [10 x [5 x %struct.S]], [10 x [5 x %struct.S]]* %input, i64 0, i64 %s, i64 %t, i32 0 %p0 = getelementptr inbounds [10 x [5 x %struct.S]], [10 x [5 x %struct.S]]* %input, i64 0, i64 %s, i64 %t, i32 0
%v0 = load i64, i64* %p0 %v0 = load i64, i64* %p0
call void @bar(i64 %v0)
; v1 = input[s * 2][t].f1; ; v1 = input[s * 2][t].f1;
%s2 = shl nsw i64 %s, 1 %s2 = shl nsw i64 %s, 1
@ -95,30 +127,31 @@ define i64 @slsr_gep_uglygep([10 x [5 x %struct.S]]* %input, i64 %s, i64 %t) {
%p1 = getelementptr inbounds [10 x [5 x %struct.S]], [10 x [5 x %struct.S]]* %input, i64 0, i64 %s2, i64 %t, i32 0 %p1 = getelementptr inbounds [10 x [5 x %struct.S]], [10 x [5 x %struct.S]]* %input, i64 0, i64 %s2, i64 %t, i32 0
; CHECK: getelementptr inbounds i8, i8* %{{[0-9]+}}, i64 [[BUMP]] ; CHECK: getelementptr inbounds i8, i8* %{{[0-9]+}}, i64 [[BUMP]]
%v1 = load i64, i64* %p1 %v1 = load i64, i64* %p1
call void @bar(i64 %v1)
; v2 = input[s * 3][t].f1; ; v2 = input[s * 3][t].f1;
%s3 = mul nsw i64 %s, 3 %s3 = mul nsw i64 %s, 3
%p2 = getelementptr inbounds [10 x [5 x %struct.S]], [10 x [5 x %struct.S]]* %input, i64 0, i64 %s3, i64 %t, i32 0 %p2 = getelementptr inbounds [10 x [5 x %struct.S]], [10 x [5 x %struct.S]]* %input, i64 0, i64 %s3, i64 %t, i32 0
; CHECK: getelementptr inbounds i8, i8* %{{[0-9]+}}, i64 [[BUMP]] ; CHECK: getelementptr inbounds i8, i8* %{{[0-9]+}}, i64 [[BUMP]]
%v2 = load i64, i64* %p2 %v2 = load i64, i64* %p2
call void @bar(i64 %v2)
; return v0 + v1 + v2; ret void
%1 = add i64 %v0, %v1
%2 = add i64 %1, %v2
ret i64 %2
} }
define i32 @slsr_out_of_bounds_gep(i32* %input, i32 %s) { define void @slsr_out_of_bounds_gep(i32* %input, i32 %s) {
; CHECK-LABEL: @slsr_out_of_bounds_gep( ; CHECK-LABEL: @slsr_out_of_bounds_gep(
; v0 = input[0]; ; v0 = input[0];
%p0 = getelementptr i32, i32* %input, i64 0 %p0 = getelementptr i32, i32* %input, i64 0
%v0 = load i32, i32* %p0 %v0 = load i32, i32* %p0
call void @foo(i32 %v0)
; v1 = input[(long)s]; ; v1 = input[(long)s];
%t = sext i32 %s to i64 %t = sext i32 %s to i64
%p1 = getelementptr i32, i32* %input, i64 %t %p1 = getelementptr i32, i32* %input, i64 %t
; CHECK: %p1 = getelementptr i32, i32* %input, i64 %t ; CHECK: %p1 = getelementptr i32, i32* %input, i64 %t
%v1 = load i32, i32* %p1 %v1 = load i32, i32* %p1
call void @foo(i32 %v1)
; v2 = input[(long)(s * 2)]; ; v2 = input[(long)(s * 2)];
%s2 = shl nsw i32 %s, 1 %s2 = shl nsw i32 %s, 1
@ -126,9 +159,10 @@ define i32 @slsr_out_of_bounds_gep(i32* %input, i32 %s) {
%p2 = getelementptr i32, i32* %input, i64 %t2 %p2 = getelementptr i32, i32* %input, i64 %t2
; CHECK: %p2 = getelementptr i32, i32* %p1, i64 %t ; CHECK: %p2 = getelementptr i32, i32* %p1, i64 %t
%v2 = load i32, i32* %p2 %v2 = load i32, i32* %p2
call void @foo(i32 %v2)
; return v0 + v1 + v2; ret void
%1 = add i32 %v0, %v1
%2 = add i32 %1, %v2
ret i32 %2
} }
declare void @foo(i32)
declare void @bar(i64)

View File

@ -2,37 +2,32 @@
target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64" target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
declare i32 @foo(i32 %a) define void @slsr1(i32 %b, i32 %s) {
define i32 @slsr1(i32 %b, i32 %s) {
; CHECK-LABEL: @slsr1( ; CHECK-LABEL: @slsr1(
; v0 = foo(b * s); ; foo(b * s);
%mul0 = mul i32 %b, %s %mul0 = mul i32 %b, %s
; CHECK: mul i32 ; CHECK: mul i32
; CHECK-NOT: mul i32 ; CHECK-NOT: mul i32
%v0 = call i32 @foo(i32 %mul0) call void @foo(i32 %mul0)
; v1 = foo((b + 1) * s); ; foo((b + 1) * s);
%b1 = add i32 %b, 1 %b1 = add i32 %b, 1
%mul1 = mul i32 %b1, %s %mul1 = mul i32 %b1, %s
%v1 = call i32 @foo(i32 %mul1) call void @foo(i32 %mul1)
; v2 = foo((b + 2) * s); ; foo((b + 2) * s);
%b2 = add i32 %b, 2 %b2 = add i32 %b, 2
%mul2 = mul i32 %b2, %s %mul2 = mul i32 %b2, %s
%v2 = call i32 @foo(i32 %mul2) call void @foo(i32 %mul2)
; return v0 + v1 + v2; ret void
%1 = add i32 %v0, %v1
%2 = add i32 %1, %v2
ret i32 %2
} }
; v0 = foo(a * b) ; foo(a * b)
; v1 = foo((a + 1) * b) ; foo((a + 1) * b)
; v2 = foo(a * (b + 1)) ; foo(a * (b + 1))
; v3 = foo((a + 1) * (b + 1)) ; foo((a + 1) * (b + 1))
define i32 @slsr2(i32 %a, i32 %b) { define void @slsr2(i32 %a, i32 %b) {
; CHECK-LABEL: @slsr2( ; CHECK-LABEL: @slsr2(
%a1 = add i32 %a, 1 %a1 = add i32 %a, 1
%b1 = add i32 %b, 1 %b1 = add i32 %b, 1
@ -43,63 +38,50 @@ define i32 @slsr2(i32 %a, i32 %b) {
%mul2 = mul i32 %a, %b1 %mul2 = mul i32 %a, %b1
%mul3 = mul i32 %a1, %b1 %mul3 = mul i32 %a1, %b1
%v0 = call i32 @foo(i32 %mul0) call void @foo(i32 %mul0)
%v1 = call i32 @foo(i32 %mul1) call void @foo(i32 %mul1)
%v2 = call i32 @foo(i32 %mul2) call void @foo(i32 %mul2)
%v3 = call i32 @foo(i32 %mul3) call void @foo(i32 %mul3)
%1 = add i32 %v0, %v1 ret void
%2 = add i32 %1, %v2
%3 = add i32 %2, %v3
ret i32 %3
} }
; The bump is a multiple of the stride. ; The bump is a multiple of the stride.
; ;
; v0 = foo(b * s); ; foo(b * s);
; v1 = foo((b + 2) * s); ; foo((b + 2) * s);
; v2 = foo((b + 4) * s); ; foo((b + 4) * s);
; return v0 + v1 + v2; ; =>
;
; ==>
;
; mul0 = b * s; ; mul0 = b * s;
; v0 = foo(mul0);
; bump = s * 2; ; bump = s * 2;
; mul1 = mul0 + bump; // GVN ensures mul1 and mul2 use the same bump. ; mul1 = mul0 + bump; // GVN ensures mul1 and mul2 use the same bump.
; v1 = foo(mul1);
; mul2 = mul1 + bump; ; mul2 = mul1 + bump;
; v2 = foo(mul2); define void @slsr3(i32 %b, i32 %s) {
; return v0 + v1 + v2;
define i32 @slsr3(i32 %b, i32 %s) {
; CHECK-LABEL: @slsr3( ; CHECK-LABEL: @slsr3(
%mul0 = mul i32 %b, %s %mul0 = mul i32 %b, %s
; CHECK: mul i32 ; CHECK: mul i32
%v0 = call i32 @foo(i32 %mul0) call void @foo(i32 %mul0)
%b1 = add i32 %b, 2 %b1 = add i32 %b, 2
%mul1 = mul i32 %b1, %s %mul1 = mul i32 %b1, %s
; CHECK: [[BUMP:%[a-zA-Z0-9]+]] = shl i32 %s, 1 ; CHECK: [[BUMP:%[a-zA-Z0-9]+]] = shl i32 %s, 1
; CHECK: %mul1 = add i32 %mul0, [[BUMP]] ; CHECK: %mul1 = add i32 %mul0, [[BUMP]]
%v1 = call i32 @foo(i32 %mul1) call void @foo(i32 %mul1)
%b2 = add i32 %b, 4 %b2 = add i32 %b, 4
%mul2 = mul i32 %b2, %s %mul2 = mul i32 %b2, %s
; CHECK: %mul2 = add i32 %mul1, [[BUMP]] ; CHECK: %mul2 = add i32 %mul1, [[BUMP]]
%v2 = call i32 @foo(i32 %mul2) call void @foo(i32 %mul2)
%1 = add i32 %v0, %v1 ret void
%2 = add i32 %1, %v2
ret i32 %2
} }
; Do not rewrite a candidate if its potential basis does not dominate it. ; Do not rewrite a candidate if its potential basis does not dominate it.
; v0 = 0; ;
; if (cond) ; if (cond)
; v0 = foo(a * b); ; foo(a * b);
; v1 = foo((a + 1) * b); ; foo((a + 1) * b);
; return v0 + v1; define void @not_dominate(i1 %cond, i32 %a, i32 %b) {
define i32 @not_dominate(i1 %cond, i32 %a, i32 %b) {
; CHECK-LABEL: @not_dominate( ; CHECK-LABEL: @not_dominate(
entry: entry:
%a1 = add i32 %a, 1 %a1 = add i32 %a, 1
@ -108,14 +90,14 @@ entry:
then: then:
%mul0 = mul i32 %a, %b %mul0 = mul i32 %a, %b
; CHECK: %mul0 = mul i32 %a, %b ; CHECK: %mul0 = mul i32 %a, %b
%v0 = call i32 @foo(i32 %mul0) call void @foo(i32 %mul0)
br label %merge br label %merge
merge: merge:
%v0.phi = phi i32 [ 0, %entry ], [ %mul0, %then ]
%mul1 = mul i32 %a1, %b %mul1 = mul i32 %a1, %b
; CHECK: %mul1 = mul i32 %a1, %b ; CHECK: %mul1 = mul i32 %a1, %b
%v1 = call i32 @foo(i32 %mul1) call void @foo(i32 %mul1)
%sum = add i32 %v0.phi, %v1 ret void
ret i32 %sum
} }
declare void @foo(i32)