1 ; This test is designed to run 4 times, once with function attribute +c,
2 ; once with function attribute -c for eq/ne in icmp
3 ; The optimization should appear only with +c, otherwise default isel should be
6 ; RUN: cat %s | sed 's/CMPCOND/eq/g' | sed 's/RESBRNORMAL/beq/g' | \
7 ; RUN: sed 's/RESBROPT/c.beqz/g' > %t.compress_eq
8 ; RUN: llc -mtriple=riscv32 -target-abi ilp32d -mattr=+c,+f,+d -filetype=obj \
9 ; RUN: -disable-block-placement < %t.compress_eq \
10 ; RUN: | llvm-objdump -d --triple=riscv32 --mattr=+c,+f,+d -M no-aliases - \
11 ; RUN: | FileCheck -check-prefix=RV32IFDC %t.compress_eq
13 ; RUN: cat %s | sed -e 's/CMPCOND/eq/g' | sed -e 's/RESBRNORMAL/beq/g'\
14 ; RUN: | sed -e 's/RESBROPT/c.beqz/g' > %t.nocompr_eq
15 ; RUN: llc -mtriple=riscv32 -target-abi ilp32d -mattr=-c,+f,+d -filetype=obj \
16 ; RUN: -disable-block-placement < %t.nocompr_eq \
17 ; RUN: | llvm-objdump -d --triple=riscv32 --mattr=-c,+f,+d -M no-aliases - \
18 ; RUN: | FileCheck -check-prefix=RV32IFD %t.nocompr_eq
20 ; RUN: cat %s | sed 's/CMPCOND/ne/g' | sed 's/RESBRNORMAL/bne/g' | \
21 ; RUN: sed 's/RESBROPT/c.bnez/g' > %t.compress_neq
22 ; RUN: llc -mtriple=riscv32 -target-abi ilp32d -mattr=+c,+f,+d -filetype=obj \
23 ; RUN: -disable-block-placement < %t.compress_neq \
24 ; RUN: | llvm-objdump -d --triple=riscv32 --mattr=+c,+f,+d -M no-aliases - \
25 ; RUN: | FileCheck -check-prefix=RV32IFDC %t.compress_neq
27 ; RUN: cat %s | sed -e 's/CMPCOND/ne/g' | sed -e 's/RESBRNORMAL/bne/g'\
28 ; RUN: | sed -e 's/RESBROPT/c.bnez/g' > %t.nocompr_neq
29 ; RUN: llc -mtriple=riscv32 -target-abi ilp32d -mattr=-c,+f,+d -filetype=obj \
30 ; RUN: -disable-block-placement < %t.nocompr_neq \
31 ; RUN: | llvm-objdump -d --triple=riscv32 --mattr=-c,+f,+d -M no-aliases - \
32 ; RUN: | FileCheck -check-prefix=RV32IFD %t.nocompr_neq
35 ; constant is small and fit in 6 bit (compress imm)
36 ; RV32IFDC-LABEL: <f_small_pos>:
37 ; RV32IFDC: c.li [[REG:.*]], 0x14
38 ; RV32IFDC: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]]
39 ; --- no compress extension
40 ; RV32IFD-LABEL: <f_small_pos>:
41 ; RV32IFD: addi [[REG:.*]], zero, 0x14
42 ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]]
43 define i32 @f_small_pos(i32 %in0) minsize {
44 %cmp = icmp CMPCOND i32 %in0, 20
45 %toRet = select i1 %cmp, i32 -99, i32 42
49 ; constant is small and fit in 6 bit (compress imm)
50 ; RV32IFDC-LABEL: <f_small_neg>:
51 ; RV32IFDC: c.li [[REG:.*]], -0x14
52 ; RV32IFDC: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]]
53 ; --- no compress extension
54 ; RV32IFD-LABEL: <f_small_neg>:
55 ; RV32IFD: addi [[REG:.*]], zero, -0x14
56 ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]]
57 define i32 @f_small_neg(i32 %in0) minsize {
58 %cmp = icmp CMPCOND i32 %in0, -20
59 %toRet = select i1 %cmp, i32 -99, i32 42
63 ; constant is small and fit in 6 bit (compress imm)
64 ; RV32IFDC-LABEL: <f_small_edge_pos>:
65 ; RV32IFDC: c.li [[REG:.*]], 0x1f
66 ; RV32IFDC: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]]
67 ; --- no compress extension
68 ; RV32IFD-LABEL: <f_small_edge_pos>:
69 ; RV32IFD: addi [[REG:.*]], zero, 0x1f
70 ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]]
71 define i32 @f_small_edge_pos(i32 %in0) minsize {
72 %cmp = icmp CMPCOND i32 %in0, 31
73 %toRet = select i1 %cmp, i32 -99, i32 42
77 ; constant is small and fit in 6 bit (compress imm)
78 ; RV32IFDC-LABEL: <f_small_edge_neg>:
79 ; RV32IFDC: c.li [[REG:.*]], -0x20
80 ; RV32IFDC: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]]
81 ; --- no compress extension
82 ; RV32IFD-LABEL: <f_small_edge_neg>:
83 ; RV32IFD: addi [[REG:.*]], zero, -0x20
84 ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]]
85 define i32 @f_small_edge_neg(i32 %in0) minsize {
86 %cmp = icmp CMPCOND i32 %in0, -32
87 %toRet = select i1 %cmp, i32 -99, i32 42
91 ; constant is medium and not fit in 6 bit (compress imm),
92 ; but fit in 12 bit (imm)
93 ; RV32IFDC-LABEL: <f_medium_ledge_pos>:
94 ; RV32IFDC: addi [[MAYZEROREG:.*]], [[REG:.*]], -0x20
95 ; RV32IFDC: RESBROPT [[MAYZEROREG]], [[PLACE:.*]]
96 ; --- no compress extension
97 ; RV32IFD-LABEL: <f_medium_ledge_pos>:
98 ; RV32IFD: addi [[REG:.*]], zero, 0x20
99 ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]]
100 define i32 @f_medium_ledge_pos(i32 %in0) minsize {
101 %cmp = icmp CMPCOND i32 %in0, 32
102 %toRet = select i1 %cmp, i32 -99, i32 42
106 ; constant is medium and not fit in 6 bit (compress imm),
107 ; but fit in 12 bit (imm)
108 ; RV32IFDC-LABEL: <f_medium_ledge_neg>:
109 ; RV32IFDC: addi [[MAYZEROREG:.*]], [[REG:.*]], 0x21
110 ; RV32IFDC: RESBROPT [[MAYZEROREG]], [[PLACE:.*]]
111 ; --- no compress extension
112 ; RV32IFD-LABEL: <f_medium_ledge_neg>:
113 ; RV32IFD: addi [[REG:.*]], zero, -0x21
114 ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]]
115 define i32 @f_medium_ledge_neg(i32 %in0) minsize {
116 %cmp = icmp CMPCOND i32 %in0, -33
117 %toRet = select i1 %cmp, i32 -99, i32 42
121 ; constant is medium and not fit in 6 bit (compress imm),
122 ; but fit in 12 bit (imm)
123 ; RV32IFDC-LABEL: <f_medium_pos>:
124 ; RV32IFDC: addi [[MAYZEROREG:.*]], [[REG:.*]], -0x3f
125 ; RV32IFDC: RESBROPT [[MAYZEROREG]], [[PLACE:.*]]
126 ; --- no compress extension
127 ; RV32IFD-LABEL: <f_medium_pos>:
128 ; RV32IFD: addi [[REG:.*]], zero, 0x3f
129 ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]]
130 define i32 @f_medium_pos(i32 %in0) minsize {
131 %cmp = icmp CMPCOND i32 %in0, 63
132 %toRet = select i1 %cmp, i32 -99, i32 42
136 ; constant is medium and not fit in 6 bit (compress imm),
137 ; but fit in 12 bit (imm)
138 ; RV32IFDC-LABEL: <f_medium_neg>:
139 ; RV32IFDC: addi [[MAYZEROREG:.*]], [[REG:.*]], 0x3f
140 ; RV32IFDC: RESBROPT [[MAYZEROREG]], [[PLACE:.*]]
141 ; --- no compress extension
142 ; RV32IFD-LABEL: <f_medium_neg>:
143 ; RV32IFD: addi [[REG:.*]], zero, -0x3f
144 ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]]
145 define i32 @f_medium_neg(i32 %in0) minsize {
146 %cmp = icmp CMPCOND i32 %in0, -63
147 %toRet = select i1 %cmp, i32 -99, i32 42
151 ; constant is medium and not fit in 6 bit (compress imm),
152 ; but fit in 12 bit (imm)
153 ; RV32IFDC-LABEL: <f_medium_bedge_pos>:
154 ; RV32IFDC: addi [[MAYZEROREG:.*]], [[REG:.*]], -0x7ff
155 ; RV32IFDC: RESBROPT [[MAYZEROREG]], [[PLACE:.*]]
156 ; --- no compress extension
157 ; RV32IFD-LABEL: <f_medium_bedge_pos>:
158 ; RV32IFD: addi [[REG:.*]], zero, 0x7ff
159 ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]]
160 define i32 @f_medium_bedge_pos(i32 %in0) minsize {
161 %cmp = icmp CMPCOND i32 %in0, 2047
162 %toRet = select i1 %cmp, i32 -99, i32 42
166 ; constant is medium and not fit in 6 bit (compress imm),
167 ; but fit in 12 bit (imm), negative value fit in 12 bit too.
168 ; RV32IFDC-LABEL: <f_medium_bedge_neg>:
169 ; RV32IFDC: addi [[MAYZEROREG:.*]], [[REG:.*]], 0x7ff
170 ; RV32IFDC: RESBROPT [[MAYZEROREG]], [[PLACE:.*]]
171 ; --- no compress extension
172 ; RV32IFD-LABEL: <f_medium_bedge_neg>:
173 ; RV32IFD: addi [[REG:.*]], zero, -0x7ff
174 ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]]
175 define i32 @f_medium_bedge_neg(i32 %in0) minsize {
176 %cmp = icmp CMPCOND i32 %in0, -2047
177 %toRet = select i1 %cmp, i32 -99, i32 42
181 ; constant is big and do not fit in 12 bit (imm), fit in i32
182 ; RV32IFDC-LABEL: <f_big_ledge_pos>:
183 ; RV32IFDC-NOT: RESBROPT
184 ; --- no compress extension
186 define i32 @f_big_ledge_pos(i32 %in0) minsize {
187 %cmp = icmp CMPCOND i32 %in0, 2048
188 %toRet = select i1 %cmp, i32 -99, i32 42
192 ; constant is big and do not fit in 12 bit (imm), fit in i32
193 ; RV32IFDC-LABEL: <f_big_ledge_neg>:
194 ; RV32IFDC-NOT: c.beqz
195 ; --- no compress extension
197 define i32 @f_big_ledge_neg(i32 %in0) minsize {
198 %cmp = icmp CMPCOND i32 %in0, -2048
199 %toRet = select i1 %cmp, i32 -99, i32 42