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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc --mtriple=loongarch32 < %s | FileCheck %s
;; Test generation of the bstrins.w instruction.
;; There are 8 patterns that can be matched to bstrins.w. See performORCombine
;; for details.
;; Pattern 1
;; R = or (and X, mask0), (and (shl Y, lsb), mask1)
;; =>
;; R = BSTRINS X, Y, msb, lsb
define i32 @pat1(i32 %a, i32 %b) nounwind {
; CHECK-LABEL: pat1:
; CHECK: # %bb.0:
; CHECK-NEXT: bstrins.w $a0, $a1, 19, 8
; CHECK-NEXT: ret
%and1 = and i32 %a, -1048321 ; 0xfff000ff
%shl = shl i32 %b, 8
%and2 = and i32 %shl, 1048320 ; 0x000fff00
%or = or i32 %and1, %and2
ret i32 %or
}
define i32 @pat1_swap(i32 %a, i32 %b) nounwind {
; CHECK-LABEL: pat1_swap:
; CHECK: # %bb.0:
; CHECK-NEXT: bstrins.w $a0, $a1, 19, 8
; CHECK-NEXT: ret
%and1 = and i32 %a, -1048321 ; 0xfff000ff
%shl = shl i32 %b, 8
%and2 = and i32 %shl, 1048320 ; 0x000fff00
%or = or i32 %and2, %and1
ret i32 %or
}
;; Pattern 2
;; R = or (and X, mask0), (shl (and Y, mask1), lsb)
;; =>
;; R = BSTRINS X, Y, msb, lsb
define i32 @pat2(i32 %a, i32 %b) nounwind {
; CHECK-LABEL: pat2:
; CHECK: # %bb.0:
; CHECK-NEXT: bstrins.w $a0, $a1, 19, 8
; CHECK-NEXT: ret
%and1 = and i32 %a, -1048321 ; 0xfff000ff
%and2 = and i32 %b, 4095 ; 0x00000fff
%shl = shl i32 %and2, 8
%or = or i32 %and1, %shl
ret i32 %or
}
define i32 @pat2_swap(i32 %a, i32 %b) nounwind {
; CHECK-LABEL: pat2_swap:
; CHECK: # %bb.0:
; CHECK-NEXT: bstrins.w $a0, $a1, 19, 8
; CHECK-NEXT: ret
%and1 = and i32 %a, -1048321 ; 0xfff000ff
%and2 = and i32 %b, 4095 ; 0x00000fff
%shl = shl i32 %and2, 8
%or = or i32 %shl, %and1
ret i32 %or
}
;; Pattern 3
;; R = or (and X, mask0), (and Y, mask1)
;; =>
;; R = BSTRINS X, (srl (and Y, mask1), lsb), msb, lsb
define i32 @pat3(i32 %a, i32 %b) nounwind {
; CHECK-LABEL: pat3:
; CHECK: # %bb.0:
; CHECK-NEXT: andi $a1, $a1, 288
; CHECK-NEXT: srli.w $a1, $a1, 4
; CHECK-NEXT: bstrins.w $a0, $a1, 11, 4
; CHECK-NEXT: ret
%and1 = and i32 %a, -4081 ; 0xfffff00f
%and2 = and i32 %b, 288 ; 0x00000120
%or = or i32 %and1, %and2
ret i32 %or
}
define i32 @pat3_swap(i32 %a, i32 %b) nounwind {
; CHECK-LABEL: pat3_swap:
; CHECK: # %bb.0:
; CHECK-NEXT: andi $a1, $a1, 288
; CHECK-NEXT: srli.w $a1, $a1, 4
; CHECK-NEXT: bstrins.w $a0, $a1, 11, 4
; CHECK-NEXT: ret
%and1 = and i32 %a, -4081 ; 0xfffff00f
%and2 = and i32 %b, 288 ; 0x00000120
%or = or i32 %and2, %and1
ret i32 %or
}
define i32 @pat3_positive_mask0(i32 %a, i32 %b) nounwind {
; CHECK-LABEL: pat3_positive_mask0:
; CHECK: # %bb.0:
; CHECK-NEXT: srli.w $a1, $a1, 28
; CHECK-NEXT: bstrins.w $a0, $a1, 31, 28
; CHECK-NEXT: ret
%and1 = and i32 %a, 268435455 ; 0x0fffffff
%and2 = and i32 %b, 4026531840 ; 0xf0000000
%or = or i32 %and1, %and2
ret i32 %or
}
;; Pattern 4
;; R = or (and X, mask), (shl Y, shamt)
;; =>
;; R = BSTRINS X, Y, 31, shamt
define i32 @pat4(i32 %a, i32 %b) nounwind {
; CHECK-LABEL: pat4:
; CHECK: # %bb.0:
; CHECK-NEXT: bstrins.w $a0, $a1, 31, 28
; CHECK-NEXT: ret
%and = and i32 %a, 268435455 ; 0x0fffffff
%shl = shl i32 %b, 28
%or = or i32 %and, %shl
ret i32 %or
}
define i32 @pat4_swap(i32 %a, i32 %b) nounwind {
; CHECK-LABEL: pat4_swap:
; CHECK: # %bb.0:
; CHECK-NEXT: bstrins.w $a0, $a1, 31, 28
; CHECK-NEXT: ret
%and = and i32 %a, 268435455 ; 0x0fffffff
%shl = shl i32 %b, 28
%or = or i32 %shl, %and
ret i32 %or
}
;; Pattern 5
;; R = or (and X, mask), const
;; =>
;; R = BSTRINS X, (const >> lsb), msb, lsb
define i32 @pat5(i32 %a) nounwind {
; CHECK-LABEL: pat5:
; CHECK: # %bb.0:
; CHECK-NEXT: lu12i.w $a1, 1
; CHECK-NEXT: ori $a1, $a1, 564
; CHECK-NEXT: bstrins.w $a0, $a1, 23, 8
; CHECK-NEXT: ret
%and = and i32 %a, 4278190335 ; 0xff0000ff
%or = or i32 %and, 1192960 ; 0x00123400
ret i32 %or
}
;; Pattern 6: a = b | ((c & mask) << shamt)
;; In this testcase b is 0x10000002, but in fact we do not require b being a
;; constant. As long as all positions in b to be overwritten by the incoming
;; bits are known to be zero, the pattern could be matched.
define i32 @pat6(i32 %c) nounwind {
; CHECK-LABEL: pat6:
; CHECK: # %bb.0:
; CHECK-NEXT: lu12i.w $a1, 65536
; CHECK-NEXT: ori $a1, $a1, 2
; CHECK-NEXT: bstrins.w $a1, $a0, 27, 4
; CHECK-NEXT: move $a0, $a1
; CHECK-NEXT: ret
%and = and i32 %c, 16777215 ; 0x00ffffff
%shl = shl i32 %and, 4
%or = or i32 %shl, 268435458 ; 0x10000002
ret i32 %or
}
;; Pattern 7: a = b | ((c << shamt) & shifted_mask)
;; Similar to pattern 6.
define i32 @pat7(i32 %c) nounwind {
; CHECK-LABEL: pat7:
; CHECK: # %bb.0:
; CHECK-NEXT: lu12i.w $a1, 65536
; CHECK-NEXT: ori $a1, $a1, 2
; CHECK-NEXT: bstrins.w $a1, $a0, 27, 4
; CHECK-NEXT: move $a0, $a1
; CHECK-NEXT: ret
%shl = shl i32 %c, 4
%and = and i32 %shl, 268435440 ; 0x0ffffff0
%or = or i32 %and, 268435458 ; 0x10000002
ret i32 %or
}
;; Pattern 8: a = b | (c & shifted_mask)
;; Similar to pattern 7 but without shift to c.
define i32 @pat8(i32 %c) nounwind {
; CHECK-LABEL: pat8:
; CHECK: # %bb.0:
; CHECK-NEXT: srli.w $a1, $a0, 4
; CHECK-NEXT: lu12i.w $a0, 65536
; CHECK-NEXT: ori $a0, $a0, 2
; CHECK-NEXT: bstrins.w $a0, $a1, 27, 4
; CHECK-NEXT: ret
%and = and i32 %c, 268435440 ; 0x0ffffff0
%or = or i32 %and, 268435458 ; 0x10000002
ret i32 %or
}
;; Test that bstrins.w is not generated because constant OR operand
;; doesn't fit into bits cleared by constant AND operand.
define i32 @no_bstrins_w(i32 %a) nounwind {
; CHECK-LABEL: no_bstrins_w:
; CHECK: # %bb.0:
; CHECK-NEXT: lu12i.w $a1, 291
; CHECK-NEXT: ori $a1, $a1, 1104
; CHECK-NEXT: or $a0, $a0, $a1
; CHECK-NEXT: lu12i.w $a1, -3805
; CHECK-NEXT: ori $a1, $a1, 1279
; CHECK-NEXT: and $a0, $a0, $a1
; CHECK-NEXT: ret
%and = and i32 %a, 4278190335 ; 0xff0000ff
%or = or i32 %and, 1193040 ; 0x00123450
ret i32 %or
}
|