File: fake-use-tailcall.mir

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,696 kB
  • sloc: cpp: 7,438,781; ansic: 1,393,871; asm: 1,012,926; python: 241,771; f90: 86,635; objc: 75,411; lisp: 42,144; pascal: 17,286; sh: 8,596; ml: 5,082; perl: 4,730; makefile: 3,591; awk: 3,523; javascript: 2,251; xml: 892; fortran: 672
file content (99 lines) | stat: -rw-r--r-- 2,694 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# In certain cases CodeGenPrepare folds a return instruction into
# the return block's predecessor blocks and subsequently deletes the return block.
# The purpose of this is to enable tail call optimization in the predecessor blocks.
# Removal of the return block also removes fake use instructions that were present
# in the return block, potentially causing debug information to be lost.
#
# The fix is to clone any fake use instructions that are not dominated by definitions
# in the return block itself into the predecessor blocks. This test enures that we do so.
#
# Generated from the following source with
# clang -fextend-variable-liveness -S -emit-llvm -O2 -mllvm -stop-before=codegenprepare -o test.mir test.c
#
# extern int f0();
# extern int f1();
#
# int foo(int i) {
#   int temp = i;
#   if (temp == 0)
#     temp = f0();
#   else
#     temp = f1();
#   return temp;
# }
#
# RUN: llc -run-pass=codegenprepare -mtriple=x86_64-unknown-linux -o - %s | FileCheck %s
#
# CHECK:      define{{.*}}foo
# CHECK:      if.then:
# CHECK-NEXT: call{{.*}}fake.use(i32 %i)
# CHECK-NEXT: tail call i32{{.*}}@f0
# CHECK-NEXT: ret
# CHECK:      if.else:
# CHECK-NEXT: call{{.*}}fake.use(i32 %i)
# CHECK-NEXT: tail call i32{{.*}}@f1
# CHECK-NEXT: ret

--- |
  define hidden i32 @foo(i32 %i) local_unnamed_addr optdebug {
  entry:
    %cmp = icmp eq i32 %i, 0
    br i1 %cmp, label %if.then, label %if.else

  if.then:
    %call = tail call i32 (...) @f0()
    br label %if.end

  if.else:
    %call1 = tail call i32 (...) @f1()
    br label %if.end

  if.end:
    %temp.0 = phi i32 [ %call, %if.then ], [ %call1, %if.else ]
    notail call void (...) @llvm.fake.use(i32 %temp.0)
    notail call void (...) @llvm.fake.use(i32 %i)
    ret i32 %temp.0
  }
  declare i32 @f0(...) local_unnamed_addr
  declare i32 @f1(...) local_unnamed_addr

...
---
name:            foo
alignment:       16
exposesReturnsTwice: false
legalized:       false
regBankSelected: false
selected:        false
failedISel:      false
tracksRegLiveness: true
hasWinCFI:       false
registers:       []
liveins:         []
frameInfo:
  isFrameAddressTaken: false
  isReturnAddressTaken: false
  hasStackMap:     false
  hasPatchPoint:   false
  stackSize:       0
  offsetAdjustment: 0
  maxAlignment:    1
  adjustsStack:    false
  hasCalls:        false
  stackProtector:  ''
  maxCallFrameSize: 4294967295
  cvBytesOfCalleeSavedRegisters: 0
  hasOpaqueSPAdjustment: false
  hasVAStart:      false
  hasMustTailInVarArgFunc: false
  localFrameSize:  0
  savePoint:       ''
  restorePoint:    ''
fixedStack:      []
stack:           []
callSites:       []
constants:       []
machineFunctionInfo: {}
body:             |

...