1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes="ipsccp<func-spec>" -funcspec-max-clones=0 -funcspec-min-function-size=14 -S < %s | FileCheck %s --check-prefix=NONE
3 ; RUN: opt -passes="ipsccp<func-spec>" -funcspec-max-clones=1 -funcspec-min-function-size=14 -S < %s | FileCheck %s --check-prefix=ONE
4 ; RUN: opt -passes="ipsccp<func-spec>" -funcspec-max-clones=2 -funcspec-min-function-size=14 -S < %s | FileCheck %s --check-prefix=TWO
5 ; RUN: opt -passes="ipsccp<func-spec>" -funcspec-max-clones=3 -funcspec-min-function-size=14 -S < %s | FileCheck %s --check-prefix=THREE
7 ; Make sure that we iterate correctly after sorting the specializations:
8 ; FnSpecialization: Specializations for function compute
9 ; FnSpecialization: Gain = 608
10 ; FnSpecialization: FormalArg = binop1, ActualArg = power
11 ; FnSpecialization: FormalArg = binop2, ActualArg = mul
12 ; FnSpecialization: Gain = 982
13 ; FnSpecialization: FormalArg = binop1, ActualArg = plus
14 ; FnSpecialization: FormalArg = binop2, ActualArg = minus
15 ; FnSpecialization: Gain = 795
16 ; FnSpecialization: FormalArg = binop1, ActualArg = minus
17 ; FnSpecialization: FormalArg = binop2, ActualArg = power
19 define i64 @main(i64 %x, i64 %y, i1 %flag) {
22 ; NONE-NEXT: br i1 [[FLAG:%.*]], label [[PLUS:%.*]], label [[MINUS:%.*]]
24 ; NONE-NEXT: [[TMP0:%.*]] = call i64 @compute(i64 [[X:%.*]], i64 [[Y:%.*]], ptr @power, ptr @mul)
25 ; NONE-NEXT: br label [[MERGE:%.*]]
27 ; NONE-NEXT: [[TMP1:%.*]] = call i64 @compute(i64 [[X]], i64 [[Y]], ptr @plus, ptr @minus)
28 ; NONE-NEXT: br label [[MERGE]]
30 ; NONE-NEXT: [[TMP2:%.*]] = phi i64 [ [[TMP0]], [[PLUS]] ], [ [[TMP1]], [[MINUS]] ]
31 ; NONE-NEXT: [[TMP3:%.*]] = call i64 @compute(i64 [[TMP2]], i64 42, ptr @minus, ptr @power)
32 ; NONE-NEXT: ret i64 [[TMP3]]
36 ; ONE-NEXT: br i1 [[FLAG:%.*]], label [[PLUS:%.*]], label [[MINUS:%.*]]
38 ; ONE-NEXT: [[TMP0:%.*]] = call i64 @compute(i64 [[X:%.*]], i64 [[Y:%.*]], ptr @power, ptr @mul)
39 ; ONE-NEXT: br label [[MERGE:%.*]]
41 ; ONE-NEXT: [[TMP1:%.*]] = call i64 @compute.specialized.1(i64 [[X]], i64 [[Y]], ptr @plus, ptr @minus)
42 ; ONE-NEXT: br label [[MERGE]]
44 ; ONE-NEXT: [[TMP2:%.*]] = phi i64 [ [[TMP0]], [[PLUS]] ], [ [[TMP1]], [[MINUS]] ]
45 ; ONE-NEXT: [[TMP3:%.*]] = call i64 @compute(i64 [[TMP2]], i64 42, ptr @minus, ptr @power)
46 ; ONE-NEXT: ret i64 [[TMP3]]
50 ; TWO-NEXT: br i1 [[FLAG:%.*]], label [[PLUS:%.*]], label [[MINUS:%.*]]
52 ; TWO-NEXT: [[TMP0:%.*]] = call i64 @compute(i64 [[X:%.*]], i64 [[Y:%.*]], ptr @power, ptr @mul)
53 ; TWO-NEXT: br label [[MERGE:%.*]]
55 ; TWO-NEXT: [[TMP1:%.*]] = call i64 @compute.specialized.2(i64 [[X]], i64 [[Y]], ptr @plus, ptr @minus)
56 ; TWO-NEXT: br label [[MERGE]]
58 ; TWO-NEXT: [[TMP2:%.*]] = phi i64 [ [[TMP0]], [[PLUS]] ], [ [[TMP1]], [[MINUS]] ]
59 ; TWO-NEXT: [[TMP3:%.*]] = call i64 @compute.specialized.1(i64 [[TMP2]], i64 42, ptr @minus, ptr @power)
60 ; TWO-NEXT: ret i64 [[TMP3]]
64 ; THREE-NEXT: br i1 [[FLAG:%.*]], label [[PLUS:%.*]], label [[MINUS:%.*]]
66 ; THREE-NEXT: [[TMP0:%.*]] = call i64 @compute.specialized.1(i64 [[X:%.*]], i64 [[Y:%.*]], ptr @power, ptr @mul)
67 ; THREE-NEXT: br label [[MERGE:%.*]]
69 ; THREE-NEXT: [[TMP1:%.*]] = call i64 @compute.specialized.2(i64 [[X]], i64 [[Y]], ptr @plus, ptr @minus)
70 ; THREE-NEXT: br label [[MERGE]]
72 ; THREE-NEXT: [[TMP2:%.*]] = phi i64 [ [[TMP0]], [[PLUS]] ], [ [[TMP1]], [[MINUS]] ]
73 ; THREE-NEXT: [[TMP3:%.*]] = call i64 @compute.specialized.3(i64 [[TMP2]], i64 42, ptr @minus, ptr @power)
74 ; THREE-NEXT: ret i64 [[TMP3]]
77 br i1 %flag, label %plus, label %minus
80 %tmp0 = call i64 @compute(i64 %x, i64 %y, ptr @power, ptr @mul)
84 %tmp1 = call i64 @compute(i64 %x, i64 %y, ptr @plus, ptr @minus)
88 %tmp2 = phi i64 [ %tmp0, %plus ], [ %tmp1, %minus]
89 %tmp3 = call i64 @compute(i64 %tmp2, i64 42, ptr @minus, ptr @power)
93 ; THREE-NOT: define internal i64 @compute
95 ; THREE-LABEL: define internal i64 @compute.specialized.1(i64 %x, i64 %y, ptr %binop1, ptr %binop2) {
97 ; THREE-NEXT: [[TMP0:%.+]] = call i64 @power(i64 %x, i64 %y)
98 ; THREE-NEXT: [[TMP1:%.+]] = call i64 @mul(i64 %x, i64 %y)
99 ; THREE-NEXT: [[TMP2:%.+]] = add i64 [[TMP0]], [[TMP1]]
100 ; THREE-NEXT: [[TMP3:%.+]] = sdiv i64 [[TMP2]], %x
101 ; THREE-NEXT: [[TMP4:%.+]] = sub i64 [[TMP3]], %y
102 ; THREE-NEXT: [[TMP5:%.+]] = mul i64 [[TMP4]], 2
103 ; THREE-NEXT: ret i64 [[TMP5]]
106 ; THREE-LABEL: define internal i64 @compute.specialized.2(i64 %x, i64 %y, ptr %binop1, ptr %binop2) {
108 ; THREE-NEXT: [[TMP0:%.+]] = call i64 @plus(i64 %x, i64 %y)
109 ; THREE-NEXT: [[TMP1:%.+]] = call i64 @minus(i64 %x, i64 %y)
110 ; THREE-NEXT: [[TMP2:%.+]] = add i64 [[TMP0]], [[TMP1]]
111 ; THREE-NEXT: [[TMP3:%.+]] = sdiv i64 [[TMP2]], %x
112 ; THREE-NEXT: [[TMP4:%.+]] = sub i64 [[TMP3]], %y
113 ; THREE-NEXT: [[TMP5:%.+]] = mul i64 [[TMP4]], 2
114 ; THREE-NEXT: ret i64 [[TMP5]]
117 ; THREE-LABEL: define internal i64 @compute.specialized.3(i64 %x, i64 %y, ptr %binop1, ptr %binop2) {
119 ; THREE-NEXT: [[TMP0:%.+]] = call i64 @minus(i64 %x, i64 %y)
120 ; THREE-NEXT: [[TMP1:%.+]] = call i64 @power(i64 %x, i64 %y)
121 ; THREE-NEXT: [[TMP2:%.+]] = add i64 [[TMP0]], [[TMP1]]
122 ; THREE-NEXT: [[TMP3:%.+]] = sdiv i64 [[TMP2]], %x
123 ; THREE-NEXT: [[TMP4:%.+]] = sub i64 [[TMP3]], %y
124 ; THREE-NEXT: [[TMP5:%.+]] = mul i64 [[TMP4]], 2
125 ; THREE-NEXT: ret i64 [[TMP5]]
128 define internal i64 @compute(i64 %x, i64 %y, ptr %binop1, ptr %binop2) {
130 %tmp0 = call i64 %binop1(i64 %x, i64 %y)
131 %tmp1 = call i64 %binop2(i64 %x, i64 %y)
132 %add = add i64 %tmp0, %tmp1
133 %div = sdiv i64 %add, %x
134 %sub = sub i64 %div, %y
135 %mul = mul i64 %sub, 2
139 define internal i64 @plus(i64 %x, i64 %y) {
141 %tmp0 = add i64 %x, %y
145 define internal i64 @minus(i64 %x, i64 %y) {
147 %tmp0 = sub i64 %x, %y
151 define internal i64 @mul(i64 %x, i64 %n) {
153 %cmp6 = icmp sgt i64 %n, 1
154 br i1 %cmp6, label %for.body, label %for.cond.cleanup
156 for.cond.cleanup: ; preds = %for.body, %entry
157 %x.addr.0.lcssa = phi i64 [ %x, %entry ], [ %add, %for.body ]
158 ret i64 %x.addr.0.lcssa
160 for.body: ; preds = %entry, %for.body
161 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 1, %entry ]
162 %x.addr.07 = phi i64 [ %add, %for.body ], [ %x, %entry ]
163 %add = shl nsw i64 %x.addr.07, 1
164 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
165 %exitcond.not = icmp eq i64 %indvars.iv.next, %n
166 br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
169 define internal i64 @power(i64 %x, i64 %n) {
171 %cmp6 = icmp sgt i64 %n, 1
172 br i1 %cmp6, label %for.body, label %for.cond.cleanup
174 for.cond.cleanup: ; preds = %for.body, %entry
175 %x.addr.0.lcssa = phi i64 [ %x, %entry ], [ %mul, %for.body ]
176 ret i64 %x.addr.0.lcssa
178 for.body: ; preds = %entry, %for.body
179 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 1, %entry ]
180 %x.addr.07 = phi i64 [ %mul, %for.body ], [ %x, %entry ]
181 %mul = mul nsw i64 %x.addr.07, %x.addr.07
182 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
183 %exitcond.not = icmp eq i64 %indvars.iv.next, %n
184 br i1 %exitcond.not, label %for.cond.cleanup, label %for.body