|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py |
| 2 | +; RUN: llc -mtriple=riscv32 -global-isel < %s \ |
| 3 | +; RUN: | FileCheck %s -check-prefix=RV32I |
| 4 | +; RUN: llc -mtriple=riscv64 -global-isel < %s \ |
| 5 | +; RUN: | FileCheck %s -check-prefix=RV64I |
| 6 | + |
| 7 | +; These test how the immediate in an addition is materialized. |
| 8 | + |
| 9 | +define i32 @add_positive_low_bound_reject(i32 %a) nounwind { |
| 10 | +; RV32I-LABEL: add_positive_low_bound_reject: |
| 11 | +; RV32I: # %bb.0: |
| 12 | +; RV32I-NEXT: addi a0, a0, 2047 |
| 13 | +; RV32I-NEXT: ret |
| 14 | +; |
| 15 | +; RV64I-LABEL: add_positive_low_bound_reject: |
| 16 | +; RV64I: # %bb.0: |
| 17 | +; RV64I-NEXT: addi a0, a0, 2047 |
| 18 | +; RV64I-NEXT: ret |
| 19 | + %1 = add i32 %a, 2047 |
| 20 | + ret i32 %1 |
| 21 | +} |
| 22 | + |
| 23 | +define i32 @add_positive_low_bound_accept(i32 %a) nounwind { |
| 24 | +; RV32I-LABEL: add_positive_low_bound_accept: |
| 25 | +; RV32I: # %bb.0: |
| 26 | +; RV32I-NEXT: li a1, 1 |
| 27 | +; RV32I-NEXT: slli a1, a1, 11 |
| 28 | +; RV32I-NEXT: add a0, a0, a1 |
| 29 | +; RV32I-NEXT: ret |
| 30 | +; |
| 31 | +; RV64I-LABEL: add_positive_low_bound_accept: |
| 32 | +; RV64I: # %bb.0: |
| 33 | +; RV64I-NEXT: li a1, 1 |
| 34 | +; RV64I-NEXT: slli a1, a1, 11 |
| 35 | +; RV64I-NEXT: add a0, a0, a1 |
| 36 | +; RV64I-NEXT: ret |
| 37 | + %1 = add i32 %a, 2048 |
| 38 | + ret i32 %1 |
| 39 | +} |
| 40 | + |
| 41 | +define i32 @add_positive_high_bound_accept(i32 %a) nounwind { |
| 42 | +; RV32I-LABEL: add_positive_high_bound_accept: |
| 43 | +; RV32I: # %bb.0: |
| 44 | +; RV32I-NEXT: lui a1, 1 |
| 45 | +; RV32I-NEXT: addi a1, a1, -2 |
| 46 | +; RV32I-NEXT: add a0, a0, a1 |
| 47 | +; RV32I-NEXT: ret |
| 48 | +; |
| 49 | +; RV64I-LABEL: add_positive_high_bound_accept: |
| 50 | +; RV64I: # %bb.0: |
| 51 | +; RV64I-NEXT: lui a1, 1 |
| 52 | +; RV64I-NEXT: addiw a1, a1, -2 |
| 53 | +; RV64I-NEXT: add a0, a0, a1 |
| 54 | +; RV64I-NEXT: ret |
| 55 | + %1 = add i32 %a, 4094 |
| 56 | + ret i32 %1 |
| 57 | +} |
| 58 | + |
| 59 | +define i32 @add_positive_high_bound_reject(i32 %a) nounwind { |
| 60 | +; RV32I-LABEL: add_positive_high_bound_reject: |
| 61 | +; RV32I: # %bb.0: |
| 62 | +; RV32I-NEXT: lui a1, 1 |
| 63 | +; RV32I-NEXT: addi a1, a1, -1 |
| 64 | +; RV32I-NEXT: add a0, a0, a1 |
| 65 | +; RV32I-NEXT: ret |
| 66 | +; |
| 67 | +; RV64I-LABEL: add_positive_high_bound_reject: |
| 68 | +; RV64I: # %bb.0: |
| 69 | +; RV64I-NEXT: lui a1, 1 |
| 70 | +; RV64I-NEXT: addiw a1, a1, -1 |
| 71 | +; RV64I-NEXT: add a0, a0, a1 |
| 72 | +; RV64I-NEXT: ret |
| 73 | + %1 = add i32 %a, 4095 |
| 74 | + ret i32 %1 |
| 75 | +} |
| 76 | + |
| 77 | +define i32 @add_negative_high_bound_reject(i32 %a) nounwind { |
| 78 | +; RV32I-LABEL: add_negative_high_bound_reject: |
| 79 | +; RV32I: # %bb.0: |
| 80 | +; RV32I-NEXT: addi a0, a0, -2048 |
| 81 | +; RV32I-NEXT: ret |
| 82 | +; |
| 83 | +; RV64I-LABEL: add_negative_high_bound_reject: |
| 84 | +; RV64I: # %bb.0: |
| 85 | +; RV64I-NEXT: addi a0, a0, -2048 |
| 86 | +; RV64I-NEXT: ret |
| 87 | + %1 = add i32 %a, -2048 |
| 88 | + ret i32 %1 |
| 89 | +} |
| 90 | + |
| 91 | +define i32 @add_negative_high_bound_accept(i32 %a) nounwind { |
| 92 | +; RV32I-LABEL: add_negative_high_bound_accept: |
| 93 | +; RV32I: # %bb.0: |
| 94 | +; RV32I-NEXT: lui a1, 1048575 |
| 95 | +; RV32I-NEXT: addi a1, a1, 2047 |
| 96 | +; RV32I-NEXT: add a0, a0, a1 |
| 97 | +; RV32I-NEXT: ret |
| 98 | +; |
| 99 | +; RV64I-LABEL: add_negative_high_bound_accept: |
| 100 | +; RV64I: # %bb.0: |
| 101 | +; RV64I-NEXT: lui a1, 1048575 |
| 102 | +; RV64I-NEXT: addiw a1, a1, 2047 |
| 103 | +; RV64I-NEXT: add a0, a0, a1 |
| 104 | +; RV64I-NEXT: ret |
| 105 | + %1 = add i32 %a, -2049 |
| 106 | + ret i32 %1 |
| 107 | +} |
| 108 | + |
| 109 | +define i32 @add_negative_low_bound_accept(i32 %a) nounwind { |
| 110 | +; RV32I-LABEL: add_negative_low_bound_accept: |
| 111 | +; RV32I: # %bb.0: |
| 112 | +; RV32I-NEXT: lui a1, 1048575 |
| 113 | +; RV32I-NEXT: add a0, a0, a1 |
| 114 | +; RV32I-NEXT: ret |
| 115 | +; |
| 116 | +; RV64I-LABEL: add_negative_low_bound_accept: |
| 117 | +; RV64I: # %bb.0: |
| 118 | +; RV64I-NEXT: lui a1, 1048575 |
| 119 | +; RV64I-NEXT: add a0, a0, a1 |
| 120 | +; RV64I-NEXT: ret |
| 121 | + %1 = add i32 %a, -4096 |
| 122 | + ret i32 %1 |
| 123 | +} |
| 124 | + |
| 125 | +define i32 @add_negative_low_bound_reject(i32 %a) nounwind { |
| 126 | +; RV32I-LABEL: add_negative_low_bound_reject: |
| 127 | +; RV32I: # %bb.0: |
| 128 | +; RV32I-NEXT: lui a1, 1048575 |
| 129 | +; RV32I-NEXT: addi a1, a1, -1 |
| 130 | +; RV32I-NEXT: add a0, a0, a1 |
| 131 | +; RV32I-NEXT: ret |
| 132 | +; |
| 133 | +; RV64I-LABEL: add_negative_low_bound_reject: |
| 134 | +; RV64I: # %bb.0: |
| 135 | +; RV64I-NEXT: lui a1, 1048575 |
| 136 | +; RV64I-NEXT: addiw a1, a1, -1 |
| 137 | +; RV64I-NEXT: add a0, a0, a1 |
| 138 | +; RV64I-NEXT: ret |
| 139 | + %1 = add i32 %a, -4097 |
| 140 | + ret i32 %1 |
| 141 | +} |
| 142 | + |
| 143 | +define i32 @add32_accept(i32 %a) nounwind { |
| 144 | +; RV32I-LABEL: add32_accept: |
| 145 | +; RV32I: # %bb.0: |
| 146 | +; RV32I-NEXT: lui a1, 1 |
| 147 | +; RV32I-NEXT: addi a1, a1, -1097 |
| 148 | +; RV32I-NEXT: add a0, a0, a1 |
| 149 | +; RV32I-NEXT: ret |
| 150 | +; |
| 151 | +; RV64I-LABEL: add32_accept: |
| 152 | +; RV64I: # %bb.0: |
| 153 | +; RV64I-NEXT: lui a1, 1 |
| 154 | +; RV64I-NEXT: addiw a1, a1, -1097 |
| 155 | +; RV64I-NEXT: add a0, a0, a1 |
| 156 | +; RV64I-NEXT: ret |
| 157 | + %1 = add i32 %a, 2999 |
| 158 | + ret i32 %1 |
| 159 | +} |
| 160 | + |
| 161 | +define signext i32 @add32_sext_accept(i32 signext %a) nounwind { |
| 162 | +; RV32I-LABEL: add32_sext_accept: |
| 163 | +; RV32I: # %bb.0: |
| 164 | +; RV32I-NEXT: lui a1, 1 |
| 165 | +; RV32I-NEXT: addi a1, a1, -1097 |
| 166 | +; RV32I-NEXT: add a0, a0, a1 |
| 167 | +; RV32I-NEXT: ret |
| 168 | +; |
| 169 | +; RV64I-LABEL: add32_sext_accept: |
| 170 | +; RV64I: # %bb.0: |
| 171 | +; RV64I-NEXT: lui a1, 1 |
| 172 | +; RV64I-NEXT: addi a1, a1, -1097 |
| 173 | +; RV64I-NEXT: addw a0, a0, a1 |
| 174 | +; RV64I-NEXT: ret |
| 175 | + %1 = add i32 %a, 2999 |
| 176 | + ret i32 %1 |
| 177 | +} |
| 178 | + |
| 179 | +@gv0 = global i32 0, align 4 |
| 180 | +define signext i32 @add32_sext_reject_on_rv64(i32 signext %a) nounwind { |
| 181 | +; RV32I-LABEL: add32_sext_reject_on_rv64: |
| 182 | +; RV32I: # %bb.0: |
| 183 | +; RV32I-NEXT: lui a1, 1 |
| 184 | +; RV32I-NEXT: addi a1, a1, -1096 |
| 185 | +; RV32I-NEXT: lui a2, %hi(gv0) |
| 186 | +; RV32I-NEXT: add a0, a0, a1 |
| 187 | +; RV32I-NEXT: sw a0, %lo(gv0)(a2) |
| 188 | +; RV32I-NEXT: ret |
| 189 | +; |
| 190 | +; RV64I-LABEL: add32_sext_reject_on_rv64: |
| 191 | +; RV64I: # %bb.0: |
| 192 | +; RV64I-NEXT: lui a1, 1 |
| 193 | +; RV64I-NEXT: addi a1, a1, -1096 |
| 194 | +; RV64I-NEXT: lui a2, %hi(gv0) |
| 195 | +; RV64I-NEXT: addw a0, a0, a1 |
| 196 | +; RV64I-NEXT: sw a0, %lo(gv0)(a2) |
| 197 | +; RV64I-NEXT: ret |
| 198 | + %b = add nsw i32 %a, 3000 |
| 199 | + store i32 %b, ptr @gv0, align 4 |
| 200 | + ret i32 %b |
| 201 | +} |
| 202 | + |
| 203 | +define i64 @add64_accept(i64 %a) nounwind { |
| 204 | +; RV32I-LABEL: add64_accept: |
| 205 | +; RV32I: # %bb.0: |
| 206 | +; RV32I-NEXT: lui a2, 1 |
| 207 | +; RV32I-NEXT: addi a2, a2, -1097 |
| 208 | +; RV32I-NEXT: add a0, a0, a2 |
| 209 | +; RV32I-NEXT: sltu a2, a0, a2 |
| 210 | +; RV32I-NEXT: add a1, a1, a2 |
| 211 | +; RV32I-NEXT: ret |
| 212 | +; |
| 213 | +; RV64I-LABEL: add64_accept: |
| 214 | +; RV64I: # %bb.0: |
| 215 | +; RV64I-NEXT: lui a1, 1 |
| 216 | +; RV64I-NEXT: addiw a1, a1, -1097 |
| 217 | +; RV64I-NEXT: add a0, a0, a1 |
| 218 | +; RV64I-NEXT: ret |
| 219 | + %1 = add i64 %a, 2999 |
| 220 | + ret i64 %1 |
| 221 | +} |
| 222 | + |
| 223 | +@ga = global i32 0, align 4 |
| 224 | +@gb = global i32 0, align 4 |
| 225 | +define void @add32_reject() nounwind { |
| 226 | +; RV32I-LABEL: add32_reject: |
| 227 | +; RV32I: # %bb.0: |
| 228 | +; RV32I-NEXT: lui a0, %hi(ga) |
| 229 | +; RV32I-NEXT: lui a1, %hi(gb) |
| 230 | +; RV32I-NEXT: lw a2, %lo(ga)(a0) |
| 231 | +; RV32I-NEXT: lw a3, %lo(gb)(a1) |
| 232 | +; RV32I-NEXT: lui a4, 1 |
| 233 | +; RV32I-NEXT: addi a4, a4, -1096 |
| 234 | +; RV32I-NEXT: add a2, a2, a4 |
| 235 | +; RV32I-NEXT: add a3, a3, a4 |
| 236 | +; RV32I-NEXT: sw a2, %lo(ga)(a0) |
| 237 | +; RV32I-NEXT: sw a3, %lo(gb)(a1) |
| 238 | +; RV32I-NEXT: ret |
| 239 | +; |
| 240 | +; RV64I-LABEL: add32_reject: |
| 241 | +; RV64I: # %bb.0: |
| 242 | +; RV64I-NEXT: lui a0, %hi(ga) |
| 243 | +; RV64I-NEXT: lui a1, %hi(gb) |
| 244 | +; RV64I-NEXT: lw a2, %lo(ga)(a0) |
| 245 | +; RV64I-NEXT: lw a3, %lo(gb)(a1) |
| 246 | +; RV64I-NEXT: lui a4, 1 |
| 247 | +; RV64I-NEXT: addi a4, a4, -1096 |
| 248 | +; RV64I-NEXT: add a2, a2, a4 |
| 249 | +; RV64I-NEXT: add a3, a3, a4 |
| 250 | +; RV64I-NEXT: sw a2, %lo(ga)(a0) |
| 251 | +; RV64I-NEXT: sw a3, %lo(gb)(a1) |
| 252 | +; RV64I-NEXT: ret |
| 253 | + %1 = load i32, ptr @ga, align 4 |
| 254 | + %2 = load i32, ptr @gb, align 4 |
| 255 | + %3 = add i32 %1, 3000 |
| 256 | + %4 = add i32 %2, 3000 |
| 257 | + store i32 %3, ptr @ga, align 4 |
| 258 | + store i32 %4, ptr @gb, align 4 |
| 259 | + ret void |
| 260 | +} |
0 commit comments