xref: /llvm-project/llvm/test/Transforms/FunctionSpecialization/identical-specializations.ll (revision 06664fdc7680f7f9fa9b0a414a8fb8df2f913d48)
1d68083feSHari Limaye; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --include-generated-funcs --version 5
2*06664fdcSHari Limaye; RUN: opt -passes="ipsccp<func-spec>" -force-specialization -funcspec-for-literal-constant=false -S < %s | FileCheck %s
325162418SAlexandros Lamprineas
425162418SAlexandros Lamprineasdefine i64 @main(i64 %x, i64 %y, i1 %flag) {
525162418SAlexandros Lamprineasentry:
625162418SAlexandros Lamprineas  br i1 %flag, label %plus, label %minus
725162418SAlexandros Lamprineas
825162418SAlexandros Lamprineasplus:
996a14f38SNikita Popov  %cmp0 = call i64 @compute(i64 %x, i64 %y, ptr @plus, ptr @minus)
1025162418SAlexandros Lamprineas  br label %merge
1125162418SAlexandros Lamprineas
1225162418SAlexandros Lamprineasminus:
13ebdf5aefSMatt Arsenault  %cmp1 = call i64 @compute(i64 %x, i64 %y, ptr @minus, ptr @plus)
1425162418SAlexandros Lamprineas  br label %merge
1525162418SAlexandros Lamprineas
1625162418SAlexandros Lamprineasmerge:
1725162418SAlexandros Lamprineas  %ph = phi i64 [ %cmp0, %plus ], [ %cmp1, %minus]
18ebdf5aefSMatt Arsenault  %cmp2 = call i64 @compute(i64 %ph, i64 42, ptr @plus, ptr @minus)
1925162418SAlexandros Lamprineas  ret i64 %cmp2
2025162418SAlexandros Lamprineas}
2125162418SAlexandros Lamprineas
22ebdf5aefSMatt Arsenaultdefine internal i64 @compute(i64 %x, i64 %y, ptr %binop1, ptr %binop2) {
2325162418SAlexandros Lamprineasentry:
2425162418SAlexandros Lamprineas  %op0 = call i64 %binop1(i64 %x, i64 %y)
2525162418SAlexandros Lamprineas  %op1 = call i64 %binop2(i64 %x, i64 %y)
26ebdf5aefSMatt Arsenault  %op2 = call i64 @compute(i64 %x, i64 %y, ptr %binop1, ptr @plus)
2725162418SAlexandros Lamprineas  %add0 = add i64 %op0, %op1
2825162418SAlexandros Lamprineas  %add1 = add i64 %add0, %op2
2925162418SAlexandros Lamprineas  %div = sdiv i64 %add1, %x
3025162418SAlexandros Lamprineas  %sub = sub i64 %div, %y
3125162418SAlexandros Lamprineas  %mul = mul i64 %sub, 2
3225162418SAlexandros Lamprineas  ret i64 %mul
3325162418SAlexandros Lamprineas}
3425162418SAlexandros Lamprineas
3525162418SAlexandros Lamprineasdefine internal i64 @plus(i64 %x, i64 %y) {
3625162418SAlexandros Lamprineasentry:
3725162418SAlexandros Lamprineas  %add = add i64 %x, %y
3825162418SAlexandros Lamprineas  ret i64 %add
3925162418SAlexandros Lamprineas}
4025162418SAlexandros Lamprineas
4125162418SAlexandros Lamprineasdefine internal i64 @minus(i64 %x, i64 %y) {
4225162418SAlexandros Lamprineasentry:
4325162418SAlexandros Lamprineas  %sub = sub i64 %x, %y
4425162418SAlexandros Lamprineas  ret i64 %sub
4525162418SAlexandros Lamprineas}
4625162418SAlexandros Lamprineas
4725162418SAlexandros Lamprineas
4825162418SAlexandros Lamprineas
49d68083feSHari Limaye; CHECK-LABEL: define i64 @main(
50d68083feSHari Limaye; CHECK-SAME: i64 [[X:%.*]], i64 [[Y:%.*]], i1 [[FLAG:%.*]]) {
51d68083feSHari Limaye; CHECK-NEXT:  [[ENTRY:.*:]]
52d68083feSHari Limaye; CHECK-NEXT:    br i1 [[FLAG]], label %[[PLUS:.*]], label %[[MINUS:.*]]
53d68083feSHari Limaye; CHECK:       [[PLUS]]:
54d68083feSHari Limaye; CHECK-NEXT:    [[CMP0:%.*]] = call i64 @compute.specialized.2(i64 [[X]], i64 [[Y]], ptr @plus, ptr @minus)
55d68083feSHari Limaye; CHECK-NEXT:    br label %[[MERGE:.*]]
56d68083feSHari Limaye; CHECK:       [[MINUS]]:
57d68083feSHari Limaye; CHECK-NEXT:    [[CMP1:%.*]] = call i64 @compute.specialized.3(i64 [[X]], i64 [[Y]], ptr @minus, ptr @plus)
58d68083feSHari Limaye; CHECK-NEXT:    br label %[[MERGE]]
59d68083feSHari Limaye; CHECK:       [[MERGE]]:
60d68083feSHari Limaye; CHECK-NEXT:    [[PH:%.*]] = phi i64 [ [[CMP0]], %[[PLUS]] ], [ [[CMP1]], %[[MINUS]] ]
61d68083feSHari Limaye; CHECK-NEXT:    [[CMP2:%.*]] = call i64 @compute.specialized.2(i64 [[PH]], i64 42, ptr @plus, ptr @minus)
62d68083feSHari Limaye; CHECK-NEXT:    ret i64 [[CMP2]]
63d68083feSHari Limaye;
64d68083feSHari Limaye;
65d68083feSHari Limaye; CHECK-LABEL: define internal i64 @plus(
66d68083feSHari Limaye; CHECK-SAME: i64 [[X:%.*]], i64 [[Y:%.*]]) {
67d68083feSHari Limaye; CHECK-NEXT:  [[ENTRY:.*:]]
68d68083feSHari Limaye; CHECK-NEXT:    [[ADD:%.*]] = add i64 [[X]], [[Y]]
69d68083feSHari Limaye; CHECK-NEXT:    ret i64 [[ADD]]
70d68083feSHari Limaye;
71d68083feSHari Limaye;
72d68083feSHari Limaye; CHECK-LABEL: define internal i64 @minus(
73d68083feSHari Limaye; CHECK-SAME: i64 [[X:%.*]], i64 [[Y:%.*]]) {
74d68083feSHari Limaye; CHECK-NEXT:  [[ENTRY:.*:]]
75d68083feSHari Limaye; CHECK-NEXT:    [[SUB:%.*]] = sub i64 [[X]], [[Y]]
76d68083feSHari Limaye; CHECK-NEXT:    ret i64 [[SUB]]
77d68083feSHari Limaye;
78d68083feSHari Limaye;
79d68083feSHari Limaye; CHECK-LABEL: define internal i64 @compute.specialized.1(
80d68083feSHari Limaye; CHECK-SAME: i64 [[X:%.*]], i64 [[Y:%.*]], ptr [[BINOP1:%.*]], ptr [[BINOP2:%.*]]) {
81d68083feSHari Limaye; CHECK-NEXT:  [[ENTRY:.*:]]
82d68083feSHari Limaye; CHECK-NEXT:    [[OP1:%.*]] = call i64 [[BINOP1]](i64 [[X]], i64 [[Y]])
83d68083feSHari Limaye; CHECK-NEXT:    [[OP0:%.*]] = call i64 @plus(i64 [[X]], i64 [[Y]])
84d68083feSHari Limaye; CHECK-NEXT:    [[OP2:%.*]] = call i64 @compute.specialized.1(i64 [[X]], i64 [[Y]], ptr [[BINOP1]], ptr @plus)
85d68083feSHari Limaye; CHECK-NEXT:    [[ADD0:%.*]] = add i64 [[OP1]], [[OP0]]
86d68083feSHari Limaye; CHECK-NEXT:    [[ADD1:%.*]] = add i64 [[ADD0]], [[OP2]]
87d68083feSHari Limaye; CHECK-NEXT:    [[DIV:%.*]] = sdiv i64 [[ADD1]], [[X]]
88d68083feSHari Limaye; CHECK-NEXT:    [[SUB:%.*]] = sub i64 [[DIV]], [[Y]]
89d68083feSHari Limaye; CHECK-NEXT:    [[MUL:%.*]] = mul i64 [[SUB]], 2
90d68083feSHari Limaye; CHECK-NEXT:    ret i64 [[MUL]]
91d68083feSHari Limaye;
92d68083feSHari Limaye;
93d68083feSHari Limaye; CHECK-LABEL: define internal i64 @compute.specialized.2(
94d68083feSHari Limaye; CHECK-SAME: i64 [[X:%.*]], i64 [[Y:%.*]], ptr [[BINOP1:%.*]], ptr [[BINOP2:%.*]]) {
95d68083feSHari Limaye; CHECK-NEXT:  [[ENTRY:.*:]]
96d68083feSHari Limaye; CHECK-NEXT:    [[OP0:%.*]] = call i64 @plus(i64 [[X]], i64 [[Y]])
97d68083feSHari Limaye; CHECK-NEXT:    [[OP1:%.*]] = call i64 @minus(i64 [[X]], i64 [[Y]])
98d68083feSHari Limaye; CHECK-NEXT:    [[OP2:%.*]] = call i64 @compute.specialized.1(i64 [[X]], i64 [[Y]], ptr @plus, ptr @plus)
99d68083feSHari Limaye; CHECK-NEXT:    [[ADD0:%.*]] = add i64 [[OP0]], [[OP1]]
100d68083feSHari Limaye; CHECK-NEXT:    [[ADD1:%.*]] = add i64 [[ADD0]], [[OP2]]
101d68083feSHari Limaye; CHECK-NEXT:    [[DIV:%.*]] = sdiv i64 [[ADD1]], [[X]]
102d68083feSHari Limaye; CHECK-NEXT:    [[SUB:%.*]] = sub i64 [[DIV]], [[Y]]
103d68083feSHari Limaye; CHECK-NEXT:    [[MUL:%.*]] = mul i64 [[SUB]], 2
104d68083feSHari Limaye; CHECK-NEXT:    ret i64 [[MUL]]
105d68083feSHari Limaye;
106d68083feSHari Limaye;
107d68083feSHari Limaye; CHECK-LABEL: define internal i64 @compute.specialized.3(
108d68083feSHari Limaye; CHECK-SAME: i64 [[X:%.*]], i64 [[Y:%.*]], ptr [[BINOP1:%.*]], ptr [[BINOP2:%.*]]) {
109d68083feSHari Limaye; CHECK-NEXT:  [[ENTRY:.*:]]
110d68083feSHari Limaye; CHECK-NEXT:    [[OP0:%.*]] = call i64 @minus(i64 [[X]], i64 [[Y]])
111d68083feSHari Limaye; CHECK-NEXT:    [[OP1:%.*]] = call i64 @plus(i64 [[X]], i64 [[Y]])
112d68083feSHari Limaye; CHECK-NEXT:    [[OP2:%.*]] = call i64 @compute.specialized.3(i64 [[X]], i64 [[Y]], ptr @minus, ptr @plus)
113d68083feSHari Limaye; CHECK-NEXT:    [[ADD0:%.*]] = add i64 [[OP0]], [[OP1]]
114d68083feSHari Limaye; CHECK-NEXT:    [[ADD1:%.*]] = add i64 [[ADD0]], [[OP2]]
115d68083feSHari Limaye; CHECK-NEXT:    [[DIV:%.*]] = sdiv i64 [[ADD1]], [[X]]
116d68083feSHari Limaye; CHECK-NEXT:    [[SUB:%.*]] = sub i64 [[DIV]], [[Y]]
117d68083feSHari Limaye; CHECK-NEXT:    [[MUL:%.*]] = mul i64 [[SUB]], 2
118d68083feSHari Limaye; CHECK-NEXT:    ret i64 [[MUL]]
119d68083feSHari Limaye;
120