1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2 ; RUN: opt -S -passes=argpromotion < %s | FileCheck %s
3 define internal i32 @foo(ptr %x, i32 %n, i32 %m) {
4 ; CHECK-LABEL: define internal i32 @foo(
5 ; CHECK-SAME: i32 [[X_0_VAL:%.*]], i32 [[N:%.*]], i32 [[M:%.*]]) {
6 ; CHECK-NEXT: [[ENTRY:.*:]]
7 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[N]], 0
8 ; CHECK-NEXT: br i1 [[CMP]], label %[[COND_TRUE:.*]], label %[[COND_FALSE:.*]]
9 ; CHECK: [[COND_TRUE]]:
10 ; CHECK-NEXT: br label %[[RETURN:.*]]
11 ; CHECK: [[COND_FALSE]]:
12 ; CHECK-NEXT: [[SUBVAL:%.*]] = sub i32 [[N]], 1
13 ; CHECK-NEXT: [[CALLRET:%.*]] = call i32 @foo(i32 [[X_0_VAL]], i32 [[SUBVAL]], i32 [[X_0_VAL]])
14 ; CHECK-NEXT: [[SUBVAL2:%.*]] = sub i32 [[N]], 2
15 ; CHECK-NEXT: [[CALLRET2:%.*]] = call i32 @foo(i32 [[X_0_VAL]], i32 [[SUBVAL2]], i32 [[M]])
16 ; CHECK-NEXT: [[CMP2:%.*]] = add i32 [[CALLRET]], [[CALLRET2]]
17 ; CHECK-NEXT: br label %[[RETURN]]
18 ; CHECK: [[COND_NEXT:.*]]:
19 ; CHECK-NEXT: br label %[[RETURN]]
21 ; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i32 [ [[X_0_VAL]], %[[COND_TRUE]] ], [ [[CMP2]], %[[COND_FALSE]] ], [ poison, %[[COND_NEXT]] ]
22 ; CHECK-NEXT: ret i32 [[RETVAL_0]]
25 %cmp = icmp ne i32 %n, 0
26 br i1 %cmp, label %cond_true, label %cond_false
28 cond_true: ; preds = %entry
29 %val = load i32, ptr %x, align 4
32 cond_false: ; preds = %entry
33 %val2 = load i32, ptr %x, align 4
34 %subval = sub i32 %n, 1
35 %callret = call i32 @foo(ptr %x, i32 %subval, i32 %val2)
36 %subval2 = sub i32 %n, 2
37 %callret2 = call i32 @foo(ptr %x, i32 %subval2, i32 %m)
38 %cmp2 = add i32 %callret, %callret2
41 cond_next: ; No predecessors!
44 return: ; preds = %cond_next, %cond_false, %cond_true
45 %retval.0 = phi i32 [ %val, %cond_true ], [ %cmp2, %cond_false ], [ poison, %cond_next ]
49 define i32 @bar(ptr align(4) dereferenceable(4) %x, i32 %n, i32 %m) {
50 ; CHECK-LABEL: define i32 @bar(
51 ; CHECK-SAME: ptr align 4 dereferenceable(4) [[X:%.*]], i32 [[N:%.*]], i32 [[M:%.*]]) {
52 ; CHECK-NEXT: [[ENTRY:.*:]]
53 ; CHECK-NEXT: [[GEPVAL:%.*]] = getelementptr ptr, ptr [[X]], i32 0
54 ; CHECK-NEXT: [[GEPVAL_VAL:%.*]] = load i32, ptr [[GEPVAL]], align 4
55 ; CHECK-NEXT: [[CALLRET3:%.*]] = call i32 @foo(i32 [[GEPVAL_VAL]], i32 [[N]], i32 [[M]])
56 ; CHECK-NEXT: br label %[[RETURN:.*]]
58 ; CHECK-NEXT: ret i32 [[CALLRET3]]
61 %gepval = getelementptr ptr, ptr %x, i32 0
62 %callret3 = call i32 @foo(ptr %gepval, i32 %n, i32 %m)
65 return: ; preds = %entry
69 define internal i32 @foo2(ptr %x, i32 %n, i32 %m) {
70 ; CHECK-LABEL: define internal i32 @foo2(
71 ; CHECK-SAME: ptr [[X:%.*]], i32 [[N:%.*]], i32 [[M:%.*]]) {
72 ; CHECK-NEXT: [[ENTRY:.*:]]
73 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[N]], 0
74 ; CHECK-NEXT: br i1 [[CMP]], label %[[COND_TRUE:.*]], label %[[COND_FALSE:.*]]
75 ; CHECK: [[COND_TRUE]]:
76 ; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[X]], align 4
77 ; CHECK-NEXT: br label %[[RETURN:.*]]
78 ; CHECK: [[COND_FALSE]]:
79 ; CHECK-NEXT: [[VAL2:%.*]] = load i32, ptr [[X]], align 4
80 ; CHECK-NEXT: [[SUBVAL:%.*]] = sub i32 [[N]], 1
81 ; CHECK-NEXT: [[CALLRET:%.*]] = call i32 @foo2(ptr [[X]], i32 [[SUBVAL]], i32 [[VAL2]])
82 ; CHECK-NEXT: [[SUBVAL2:%.*]] = sub i32 [[N]], 2
83 ; CHECK-NEXT: [[CALLRET2:%.*]] = call i32 @foo2(ptr [[X]], i32 [[SUBVAL2]], i32 [[M]])
84 ; CHECK-NEXT: [[CMP2:%.*]] = add i32 [[CALLRET]], [[CALLRET2]]
85 ; CHECK-NEXT: br label %[[RETURN]]
86 ; CHECK: [[COND_NEXT:.*]]:
87 ; CHECK-NEXT: br label %[[RETURN]]
89 ; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i32 [ [[VAL]], %[[COND_TRUE]] ], [ [[CMP2]], %[[COND_FALSE]] ], [ poison, %[[COND_NEXT]] ]
90 ; CHECK-NEXT: ret i32 [[RETVAL_0]]
93 %cmp = icmp ne i32 %n, 0
94 br i1 %cmp, label %cond_true, label %cond_false
96 cond_true: ; preds = %entry
97 %val = load i32, ptr %x, align 4
100 cond_false: ; preds = %entry
101 %val2 = load i32, ptr %x, align 4
102 %subval = sub i32 %n, 1
103 %callret = call i32 @foo2(ptr %x, i32 %subval, i32 %val2)
104 %subval2 = sub i32 %n, 2
105 %callret2 = call i32 @foo2(ptr %x, i32 %subval2, i32 %m)
106 %cmp2 = add i32 %callret, %callret2
109 cond_next: ; No predecessors!
112 return: ; preds = %cond_next, %cond_false, %cond_true
113 %retval.0 = phi i32 [ %val, %cond_true ], [ %cmp2, %cond_false ], [ poison, %cond_next ]
117 define i32 @bar2(ptr align(4) dereferenceable(4) %x, i32 %n, i32 %m) {
118 ; CHECK-LABEL: define i32 @bar2(
119 ; CHECK-SAME: ptr align 4 dereferenceable(4) [[X:%.*]], i32 [[N:%.*]], i32 [[M:%.*]]) {
120 ; CHECK-NEXT: [[ENTRY:.*:]]
121 ; CHECK-NEXT: [[GEPVAL:%.*]] = getelementptr ptr, ptr [[X]], i32 4
122 ; CHECK-NEXT: [[CALLRET3:%.*]] = call i32 @foo2(ptr [[GEPVAL]], i32 [[N]], i32 [[M]])
123 ; CHECK-NEXT: br label %[[RETURN:.*]]
125 ; CHECK-NEXT: ret i32 [[CALLRET3]]
128 %gepval = getelementptr ptr, ptr %x, i32 4
129 %callret3 = call i32 @foo2(ptr %gepval, i32 %n, i32 %m)
132 return: ; preds = %entry