Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py |
| 2 | ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \ |
| 3 | ; RUN: | FileCheck %s -check-prefix=RV32I |
| 4 | |
| 5 | ; Check indexed and unindexed, sext, zext and anyext loads |
| 6 | |
| 7 | define i32 @lb(i8 *%a) nounwind { |
| 8 | ; RV32I-LABEL: lb: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 9 | ; RV32I: # %bb.0: |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 10 | ; RV32I-NEXT: addi sp, sp, -16 |
| 11 | ; RV32I-NEXT: sw ra, 12(sp) |
| 12 | ; RV32I-NEXT: sw s0, 8(sp) |
| 13 | ; RV32I-NEXT: addi s0, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 14 | ; RV32I-NEXT: lb a1, 0(a0) |
| 15 | ; RV32I-NEXT: lb a0, 1(a0) |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 16 | ; RV32I-NEXT: lw s0, 8(sp) |
| 17 | ; RV32I-NEXT: lw ra, 12(sp) |
| 18 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 19 | ; RV32I-NEXT: jalr zero, ra, 0 |
| 20 | %1 = getelementptr i8, i8* %a, i32 1 |
| 21 | %2 = load i8, i8* %1 |
| 22 | %3 = sext i8 %2 to i32 |
| 23 | ; the unused load will produce an anyext for selection |
| 24 | %4 = load volatile i8, i8* %a |
| 25 | ret i32 %3 |
| 26 | } |
| 27 | |
| 28 | define i32 @lh(i16 *%a) nounwind { |
| 29 | ; RV32I-LABEL: lh: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 30 | ; RV32I: # %bb.0: |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 31 | ; RV32I-NEXT: addi sp, sp, -16 |
| 32 | ; RV32I-NEXT: sw ra, 12(sp) |
| 33 | ; RV32I-NEXT: sw s0, 8(sp) |
| 34 | ; RV32I-NEXT: addi s0, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 35 | ; RV32I-NEXT: lh a1, 0(a0) |
| 36 | ; RV32I-NEXT: lh a0, 4(a0) |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 37 | ; RV32I-NEXT: lw s0, 8(sp) |
| 38 | ; RV32I-NEXT: lw ra, 12(sp) |
| 39 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 40 | ; RV32I-NEXT: jalr zero, ra, 0 |
| 41 | %1 = getelementptr i16, i16* %a, i32 2 |
| 42 | %2 = load i16, i16* %1 |
| 43 | %3 = sext i16 %2 to i32 |
| 44 | ; the unused load will produce an anyext for selection |
| 45 | %4 = load volatile i16, i16* %a |
| 46 | ret i32 %3 |
| 47 | } |
| 48 | |
| 49 | define i32 @lw(i32 *%a) nounwind { |
| 50 | ; RV32I-LABEL: lw: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 51 | ; RV32I: # %bb.0: |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 52 | ; RV32I-NEXT: addi sp, sp, -16 |
| 53 | ; RV32I-NEXT: sw ra, 12(sp) |
| 54 | ; RV32I-NEXT: sw s0, 8(sp) |
| 55 | ; RV32I-NEXT: addi s0, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 56 | ; RV32I-NEXT: lw a1, 0(a0) |
| 57 | ; RV32I-NEXT: lw a0, 12(a0) |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 58 | ; RV32I-NEXT: lw s0, 8(sp) |
| 59 | ; RV32I-NEXT: lw ra, 12(sp) |
| 60 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 61 | ; RV32I-NEXT: jalr zero, ra, 0 |
| 62 | %1 = getelementptr i32, i32* %a, i32 3 |
| 63 | %2 = load i32, i32* %1 |
| 64 | %3 = load volatile i32, i32* %a |
| 65 | ret i32 %2 |
| 66 | } |
| 67 | |
| 68 | define i32 @lbu(i8 *%a) nounwind { |
| 69 | ; RV32I-LABEL: lbu: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 70 | ; RV32I: # %bb.0: |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 71 | ; RV32I-NEXT: addi sp, sp, -16 |
| 72 | ; RV32I-NEXT: sw ra, 12(sp) |
| 73 | ; RV32I-NEXT: sw s0, 8(sp) |
| 74 | ; RV32I-NEXT: addi s0, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 75 | ; RV32I-NEXT: lbu a1, 0(a0) |
| 76 | ; RV32I-NEXT: lbu a0, 4(a0) |
| 77 | ; RV32I-NEXT: add a0, a0, a1 |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 78 | ; RV32I-NEXT: lw s0, 8(sp) |
| 79 | ; RV32I-NEXT: lw ra, 12(sp) |
| 80 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 81 | ; RV32I-NEXT: jalr zero, ra, 0 |
| 82 | %1 = getelementptr i8, i8* %a, i32 4 |
| 83 | %2 = load i8, i8* %1 |
| 84 | %3 = zext i8 %2 to i32 |
| 85 | %4 = load volatile i8, i8* %a |
| 86 | %5 = zext i8 %4 to i32 |
| 87 | %6 = add i32 %3, %5 |
| 88 | ret i32 %6 |
| 89 | } |
| 90 | |
| 91 | define i32 @lhu(i16 *%a) nounwind { |
| 92 | ; RV32I-LABEL: lhu: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 93 | ; RV32I: # %bb.0: |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 94 | ; RV32I-NEXT: addi sp, sp, -16 |
| 95 | ; RV32I-NEXT: sw ra, 12(sp) |
| 96 | ; RV32I-NEXT: sw s0, 8(sp) |
| 97 | ; RV32I-NEXT: addi s0, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 98 | ; RV32I-NEXT: lhu a1, 0(a0) |
| 99 | ; RV32I-NEXT: lhu a0, 10(a0) |
| 100 | ; RV32I-NEXT: add a0, a0, a1 |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 101 | ; RV32I-NEXT: lw s0, 8(sp) |
| 102 | ; RV32I-NEXT: lw ra, 12(sp) |
| 103 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 104 | ; RV32I-NEXT: jalr zero, ra, 0 |
| 105 | %1 = getelementptr i16, i16* %a, i32 5 |
| 106 | %2 = load i16, i16* %1 |
| 107 | %3 = zext i16 %2 to i32 |
| 108 | %4 = load volatile i16, i16* %a |
| 109 | %5 = zext i16 %4 to i32 |
| 110 | %6 = add i32 %3, %5 |
| 111 | ret i32 %6 |
| 112 | } |
| 113 | |
| 114 | ; Check indexed and unindexed stores |
| 115 | |
| 116 | define void @sb(i8 *%a, i8 %b) nounwind { |
| 117 | ; RV32I-LABEL: sb: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 118 | ; RV32I: # %bb.0: |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 119 | ; RV32I-NEXT: addi sp, sp, -16 |
| 120 | ; RV32I-NEXT: sw ra, 12(sp) |
| 121 | ; RV32I-NEXT: sw s0, 8(sp) |
| 122 | ; RV32I-NEXT: addi s0, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 123 | ; RV32I-NEXT: sb a1, 6(a0) |
| 124 | ; RV32I-NEXT: sb a1, 0(a0) |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 125 | ; RV32I-NEXT: lw s0, 8(sp) |
| 126 | ; RV32I-NEXT: lw ra, 12(sp) |
| 127 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 128 | ; RV32I-NEXT: jalr zero, ra, 0 |
| 129 | store i8 %b, i8* %a |
| 130 | %1 = getelementptr i8, i8* %a, i32 6 |
| 131 | store i8 %b, i8* %1 |
| 132 | ret void |
| 133 | } |
| 134 | |
| 135 | define void @sh(i16 *%a, i16 %b) nounwind { |
| 136 | ; RV32I-LABEL: sh: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 137 | ; RV32I: # %bb.0: |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 138 | ; RV32I-NEXT: addi sp, sp, -16 |
| 139 | ; RV32I-NEXT: sw ra, 12(sp) |
| 140 | ; RV32I-NEXT: sw s0, 8(sp) |
| 141 | ; RV32I-NEXT: addi s0, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 142 | ; RV32I-NEXT: sh a1, 14(a0) |
| 143 | ; RV32I-NEXT: sh a1, 0(a0) |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 144 | ; RV32I-NEXT: lw s0, 8(sp) |
| 145 | ; RV32I-NEXT: lw ra, 12(sp) |
| 146 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 147 | ; RV32I-NEXT: jalr zero, ra, 0 |
| 148 | store i16 %b, i16* %a |
| 149 | %1 = getelementptr i16, i16* %a, i32 7 |
| 150 | store i16 %b, i16* %1 |
| 151 | ret void |
| 152 | } |
| 153 | |
| 154 | define void @sw(i32 *%a, i32 %b) nounwind { |
| 155 | ; RV32I-LABEL: sw: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 156 | ; RV32I: # %bb.0: |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 157 | ; RV32I-NEXT: addi sp, sp, -16 |
| 158 | ; RV32I-NEXT: sw ra, 12(sp) |
| 159 | ; RV32I-NEXT: sw s0, 8(sp) |
| 160 | ; RV32I-NEXT: addi s0, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 161 | ; RV32I-NEXT: sw a1, 32(a0) |
| 162 | ; RV32I-NEXT: sw a1, 0(a0) |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 163 | ; RV32I-NEXT: lw s0, 8(sp) |
| 164 | ; RV32I-NEXT: lw ra, 12(sp) |
| 165 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 166 | ; RV32I-NEXT: jalr zero, ra, 0 |
| 167 | store i32 %b, i32* %a |
| 168 | %1 = getelementptr i32, i32* %a, i32 8 |
| 169 | store i32 %b, i32* %1 |
| 170 | ret void |
| 171 | } |
| 172 | |
| 173 | ; Check load and store to an i1 location |
| 174 | define i32 @load_sext_zext_anyext_i1(i1 *%a) nounwind { |
| 175 | ; RV32I-LABEL: load_sext_zext_anyext_i1: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 176 | ; RV32I: # %bb.0: |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 177 | ; RV32I-NEXT: addi sp, sp, -16 |
| 178 | ; RV32I-NEXT: sw ra, 12(sp) |
| 179 | ; RV32I-NEXT: sw s0, 8(sp) |
| 180 | ; RV32I-NEXT: addi s0, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 181 | ; RV32I-NEXT: lb a1, 0(a0) |
| 182 | ; RV32I-NEXT: lbu a1, 1(a0) |
| 183 | ; RV32I-NEXT: lbu a0, 2(a0) |
| 184 | ; RV32I-NEXT: sub a0, a0, a1 |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 185 | ; RV32I-NEXT: lw s0, 8(sp) |
| 186 | ; RV32I-NEXT: lw ra, 12(sp) |
| 187 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 188 | ; RV32I-NEXT: jalr zero, ra, 0 |
| 189 | ; sextload i1 |
| 190 | %1 = getelementptr i1, i1* %a, i32 1 |
| 191 | %2 = load i1, i1* %1 |
| 192 | %3 = sext i1 %2 to i32 |
| 193 | ; zextload i1 |
| 194 | %4 = getelementptr i1, i1* %a, i32 2 |
| 195 | %5 = load i1, i1* %4 |
| 196 | %6 = zext i1 %5 to i32 |
| 197 | %7 = add i32 %3, %6 |
| 198 | ; extload i1 (anyext). Produced as the load is unused. |
| 199 | %8 = load volatile i1, i1* %a |
| 200 | ret i32 %7 |
| 201 | } |
| 202 | |
| 203 | define i16 @load_sext_zext_anyext_i1_i16(i1 *%a) nounwind { |
| 204 | ; RV32I-LABEL: load_sext_zext_anyext_i1_i16: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 205 | ; RV32I: # %bb.0: |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 206 | ; RV32I-NEXT: addi sp, sp, -16 |
| 207 | ; RV32I-NEXT: sw ra, 12(sp) |
| 208 | ; RV32I-NEXT: sw s0, 8(sp) |
| 209 | ; RV32I-NEXT: addi s0, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 210 | ; RV32I-NEXT: lb a1, 0(a0) |
| 211 | ; RV32I-NEXT: lbu a1, 1(a0) |
| 212 | ; RV32I-NEXT: lbu a0, 2(a0) |
| 213 | ; RV32I-NEXT: sub a0, a0, a1 |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 214 | ; RV32I-NEXT: lw s0, 8(sp) |
| 215 | ; RV32I-NEXT: lw ra, 12(sp) |
| 216 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 217 | ; RV32I-NEXT: jalr zero, ra, 0 |
| 218 | ; sextload i1 |
| 219 | %1 = getelementptr i1, i1* %a, i32 1 |
| 220 | %2 = load i1, i1* %1 |
| 221 | %3 = sext i1 %2 to i16 |
| 222 | ; zextload i1 |
| 223 | %4 = getelementptr i1, i1* %a, i32 2 |
| 224 | %5 = load i1, i1* %4 |
| 225 | %6 = zext i1 %5 to i16 |
| 226 | %7 = add i16 %3, %6 |
| 227 | ; extload i1 (anyext). Produced as the load is unused. |
| 228 | %8 = load volatile i1, i1* %a |
| 229 | ret i16 %7 |
| 230 | } |
| 231 | |
Alex Bradbury | ec8aa91 | 2017-11-08 13:24:21 +0000 | [diff] [blame] | 232 | ; Check load and store to a global |
| 233 | @G = global i32 0 |
| 234 | |
| 235 | define i32 @lw_sw_global(i32 %a) nounwind { |
| 236 | ; TODO: the addi should be folded in to the lw/sw operations |
| 237 | ; RV32I-LABEL: lw_sw_global: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 238 | ; RV32I: # %bb.0: |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 239 | ; RV32I-NEXT: addi sp, sp, -16 |
| 240 | ; RV32I-NEXT: sw ra, 12(sp) |
| 241 | ; RV32I-NEXT: sw s0, 8(sp) |
| 242 | ; RV32I-NEXT: addi s0, sp, 16 |
Alex Bradbury | ec8aa91 | 2017-11-08 13:24:21 +0000 | [diff] [blame] | 243 | ; RV32I-NEXT: lui a1, %hi(G) |
| 244 | ; RV32I-NEXT: addi a2, a1, %lo(G) |
| 245 | ; RV32I-NEXT: lw a1, 0(a2) |
| 246 | ; RV32I-NEXT: sw a0, 0(a2) |
| 247 | ; RV32I-NEXT: lui a2, %hi(G+36) |
| 248 | ; RV32I-NEXT: addi a2, a2, %lo(G+36) |
| 249 | ; RV32I-NEXT: lw a3, 0(a2) |
| 250 | ; RV32I-NEXT: sw a0, 0(a2) |
| 251 | ; RV32I-NEXT: addi a0, a1, 0 |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 252 | ; RV32I-NEXT: lw s0, 8(sp) |
| 253 | ; RV32I-NEXT: lw ra, 12(sp) |
| 254 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | ec8aa91 | 2017-11-08 13:24:21 +0000 | [diff] [blame] | 255 | ; RV32I-NEXT: jalr zero, ra, 0 |
| 256 | %1 = load volatile i32, i32* @G |
| 257 | store i32 %a, i32* @G |
| 258 | %2 = getelementptr i32, i32* @G, i32 9 |
| 259 | %3 = load volatile i32, i32* %2 |
| 260 | store i32 %a, i32* %2 |
| 261 | ret i32 %1 |
| 262 | } |
| 263 | |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 264 | ; Ensure that 1 is added to the high 20 bits if bit 11 of the low part is 1 |
| 265 | define i32 @lw_sw_constant(i32 %a) nounwind { |
| 266 | ; TODO: the addi should be folded in to the lw/sw |
| 267 | ; RV32I-LABEL: lw_sw_constant: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 268 | ; RV32I: # %bb.0: |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 269 | ; RV32I-NEXT: addi sp, sp, -16 |
| 270 | ; RV32I-NEXT: sw ra, 12(sp) |
| 271 | ; RV32I-NEXT: sw s0, 8(sp) |
| 272 | ; RV32I-NEXT: addi s0, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 273 | ; RV32I-NEXT: lui a1, 912092 |
| 274 | ; RV32I-NEXT: addi a2, a1, -273 |
| 275 | ; RV32I-NEXT: lw a1, 0(a2) |
| 276 | ; RV32I-NEXT: sw a0, 0(a2) |
| 277 | ; RV32I-NEXT: addi a0, a1, 0 |
Alex Bradbury | b014e3d | 2017-12-11 12:34:11 +0000 | [diff] [blame] | 278 | ; RV32I-NEXT: lw s0, 8(sp) |
| 279 | ; RV32I-NEXT: lw ra, 12(sp) |
| 280 | ; RV32I-NEXT: addi sp, sp, 16 |
Alex Bradbury | cfa6291 | 2017-11-08 12:20:01 +0000 | [diff] [blame] | 281 | ; RV32I-NEXT: jalr zero, ra, 0 |
| 282 | %1 = inttoptr i32 3735928559 to i32* |
| 283 | %2 = load volatile i32, i32* %1 |
| 284 | store i32 %a, i32* %1 |
| 285 | ret i32 %2 |
| 286 | } |