File: shrinkwrap.ll

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.6-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,304 kB
  • sloc: cpp: 7,438,677; ansic: 1,393,822; asm: 1,012,926; python: 241,650; f90: 86,635; objc: 75,479; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (170 lines) | stat: -rw-r--r-- 5,916 bytes parent folder | download | duplicates (6)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=riscv32 -mattr=+m,+v < %s | FileCheck --check-prefix=RV32 %s
; RUN: llc -mtriple=riscv64 -mattr=+m,+v < %s | FileCheck --check-prefix=RV64 %s

; FIXME: We can rematerialize "addi s0, a2, 32" (ideally along the edge
; %do.call -> %exit), and shrink wrap this routine
define void @vecaddr_straightline(i32 zeroext %a, ptr %p) {
; RV32-LABEL: vecaddr_straightline:
; RV32:       # %bb.0:
; RV32-NEXT:    addi sp, sp, -16
; RV32-NEXT:    .cfi_def_cfa_offset 16
; RV32-NEXT:    sw ra, 12(sp) # 4-byte Folded Spill
; RV32-NEXT:    sw s0, 8(sp) # 4-byte Folded Spill
; RV32-NEXT:    .cfi_offset ra, -4
; RV32-NEXT:    .cfi_offset s0, -8
; RV32-NEXT:    addi s0, a1, 32
; RV32-NEXT:    vsetivli zero, 4, e32, m1, ta, ma
; RV32-NEXT:    vle32.v v8, (s0)
; RV32-NEXT:    vadd.vi v8, v8, 1
; RV32-NEXT:    li a1, 57
; RV32-NEXT:    vse32.v v8, (s0)
; RV32-NEXT:    beq a0, a1, .LBB0_2
; RV32-NEXT:  # %bb.1: # %do_call
; RV32-NEXT:    call foo
; RV32-NEXT:    vsetivli zero, 4, e32, m1, ta, ma
; RV32-NEXT:  .LBB0_2: # %exit
; RV32-NEXT:    vle32.v v8, (s0)
; RV32-NEXT:    vadd.vi v8, v8, 1
; RV32-NEXT:    vse32.v v8, (s0)
; RV32-NEXT:    lw ra, 12(sp) # 4-byte Folded Reload
; RV32-NEXT:    lw s0, 8(sp) # 4-byte Folded Reload
; RV32-NEXT:    .cfi_restore ra
; RV32-NEXT:    .cfi_restore s0
; RV32-NEXT:    addi sp, sp, 16
; RV32-NEXT:    .cfi_def_cfa_offset 0
; RV32-NEXT:    ret
;
; RV64-LABEL: vecaddr_straightline:
; RV64:       # %bb.0:
; RV64-NEXT:    addi sp, sp, -16
; RV64-NEXT:    .cfi_def_cfa_offset 16
; RV64-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
; RV64-NEXT:    sd s0, 0(sp) # 8-byte Folded Spill
; RV64-NEXT:    .cfi_offset ra, -8
; RV64-NEXT:    .cfi_offset s0, -16
; RV64-NEXT:    addi s0, a1, 32
; RV64-NEXT:    vsetivli zero, 4, e32, m1, ta, ma
; RV64-NEXT:    vle32.v v8, (s0)
; RV64-NEXT:    vadd.vi v8, v8, 1
; RV64-NEXT:    li a1, 57
; RV64-NEXT:    vse32.v v8, (s0)
; RV64-NEXT:    beq a0, a1, .LBB0_2
; RV64-NEXT:  # %bb.1: # %do_call
; RV64-NEXT:    call foo
; RV64-NEXT:    vsetivli zero, 4, e32, m1, ta, ma
; RV64-NEXT:  .LBB0_2: # %exit
; RV64-NEXT:    vle32.v v8, (s0)
; RV64-NEXT:    vadd.vi v8, v8, 1
; RV64-NEXT:    vse32.v v8, (s0)
; RV64-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
; RV64-NEXT:    ld s0, 0(sp) # 8-byte Folded Reload
; RV64-NEXT:    .cfi_restore ra
; RV64-NEXT:    .cfi_restore s0
; RV64-NEXT:    addi sp, sp, 16
; RV64-NEXT:    .cfi_def_cfa_offset 0
; RV64-NEXT:    ret
  %gep = getelementptr i8, ptr %p, i32 32
  %v1 = load <4 x i32>, ptr %gep
  %v2 = add <4 x i32> %v1, splat (i32 1)
  store <4 x i32> %v2, ptr %gep
  %cmp0 = icmp eq i32 %a, 57
  br i1 %cmp0, label %exit, label %do_call
do_call:
  call i32 @foo()
  br label %exit
exit:
  %v3 = load <4 x i32>, ptr %gep
  %v4 = add <4 x i32> %v3, splat (i32 1)
  store <4 x i32> %v4, ptr %gep
  ret void
}

