git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235021
91177308-0d34-0410-b5e6-
96231b3b80d8
-declare void @foo(i32 %a)
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(
; v0 = input[0];
%p0 = getelementptr inbounds i32, i32* %input, i64 0
%v0 = load i32, i32* %p0
; CHECK-LABEL: @slsr_gep(
; v0 = input[0];
%p0 = getelementptr inbounds i32, i32* %input, i64 0
%v0 = load i32, i32* %p0
+ call void @foo(i32 %v0)
; v1 = input[s];
%p1 = getelementptr inbounds i32, i32* %input, i64 %s
; CHECK: %p1 = getelementptr inbounds i32, i32* %input, i64 %s
%v1 = load i32, i32* %p1
; v1 = input[s];
%p1 = getelementptr inbounds i32, i32* %input, i64 %s
; CHECK: %p1 = getelementptr inbounds i32, i32* %input, i64 %s
%v1 = load i32, i32* %p1
+ call void @foo(i32 %v1)
; v2 = input[s * 2];
%s2 = shl nsw i64 %s, 1
%p2 = getelementptr inbounds i32, i32* %input, i64 %s2
; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 %s
%v2 = load i32, i32* %p2
; v2 = input[s * 2];
%s2 = shl nsw i64 %s, 1
%p2 = getelementptr inbounds i32, i32* %input, i64 %s2
; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 %s
%v2 = load i32, i32* %p2
+ call void @foo(i32 %v2)
- ; return v0 + v1 + v2;
- %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(
; v0 = input[0];
%p0 = getelementptr inbounds i32, i32* %input, i64 0
%v0 = load i32, i32* %p0
; CHECK-LABEL: @slsr_gep_sext(
; v0 = input[0];
%p0 = getelementptr inbounds i32, i32* %input, i64 0
%v0 = load i32, i32* %p0
+ call void @foo(i32 %v0)
%t = sext i32 %s to i64
%p1 = getelementptr inbounds i32, i32* %input, i64 %t
; CHECK: %p1 = getelementptr inbounds i32, i32* %input, i64 %t
%v1 = load i32, i32* %p1
%t = sext i32 %s to i64
%p1 = getelementptr inbounds i32, i32* %input, i64 %t
; CHECK: %p1 = getelementptr inbounds i32, i32* %input, i64 %t
%v1 = load i32, i32* %p1
+ call void @foo(i32 %v1)
- ; v2 = input[(long)(s * 2)];
%s2 = shl nsw i32 %s, 1
%t2 = sext i32 %s2 to i64
%p2 = getelementptr inbounds i32, i32* %input, i64 %t2
; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 %t
%v2 = load i32, i32* %p2
%s2 = shl nsw i32 %s, 1
%t2 = sext i32 %s2 to i64
%p2 = getelementptr inbounds i32, i32* %input, i64 %t2
; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 %t
%v2 = load i32, i32* %p2
+ call void @foo(i32 %v2)
- ; return v0 + v1 + v2;
- %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(
; v0 = input[s][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
; CHECK-LABEL: @slsr_gep_2d(
; v0 = input[s][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
+ call void @foo(i32 %v0)
; v1 = input[s * 2][t];
%s2 = shl nsw i64 %s, 1
; v1 = input[s * 2][t];
%s2 = shl nsw i64 %s, 1
%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]]
%v1 = load i32, i32* %p1
%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]]
%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
%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]]
%v2 = load i32, i32* %p2
%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
; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 [[BUMP]]
%v2 = load i32, i32* %p2
+ call void @foo(i32 %v2)
- ; return v0 + v1 + v2;
- %1 = add i32 %v0, %v1
- %2 = add i32 %1, %v2
- ret i32 %2
}
%struct.S = type <{ i64, i32 }>
}
%struct.S = type <{ i64, i32 }>
; 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
; @slsr_gep_2d.
; 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
; @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(
; 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
%v0 = load i64, i64* %p0
; CHECK-LABEL: @slsr_gep_uglygep(
; 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
%v0 = load i64, i64* %p0
+ call void @bar(i64 %v0)
; v1 = input[s * 2][t].f1;
%s2 = shl nsw i64 %s, 1
; v1 = input[s * 2][t].f1;
%s2 = shl nsw i64 %s, 1
%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]]
%v1 = load i64, i64* %p1
%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]]
%v1 = load i64, i64* %p1
+ call void @bar(i64 %v1)
; v2 = input[s * 3][t].f1;
%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
; CHECK: getelementptr inbounds i8, i8* %{{[0-9]+}}, i64 [[BUMP]]
%v2 = load i64, i64* %p2
; v2 = input[s * 3][t].f1;
%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
; CHECK: getelementptr inbounds i8, i8* %{{[0-9]+}}, i64 [[BUMP]]
%v2 = load i64, i64* %p2
+ call void @bar(i64 %v2)
- ; return v0 + v1 + v2;
- %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(
; v0 = input[0];
%p0 = getelementptr i32, i32* %input, i64 0
%v0 = load i32, i32* %p0
; CHECK-LABEL: @slsr_out_of_bounds_gep(
; v0 = input[0];
%p0 = getelementptr i32, i32* %input, i64 0
%v0 = load i32, i32* %p0
+ call void @foo(i32 %v0)
; v1 = input[(long)s];
%t = sext i32 %s to i64
%p1 = getelementptr i32, i32* %input, i64 %t
; CHECK: %p1 = getelementptr i32, i32* %input, i64 %t
%v1 = load i32, i32* %p1
; v1 = input[(long)s];
%t = sext i32 %s to i64
%p1 = getelementptr i32, i32* %input, i64 %t
; CHECK: %p1 = getelementptr i32, i32* %input, i64 %t
%v1 = load i32, i32* %p1
+ call void @foo(i32 %v1)
; v2 = input[(long)(s * 2)];
%s2 = shl nsw i32 %s, 1
; v2 = input[(long)(s * 2)];
%s2 = shl nsw i32 %s, 1
%p2 = getelementptr i32, i32* %input, i64 %t2
; CHECK: %p2 = getelementptr i32, i32* %p1, i64 %t
%v2 = load i32, i32* %p2
%p2 = getelementptr i32, i32* %input, i64 %t2
; CHECK: %p2 = getelementptr i32, i32* %p1, i64 %t
%v2 = load i32, i32* %p2
+ call void @foo(i32 %v2)
- ; return v0 + v1 + v2;
- %1 = add i32 %v0, %v1
- %2 = add i32 %1, %v2
- ret i32 %2
+
+declare void @foo(i32)
+declare void @bar(i64)
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 i32 @slsr1(i32 %b, i32 %s) {
+define void @slsr1(i32 %b, i32 %s) {
%mul0 = mul i32 %b, %s
; CHECK: mul i32
; CHECK-NOT: mul i32
%mul0 = mul i32 %b, %s
; CHECK: mul i32
; CHECK-NOT: mul i32
- %v0 = call i32 @foo(i32 %mul0)
+ call void @foo(i32 %mul0)
- ; v1 = foo((b + 1) * s);
%b1 = add i32 %b, 1
%mul1 = mul i32 %b1, %s
%b1 = add i32 %b, 1
%mul1 = mul i32 %b1, %s
- %v1 = call i32 @foo(i32 %mul1)
+ call void @foo(i32 %mul1)
- ; v2 = foo((b + 2) * s);
%b2 = add i32 %b, 2
%mul2 = mul i32 %b2, %s
%b2 = add i32 %b, 2
%mul2 = mul i32 %b2, %s
- %v2 = call i32 @foo(i32 %mul2)
+ call void @foo(i32 %mul2)
- ; return v0 + v1 + v2;
- %1 = add i32 %v0, %v1
- %2 = add i32 %1, %v2
- ret i32 %2
-; v0 = foo(a * b)
-; v1 = foo((a + 1) * b)
-; v2 = foo(a * (b + 1))
-; v3 = foo((a + 1) * (b + 1))
-define i32 @slsr2(i32 %a, i32 %b) {
+; foo(a * b)
+; foo((a + 1) * b)
+; foo(a * (b + 1))
+; foo((a + 1) * (b + 1))
+define void @slsr2(i32 %a, i32 %b) {
; CHECK-LABEL: @slsr2(
%a1 = add i32 %a, 1
%b1 = add i32 %b, 1
; CHECK-LABEL: @slsr2(
%a1 = add i32 %a, 1
%b1 = add i32 %b, 1
%mul2 = mul i32 %a, %b1
%mul3 = mul i32 %a1, %b1
%mul2 = mul i32 %a, %b1
%mul3 = mul i32 %a1, %b1
- %v0 = call i32 @foo(i32 %mul0)
- %v1 = call i32 @foo(i32 %mul1)
- %v2 = call i32 @foo(i32 %mul2)
- %v3 = call i32 @foo(i32 %mul3)
+ call void @foo(i32 %mul0)
+ call void @foo(i32 %mul1)
+ call void @foo(i32 %mul2)
+ call void @foo(i32 %mul3)
- %1 = add i32 %v0, %v1
- %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);
-; v1 = foo((b + 2) * s);
-; v2 = foo((b + 4) * s);
-; return v0 + v1 + v2;
-;
-; ==>
-;
+; foo(b * s);
+; foo((b + 2) * s);
+; foo((b + 4) * s);
+; =>
; bump = s * 2;
; mul1 = mul0 + bump; // GVN ensures mul1 and mul2 use the same bump.
; bump = s * 2;
; mul1 = mul0 + bump; // GVN ensures mul1 and mul2 use the same bump.
-; v2 = foo(mul2);
-; return v0 + v1 + v2;
-define i32 @slsr3(i32 %b, i32 %s) {
+define void @slsr3(i32 %b, i32 %s) {
; CHECK-LABEL: @slsr3(
%mul0 = mul i32 %b, %s
; CHECK: mul i32
; CHECK-LABEL: @slsr3(
%mul0 = mul i32 %b, %s
; CHECK: mul i32
- %v0 = call i32 @foo(i32 %mul0)
+ call void @foo(i32 %mul0)
%b1 = add i32 %b, 2
%mul1 = mul i32 %b1, %s
; CHECK: [[BUMP:%[a-zA-Z0-9]+]] = shl i32 %s, 1
; CHECK: %mul1 = add i32 %mul0, [[BUMP]]
%b1 = add i32 %b, 2
%mul1 = mul i32 %b1, %s
; CHECK: [[BUMP:%[a-zA-Z0-9]+]] = shl i32 %s, 1
; CHECK: %mul1 = add i32 %mul0, [[BUMP]]
- %v1 = call i32 @foo(i32 %mul1)
+ call void @foo(i32 %mul1)
%b2 = add i32 %b, 4
%mul2 = mul i32 %b2, %s
; CHECK: %mul2 = add i32 %mul1, [[BUMP]]
%b2 = add i32 %b, 4
%mul2 = mul i32 %b2, %s
; CHECK: %mul2 = add i32 %mul1, [[BUMP]]
- %v2 = call i32 @foo(i32 %mul2)
+ call void @foo(i32 %mul2)
- %1 = add i32 %v0, %v1
- %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 = foo(a * b);
-; v1 = foo((a + 1) * b);
-; return v0 + v1;
-define i32 @not_dominate(i1 %cond, i32 %a, i32 %b) {
+; foo(a * b);
+; foo((a + 1) * b);
+define void @not_dominate(i1 %cond, i32 %a, i32 %b) {
; CHECK-LABEL: @not_dominate(
entry:
%a1 = add i32 %a, 1
; CHECK-LABEL: @not_dominate(
entry:
%a1 = add i32 %a, 1
then:
%mul0 = mul i32 %a, %b
; CHECK: %mul0 = mul i32 %a, %b
then:
%mul0 = mul i32 %a, %b
; CHECK: %mul0 = mul i32 %a, %b
- %v0 = call i32 @foo(i32 %mul0)
+ call void @foo(i32 %mul0)
- %v0.phi = phi i32 [ 0, %entry ], [ %mul0, %then ]
%mul1 = mul i32 %a1, %b
; CHECK: %mul1 = mul i32 %a1, %b
%mul1 = mul i32 %a1, %b
; CHECK: %mul1 = mul i32 %a1, %b
- %v1 = call i32 @foo(i32 %mul1)
- %sum = add i32 %v0.phi, %v1
- ret i32 %sum
+ call void @foo(i32 %mul1)
+ ret void
+
+declare void @foo(i32)