xref: /llvm-project/llvm/test/Transforms/FunctionSpecialization/literal-const.ll (revision 06664fdc7680f7f9fa9b0a414a8fb8df2f913d48)
1; RUN: opt -S --passes="ipsccp<func-spec>" \
2; RUN:        -funcspec-for-literal-constant=false \
3; RUN:        -force-specialization < %s | FileCheck %s -check-prefix CHECK-NOLIT
4; RUN: opt -S --passes="ipsccp<func-spec>" \
5; RUN:        -force-specialization < %s | FileCheck %s -check-prefix CHECK-LIT
6
7define i32 @f0(i32 noundef %x) {
8entry:
9  %call = tail call i32 @neg(i32 noundef %x, i1 noundef zeroext false)
10  ret i32 %call
11}
12
13define i32 @f1(i32 noundef %x) {
14entry:
15  %call = tail call i32 @neg(i32 noundef %x, i1 noundef zeroext true)
16  ret i32 %call
17}
18
19define i32 @g0(i32 noundef %x) {
20entry:
21  %call = tail call i32 @add(i32 noundef %x, i32 noundef 1)
22  ret i32 %call
23}
24
25define i32 @g1(i32 noundef %x) {
26entry:
27  %call = tail call i32 @add(i32 noundef %x, i32 noundef 2)
28  ret i32 %call
29}
30
31define float @h0(float noundef %x) {
32entry:
33  %call = tail call float @addf(float noundef %x, float noundef 1.000000e+00)
34  ret float %call
35}
36
37define float @h1(float noundef %x) {
38entry:
39  %call = tail call float @addf(float noundef %x, float noundef 2.000000e+00)
40  ret float %call
41}
42
43define internal i32 @neg(i32 noundef %x, i1 noundef zeroext %b) {
44entry:
45  %sub = sub nsw i32 0, %x
46  %cond = select i1 %b, i32 %sub, i32 %x
47  ret i32 %cond
48}
49
50define internal i32 @add(i32 noundef %x, i32 noundef %y) {
51entry:
52  %add = add nsw i32 %y, %x
53  ret i32 %add
54}
55
56define internal float @addf(float noundef %x, float noundef %y) {
57entry:
58  %add = fadd float %x, %y
59  ret float %add
60}
61
62
63; Check no functions were specialised.
64; CHECK-NOLIT-NOT: @neg.
65; CHECK-NOLIT-NOT: @add.
66; CHECK-NOLIT-NOT: @addf.
67
68; CHECK-LIT-LABEL: define i32 @f0
69; CHECK-LIT: call i32 @neg.specialized.[[#A:]]
70
71; CHECK-LIT-LABEL: define i32 @f1
72; CHECK-LIT: call i32 @neg.specialized.[[#B:]]
73
74; CHECK-LIT-LABEL: define range(i32 -2147483647, -2147483648) i32 @g0
75; CHECK-LIT: call i32 @add.specialized.[[#C:]]
76
77; CHECK-LIT-LABEL: define range(i32 -2147483647, -2147483648) i32 @g1
78; CHECK-LIT: call i32 @add.specialized.[[#D:]]
79
80; CHECK-LIT-LABEL: define float @h0
81; CHECK-LIT: call float @addf.specialized.[[#E:]]
82
83; CHECK-LIT-LABEL: define float @h1
84; CHECK-LIT: call float @addf.specialized.[[#F:]]
85
86; Check all of `neg`, `add`, and `addf` were specialised.
87; CHECK-LIT-DAG: @neg.specialized.[[#A]]
88; CHECK-LIT-DAG: @neg.specialized.[[#B]]
89; CHECK-LIT-DAG: @add.specialized.[[#C]]
90; CHECK-LIT-DAG: @add.specialized.[[#D]]
91; CHECK-LIT-DAG: @addf.specialized.[[#E]]
92; CHECK-LIT-DAG: @addf.specialized.[[#F]]
93