|
2 | 2 | ; RUN: llc -mtriple=riscv64 -mattr=+xandesperf -verify-machineinstrs < %s \ |
3 | 3 | ; RUN: | FileCheck %s |
4 | 4 |
|
| 5 | +; NDS.BFOZ |
| 6 | + |
| 7 | +; MSB >= LSB |
| 8 | + |
5 | 9 | define i32 @bfoz_from_and_i32(i32 %x) { |
6 | 10 | ; CHECK-LABEL: bfoz_from_and_i32: |
7 | 11 | ; CHECK: # %bb.0: |
@@ -60,6 +64,102 @@ define i64 @bfoz_from_lshr_and_i64(i64 %x) { |
60 | 64 | ret i64 %shifted |
61 | 65 | } |
62 | 66 |
|
| 67 | +; MSB = 0 |
| 68 | + |
| 69 | +define i32 @bfoz_from_and_shl_with_msb_zero_i32(i32 %x) { |
| 70 | +; CHECK-LABEL: bfoz_from_and_shl_with_msb_zero_i32: |
| 71 | +; CHECK: # %bb.0: |
| 72 | +; CHECK-NEXT: slli a0, a0, 63 |
| 73 | +; CHECK-NEXT: srli a0, a0, 48 |
| 74 | +; CHECK-NEXT: ret |
| 75 | + %shifted = shl i32 %x, 15 |
| 76 | + %masked = and i32 %shifted, 32768 |
| 77 | + ret i32 %masked |
| 78 | +} |
| 79 | + |
| 80 | +define i64 @bfoz_from_and_shl_with_msb_zero_i64(i64 %x) { |
| 81 | +; CHECK-LABEL: bfoz_from_and_shl_with_msb_zero_i64: |
| 82 | +; CHECK: # %bb.0: |
| 83 | +; CHECK-NEXT: slli a0, a0, 63 |
| 84 | +; CHECK-NEXT: srli a0, a0, 15 |
| 85 | +; CHECK-NEXT: ret |
| 86 | + %shifted = shl i64 %x, 48 |
| 87 | + %masked = and i64 %shifted, 281474976710656 |
| 88 | + ret i64 %masked |
| 89 | +} |
| 90 | + |
| 91 | +define i32 @bfoz_from_lshr_shl_with_msb_zero_i32(i32 %x) { |
| 92 | +; CHECK-LABEL: bfoz_from_lshr_shl_with_msb_zero_i32: |
| 93 | +; CHECK: # %bb.0: |
| 94 | +; CHECK-NEXT: slli a0, a0, 63 |
| 95 | +; CHECK-NEXT: srli a0, a0, 45 |
| 96 | +; CHECK-NEXT: ret |
| 97 | + %shl = shl i32 %x, 31 |
| 98 | + %lshr = lshr i32 %shl, 13 |
| 99 | + ret i32 %lshr |
| 100 | +} |
| 101 | + |
| 102 | +define i64 @bfoz_from_lshr_shl_with_msb_zero_i64(i64 %x) { |
| 103 | +; CHECK-LABEL: bfoz_from_lshr_shl_with_msb_zero_i64: |
| 104 | +; CHECK: # %bb.0: |
| 105 | +; CHECK-NEXT: slli a0, a0, 63 |
| 106 | +; CHECK-NEXT: srli a0, a0, 19 |
| 107 | +; CHECK-NEXT: ret |
| 108 | + %shl = shl i64 %x, 63 |
| 109 | + %lshr = lshr i64 %shl, 19 |
| 110 | + ret i64 %lshr |
| 111 | +} |
| 112 | + |
| 113 | +; MSB < LSB |
| 114 | + |
| 115 | +define i32 @bfoz_from_and_shl_i32(i32 %x) { |
| 116 | +; CHECK-LABEL: bfoz_from_and_shl_i32: |
| 117 | +; CHECK: # %bb.0: |
| 118 | +; CHECK-NEXT: slli a0, a0, 52 |
| 119 | +; CHECK-NEXT: srli a0, a0, 40 |
| 120 | +; CHECK-NEXT: ret |
| 121 | + %shifted = shl i32 %x, 12 |
| 122 | + %masked = and i32 %shifted, 16773120 |
| 123 | + ret i32 %masked |
| 124 | +} |
| 125 | + |
| 126 | +define i64 @bfoz_from_and_shl_i64(i64 %x) { |
| 127 | +; CHECK-LABEL: bfoz_from_and_shl_i64: |
| 128 | +; CHECK: # %bb.0: |
| 129 | +; CHECK-NEXT: slli a0, a0, 52 |
| 130 | +; CHECK-NEXT: srli a0, a0, 28 |
| 131 | +; CHECK-NEXT: ret |
| 132 | + %shifted = shl i64 %x, 24 |
| 133 | + %masked = and i64 %shifted, 68702699520 |
| 134 | + ret i64 %masked |
| 135 | +} |
| 136 | + |
| 137 | +define i32 @bfoz_from_lshr_shl_i32(i32 %x) { |
| 138 | +; CHECK-LABEL: bfoz_from_lshr_shl_i32: |
| 139 | +; CHECK: # %bb.0: |
| 140 | +; CHECK-NEXT: slli a0, a0, 58 |
| 141 | +; CHECK-NEXT: srli a0, a0, 39 |
| 142 | +; CHECK-NEXT: ret |
| 143 | + %shl = shl i32 %x, 26 |
| 144 | + %lshr = lshr i32 %shl, 7 |
| 145 | + ret i32 %lshr |
| 146 | +} |
| 147 | + |
| 148 | +define i64 @bfoz_from_lshr_shl_i64(i64 %x) { |
| 149 | +; CHECK-LABEL: bfoz_from_lshr_shl_i64: |
| 150 | +; CHECK: # %bb.0: |
| 151 | +; CHECK-NEXT: slli a0, a0, 40 |
| 152 | +; CHECK-NEXT: srli a0, a0, 15 |
| 153 | +; CHECK-NEXT: ret |
| 154 | + %shl = shl i64 %x, 40 |
| 155 | + %lshr = lshr i64 %shl, 15 |
| 156 | + ret i64 %lshr |
| 157 | +} |
| 158 | + |
| 159 | +; NDS.BFOS |
| 160 | + |
| 161 | +; MSB >= LSB |
| 162 | + |
63 | 163 | define i32 @bfos_from_ashr_shl_i32(i32 %x) { |
64 | 164 | ; CHECK-LABEL: bfos_from_ashr_shl_i32: |
65 | 165 | ; CHECK: # %bb.0: |
|
0 commit comments