; In this case, the second use is in a loop, so using a callee
; saved register to avoid a remat is the profitable choice.
; FIXME: We can shrink wrap the frame setup around the loop
; and avoid it along the %bb.0 -> %exit edge
define void @vecaddr_loop(i32 zeroext %a, ptr %p) {
; RV32-LABEL: vecaddr_loop:
; RV32:       # %bb.0:
; RV32-NEXT:    addi sp, sp, -16
; RV32-NEXT:    .cfi_def_cfa_offset 16
; RV32-NEXT:    sw ra, 12(sp) # 4-byte Folded Spill
; RV32-NEXT:    sw s0, 8(sp) # 4-byte Folded Spill
; RV32-NEXT:    .cfi_offset ra, -4
; RV32-NEXT:    .cfi_offset s0, -8
; RV32-NEXT:    addi s0, a1, 32
; RV32-NEXT:    vsetivli zero, 4, e32, m1, ta, ma
; RV32-NEXT:    vle32.v v8, (s0)
; RV32-NEXT:    vadd.vi v8, v8, 1
; RV32-NEXT:    li a1, 57
; RV32-NEXT:    vse32.v v8, (s0)
; RV32-NEXT:    beq a0, a1, .LBB1_2
; RV32-NEXT:  .LBB1_1: # %do_call
; RV32-NEXT:    # =>This Inner Loop Header: Depth=1
; RV32-NEXT:    call foo
; RV32-NEXT:    vsetivli zero, 4, e32, m1, ta, ma
; RV32-NEXT:    vle32.v v8, (s0)
; RV32-NEXT:    vadd.vi v8, v8, 1
; RV32-NEXT:    vse32.v v8, (s0)
; RV32-NEXT:    bnez a0, .LBB1_1
; RV32-NEXT:  .LBB1_2: # %exit
; RV32-NEXT:    lw ra, 12(sp) # 4-byte Folded Reload
; RV32-NEXT:    lw s0, 8(sp) # 4-byte Folded Reload
; RV32-NEXT:    .cfi_restore ra
; RV32-NEXT:    .cfi_restore s0
; RV32-NEXT:    addi sp, sp, 16
; RV32-NEXT:    .cfi_def_cfa_offset 0
; RV32-NEXT:    ret
;
; RV64-LABEL: vecaddr_loop:
; RV64:       # %bb.0:
; RV64-NEXT:    addi sp, sp, -16
; RV64-NEXT:    .cfi_def_cfa_offset 16
; RV64-NEXT:    sd ra, 8(sp) # 8-byte Folded Spill
; RV64-NEXT:    sd s0, 0(sp) # 8-byte Folded Spill
; RV64-NEXT:    .cfi_offset ra, -8
; RV64-NEXT:    .cfi_offset s0, -16
; RV64-NEXT:    addi s0, a1, 32
; RV64-NEXT:    vsetivli zero, 4, e32, m1, ta, ma
; RV64-NEXT:    vle32.v v8, (s0)
; RV64-NEXT:    vadd.vi v8, v8, 1
; RV64-NEXT:    li a1, 57
; RV64-NEXT:    vse32.v v8, (s0)
; RV64-NEXT:    beq a0, a1, .LBB1_2
; RV64-NEXT:  .LBB1_1: # %do_call
; RV64-NEXT:    # =>This Inner Loop Header: Depth=1
; RV64-NEXT:    call foo
; RV64-NEXT:    vsetivli zero, 4, e32, m1, ta, ma
; RV64-NEXT:    vle32.v v8, (s0)
; RV64-NEXT:    vadd.vi v8, v8, 1
; RV64-NEXT:    vse32.v v8, (s0)
; RV64-NEXT:    bnez a0, .LBB1_1
; RV64-NEXT:  .LBB1_2: # %exit
; RV64-NEXT:    ld ra, 8(sp) # 8-byte Folded Reload
; RV64-NEXT:    ld s0, 0(sp) # 8-byte Folded Reload
; RV64-NEXT:    .cfi_restore ra
; RV64-NEXT:    .cfi_restore s0
; RV64-NEXT:    addi sp, sp, 16
; RV64-NEXT:    .cfi_def_cfa_offset 0
; RV64-NEXT:    ret
  %gep = getelementptr i8, ptr %p, i32 32
  %v1 = load <4 x i32>, ptr %gep
  %v2 = add <4 x i32> %v1, splat (i32 1)
  store <4 x i32> %v2, ptr %gep
  %cmp0 = icmp eq i32 %a, 57
  br i1 %cmp0, label %exit, label %do_call
do_call:
  %b = call i32 @foo()
  %v3 = load <4 x i32>, ptr %gep
  %v4 = add <4 x i32> %v3, splat (i32 1)
  store <4 x i32> %v4, ptr %gep

  %cmp1 = icmp eq i32 %b, 0
  br i1 %cmp1, label %exit, label %do_call
exit:
  ret void
}

declare zeroext i32 @foo()