xref: /llvm-project/llvm/test/Transforms/FunctionSpecialization/get-possible-constants.ll (revision 06664fdc7680f7f9fa9b0a414a8fb8df2f913d48)
1; RUN: opt -S --passes="ipsccp<func-spec>" -funcspec-for-literal-constant=false < %s | FileCheck %s
2define dso_local i32 @p0(i32 noundef %x) {
3entry:
4  %add = add nsw i32 %x, 1
5  ret i32 %add
6}
7
8define dso_local i32 @p1(i32 noundef %x) {
9entry:
10  %sub = add nsw i32 %x, -1
11  ret i32 %sub
12}
13
14; CHECK-LABEL: define dso_local i32 @f0
15; CHECK:       tail call fastcc i32 @g.specialized.[[#A:]]({{.*}}@p0)
16;
17define dso_local i32 @f0(i32 noundef %x) {
18entry:
19  %call = tail call fastcc i32 @g(i32 noundef %x, ptr noundef nonnull @p0)
20  ret i32 %call
21}
22
23; CHECK-LABEL: define dso_local i32 @f1
24; CHECK:       tail call fastcc i32 @g.specialized.[[#B:]]({{.*}}@p1)
25;
26define dso_local i32 @f1(i32 noundef %x) {
27entry:
28  %call = tail call fastcc i32 @g(i32 noundef %x, ptr noundef nonnull @p1)
29  ret i32 %call
30}
31
32; @g gets fully specialized
33; CHECK-NOT: define internal fastcc i32 @g(
34
35define internal fastcc i32 @g(i32 noundef %x, ptr nocapture noundef readonly %p) noinline  {
36entry:
37  %pcall = tail call i32 %p(i32 noundef %x)
38  %fcall = tail call fastcc i32 @f(i32 noundef %pcall, ptr noundef nonnull %p)
39  ret i32 %fcall
40}
41
42; CHECK-LABEL: define dso_local i32 @g0
43; CHECK:       tail call fastcc i32 @f.specialized.[[#C:]]({{.*}}@p0)
44;
45define dso_local i32 @g0(i32 noundef %x) {
46entry:
47  %call = tail call fastcc i32 @f(i32 noundef %x, ptr noundef nonnull @p0)
48  ret i32 %call
49}
50
51define internal fastcc i32 @f(i32 noundef %x, ptr nocapture noundef readonly %p) noinline  {
52entry:
53  %call = tail call i32 %p(i32 noundef %x)
54  %add = add nsw i32 %call, %x
55  ret i32 %add
56}
57
58; CHECK-LABEL: define dso_local i32 @g1
59; CHECK:       tail call fastcc i32 @f.specialized.[[#D:]]({{.*}}@p1)
60;
61define dso_local i32 @g1(i32 noundef %x) {
62entry:
63  %call = tail call fastcc i32 @f(i32 noundef %x, ptr noundef nonnull @p1)
64  ret i32 %call
65}
66
67define dso_local i32 @g2(i32 noundef %x) {
68entry:
69  %call = tail call fastcc i32 @f(i32 noundef %x, ptr poison)
70  ret i32 %call
71}
72
73; Check that a single argument, that cannot be used for specialisation, does not
74; prevent specialisation based on other arguments.
75;
76; Also check that for callsites which reside in the body of newly created
77; (specialized) functions, the lattice value of the arguments is known.
78;
79; CHECK-DAG: define internal fastcc i32 @g.specialized.[[#A]]
80; CHECK-DAG: define internal fastcc i32 @g.specialized.[[#B]]
81; CHECK-DAG: define internal fastcc i32 @f.specialized.[[#C]]
82; CHECK-DAG: define internal fastcc i32 @f.specialized.[[#D]]
83