1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
2 ; RUN: opt < %s -passes=argpromotion -S | FileCheck %s
4 target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
6 %struct.ss = type { i32, i64 }
8 define internal void @f(ptr byval(%struct.ss) align 4 %b) nounwind {
9 ; CHECK-LABEL: define {{[^@]+}}@f
10 ; CHECK-SAME: (i32 [[B_0_VAL:%.*]]) #[[ATTR0:[0-9]+]] {
12 ; CHECK-NEXT: [[TEMP2:%.*]] = add i32 [[B_0_VAL]], 1
13 ; CHECK-NEXT: ret void
16 %temp1 = load i32, ptr %b, align 4
17 %temp2 = add i32 %temp1, 1
18 store i32 %temp2, ptr %b, align 4
22 define internal void @g(ptr byval(%struct.ss) align 32 %b) nounwind {
23 ; CHECK-LABEL: define {{[^@]+}}@g
24 ; CHECK-SAME: (i32 [[B_0_VAL:%.*]]) #[[ATTR0]] {
26 ; CHECK-NEXT: [[TEMP2:%.*]] = add i32 [[B_0_VAL]], 1
27 ; CHECK-NEXT: ret void
30 %temp1 = load i32, ptr %b, align 4
31 %temp2 = add i32 %temp1, 1
32 store i32 %temp2, ptr %b, align 4
36 ; Don't transform if alignment isn't specified; the actual alignment
37 ; is target-specific, and not exposed anywhere.
39 ; (If we ever change byval so a missing alignment isn't legal, we can
40 ; just delete this test.)
41 define internal void @h(ptr byval(%struct.ss) %b) nounwind {
42 ; CHECK-LABEL: define {{[^@]+}}@h
43 ; CHECK-SAME: (ptr byval([[STRUCT_SS:%.*]]) [[B:%.*]]) #[[ATTR0]] {
45 ; CHECK-NEXT: [[TEMP1:%.*]] = load i32, ptr [[B]], align 4
46 ; CHECK-NEXT: [[TEMP2:%.*]] = add i32 [[TEMP1]], 1
47 ; CHECK-NEXT: store i32 [[TEMP2]], ptr [[B]], align 4
48 ; CHECK-NEXT: ret void
51 %temp1 = load i32, ptr %b, align 4
52 %temp2 = add i32 %temp1, 1
53 store i32 %temp2, ptr %b, align 4
57 ; Transform even if an argument is written to and then is loaded from.
58 define internal void @k(ptr byval(%struct.ss) align 4 %b) nounwind {
59 ; CHECK-LABEL: define {{[^@]+}}@k
60 ; CHECK-SAME: (i32 [[B_0_VAL:%.*]]) #[[ATTR0]] {
62 ; CHECK-NEXT: [[TEMP2:%.*]] = add i32 [[B_0_VAL]], 1
63 ; CHECK-NEXT: ret void
66 %temp1 = load i32, ptr %b, align 4
67 %temp2 = add i32 %temp1, 1
68 store i32 %temp2, ptr %b, align 4
69 %temp3 = load i32, ptr %b, align 4
73 ; Transform even if a store instruction is the single user.
74 define internal void @l(ptr byval(%struct.ss) align 4 %b) nounwind {
75 ; CHECK-LABEL: define {{[^@]+}}@l
76 ; CHECK-SAME: (i32 [[B_0_VAL:%.*]]) #[[ATTR0]] {
78 ; CHECK-NEXT: ret void
81 store i32 1, ptr %b, align 4
85 ; Transform all the arguments creating the required number of 'alloca's and
86 ; then optimize them out.
87 define internal void @m(ptr byval(%struct.ss) align 4 %b, ptr byval(%struct.ss) align 4 %c) nounwind {
88 ; CHECK-LABEL: define {{[^@]+}}@m
89 ; CHECK-SAME: (i32 [[B_0_VAL:%.*]], i32 [[C_0_VAL:%.*]], i64 [[C_4_VAL:%.*]]) #[[ATTR0]] {
91 ; CHECK-NEXT: [[TEMP2:%.*]] = add i32 [[B_0_VAL]], 1
92 ; CHECK-NEXT: [[TEMP6:%.*]] = add i64 [[C_4_VAL]], 1
93 ; CHECK-NEXT: ret void
96 %temp1 = load i32, ptr %b, align 4
97 %temp2 = add i32 %temp1, 1
98 store i32 %temp2, ptr %b, align 4
100 store i32 %temp2, ptr %c, align 4
102 %temp4 = getelementptr %struct.ss, ptr %c, i32 0, i32 1
103 %temp5 = load i64, ptr %temp4, align 8
104 %temp6 = add i64 %temp5, 1
105 store i64 %temp6, ptr %temp4, align 8
110 define i32 @main() nounwind {
111 ; CHECK-LABEL: define {{[^@]+}}@main
112 ; CHECK-SAME: () #[[ATTR0]] {
114 ; CHECK-NEXT: [[S:%.*]] = alloca [[STRUCT_SS:%.*]], align 32
115 ; CHECK-NEXT: store i32 1, ptr [[S]], align 8
116 ; CHECK-NEXT: [[TEMP4:%.*]] = getelementptr [[STRUCT_SS]], ptr [[S]], i32 0, i32 1
117 ; CHECK-NEXT: store i64 2, ptr [[TEMP4]], align 4
118 ; CHECK-NEXT: [[S_VAL:%.*]] = load i32, ptr [[S]], align 4
119 ; CHECK-NEXT: call void @f(i32 [[S_VAL]])
120 ; CHECK-NEXT: [[S_VAL1:%.*]] = load i32, ptr [[S]], align 4
121 ; CHECK-NEXT: call void @g(i32 [[S_VAL1]])
122 ; CHECK-NEXT: call void @h(ptr byval([[STRUCT_SS]]) [[S]])
123 ; CHECK-NEXT: [[S_VAL2:%.*]] = load i32, ptr [[S]], align 4
124 ; CHECK-NEXT: call void @k(i32 [[S_VAL2]])
125 ; CHECK-NEXT: [[S_VAL3:%.*]] = load i32, ptr [[S]], align 4
126 ; CHECK-NEXT: call void @l(i32 [[S_VAL3]])
127 ; CHECK-NEXT: [[S_VAL4:%.*]] = load i32, ptr [[S]], align 4
128 ; CHECK-NEXT: [[S_VAL5:%.*]] = load i32, ptr [[S]], align 4
129 ; CHECK-NEXT: [[TMP0:%.*]] = getelementptr i8, ptr [[S]], i64 4
130 ; CHECK-NEXT: [[S_VAL6:%.*]] = load i64, ptr [[TMP0]], align 8
131 ; CHECK-NEXT: call void @m(i32 [[S_VAL4]], i32 [[S_VAL5]], i64 [[S_VAL6]])
132 ; CHECK-NEXT: ret i32 0
135 %S = alloca %struct.ss, align 32
136 store i32 1, ptr %S, align 8
137 %temp4 = getelementptr %struct.ss, ptr %S, i32 0, i32 1
138 store i64 2, ptr %temp4, align 4
139 call void @f(ptr byval(%struct.ss) align 4 %S) nounwind
140 call void @g(ptr byval(%struct.ss) align 32 %S) nounwind
141 call void @h(ptr byval(%struct.ss) %S) nounwind
142 call void @k(ptr byval(%struct.ss) align 4 %S) nounwind
143 call void @l(ptr byval(%struct.ss) align 4 %S) nounwind
144 call void @m(ptr byval(%struct.ss) align 4 %S, ptr byval(%struct.ss) align 4 %S) nounwind