xref: /llvm-project/llvm/test/CodeGen/PowerPC/duplicate-returns-for-tailcall.ll (revision 5e9021c606e2ebe967b465219b6a76c1ed8895a8)
1; RUN: llc -verify-machineinstrs -mcpu=pwr8 -stop-after codegenprepare -mtriple=powerpc64le-unknown-gnu-linux  < %s | FileCheck %s
2; RUN: llc -verify-machineinstrs -mcpu=pwr8 -stop-after codegenprepare -mtriple=powerpc64-unknown-gnu-linux  < %s | FileCheck %s
3
4; Function Attrs: noinline norecurse nounwind readnone
5define hidden signext i32 @call1(i32 signext %a, i32 signext %b, i32 signext %c) local_unnamed_addr #0 {
6entry:
7  %add = add nsw i32 %b, %a
8  %add1 = add nsw i32 %add, %c
9  ret i32 %add1
10}
11
12; Function Attrs: nounwind
13define signext i32 @test(i32 signext %a, i32 signext %b, i32 signext %c) local_unnamed_addr #1 {
14entry:
15  %cmp = icmp eq i32 %a, %b
16  br i1 %cmp, label %if.then, label %if.end
17
18if.then:                                          ; preds = %entry
19  %call = tail call signext i32 @call1(i32 signext %a, i32 signext %b, i32 signext %c)
20  br label %return
21; The return should get duplciated here to enable a tail-call opportunity.
22; CHECK-LABEL: if.then:
23; CHECK-NEXT:  %[[T1:[a-zA-Z0-9]+]] = tail call signext i32 @call1
24; CHECK-NEXT:  ret i32 %[[T1]]
25
26if.end:                                           ; preds = %entry
27  %cmp1 = icmp slt i32 %a, %b
28  br i1 %cmp1, label %if.then2, label %if.end4
29
30if.then2:                                         ; preds = %if.end
31  %call3 = tail call signext i32 @call2(i32 signext %a, i32 signext %b, i32 signext %c) #3
32  br label %return
33; No duplication here since we cannot tail-call an external function anyway.
34; CHECK-LABEL: if.then2:
35; CHECK-NEXT:  tail call signext i32 @call2
36; CHECK-NEXT:  br
37
38if.end4:                                          ; preds = %if.end
39  %cmp5 = icmp sgt i32 %b, %c
40  br i1 %cmp5, label %if.then6, label %return
41
42if.then6:                                         ; preds = %if.end4
43  %call7 = tail call fastcc signext i32 @call3(i32 signext %a, i32 signext %b, i32 signext %c)
44  br label %return
45; tail calling a fastcc function from a ccc function is supported.
46; CHECK-LABEL: if.then6:
47; CHECK:       %[[T2:[a-zA-Z0-9]+]] = tail call fastcc signext i32 @call3
48; CHECK-NEXT:  ret i32 %[[T2]]
49
50return:                                           ; preds = %if.end4, %if.then6, %if.then2, %if.then
51  %retval.0 = phi i32 [ %call, %if.then ], [ %call3, %if.then2 ], [ %call7, %if.then6 ], [ %c, %if.end4 ]
52  ret i32 %retval.0
53}
54
55declare signext i32 @call2(i32 signext, i32 signext, i32 signext) local_unnamed_addr #2
56
57; Function Attrs: noinline norecurse nounwind readnone
58define internal fastcc signext i32 @call3(i32 signext %a, i32 signext %b, i32 signext %c) unnamed_addr #0 {
59entry:
60  %mul = mul nsw i32 %b, %a
61  %mul1 = mul nsw i32 %mul, %c
62  ret i32 %mul1
63}
64