1 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 3
2 # RUN: llc -mtriple=riscv32 -run-pass=legalizer %s -o - \
3 # RUN: | FileCheck %s --check-prefix=RV32I
4 # RUN: llc -mtriple=riscv32 -mattr=+zbb -run-pass=legalizer %s -o - \
5 # RUN: | FileCheck %s --check-prefix=RV32ZBB_OR_RV32ZBKB
6 # RUN: llc -mtriple=riscv32 -mattr=+zbkb -run-pass=legalizer %s -o - \
7 # RUN: | FileCheck %s --check-prefix=RV32ZBB_OR_RV32ZBKB
14 ; RV32I-LABEL: name: bswap_i16
15 ; RV32I: liveins: $x10
17 ; RV32I-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $x10
18 ; RV32I-NEXT: [[ASSERT_ZEXT:%[0-9]+]]:_(s32) = G_ASSERT_ZEXT [[COPY]], 16
19 ; RV32I-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 8
20 ; RV32I-NEXT: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[ASSERT_ZEXT]], [[C]](s32)
21 ; RV32I-NEXT: [[LSHR:%[0-9]+]]:_(s32) = G_LSHR [[ASSERT_ZEXT]], [[C]](s32)
22 ; RV32I-NEXT: [[OR:%[0-9]+]]:_(s32) = G_OR [[LSHR]], [[SHL]]
23 ; RV32I-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 65535
24 ; RV32I-NEXT: [[AND:%[0-9]+]]:_(s32) = G_AND [[OR]], [[C1]]
25 ; RV32I-NEXT: $x10 = COPY [[AND]](s32)
26 ; RV32I-NEXT: PseudoRET implicit $x10
28 ; RV32ZBB_OR_RV32ZBKB-LABEL: name: bswap_i16
29 ; RV32ZBB_OR_RV32ZBKB: liveins: $x10
30 ; RV32ZBB_OR_RV32ZBKB-NEXT: {{ $}}
31 ; RV32ZBB_OR_RV32ZBKB-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $x10
32 ; RV32ZBB_OR_RV32ZBKB-NEXT: [[ASSERT_ZEXT:%[0-9]+]]:_(s32) = G_ASSERT_ZEXT [[COPY]], 16
33 ; RV32ZBB_OR_RV32ZBKB-NEXT: [[BSWAP:%[0-9]+]]:_(s32) = G_BSWAP [[ASSERT_ZEXT]]
34 ; RV32ZBB_OR_RV32ZBKB-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 16
35 ; RV32ZBB_OR_RV32ZBKB-NEXT: [[LSHR:%[0-9]+]]:_(s32) = G_LSHR [[BSWAP]], [[C]](s32)
36 ; RV32ZBB_OR_RV32ZBKB-NEXT: $x10 = COPY [[LSHR]](s32)
37 ; RV32ZBB_OR_RV32ZBKB-NEXT: PseudoRET implicit $x10
39 %1:_(s32) = G_ASSERT_ZEXT %0, 16
40 %2:_(s16) = G_TRUNC %1(s32)
41 %3:_(s16) = G_BSWAP %2
42 %4:_(s32) = G_ZEXT %3(s16)
44 PseudoRET implicit $x10
51 ; RV32I-LABEL: name: bswap_i32
52 ; RV32I: liveins: $x10
54 ; RV32I-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $x10
55 ; RV32I-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 24
56 ; RV32I-NEXT: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[COPY]], [[C]](s32)
57 ; RV32I-NEXT: [[LSHR:%[0-9]+]]:_(s32) = G_LSHR [[COPY]], [[C]](s32)
58 ; RV32I-NEXT: [[OR:%[0-9]+]]:_(s32) = G_OR [[LSHR]], [[SHL]]
59 ; RV32I-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 65280
60 ; RV32I-NEXT: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 8
61 ; RV32I-NEXT: [[AND:%[0-9]+]]:_(s32) = G_AND [[COPY]], [[C1]]
62 ; RV32I-NEXT: [[SHL1:%[0-9]+]]:_(s32) = G_SHL [[AND]], [[C2]](s32)
63 ; RV32I-NEXT: [[OR1:%[0-9]+]]:_(s32) = G_OR [[OR]], [[SHL1]]
64 ; RV32I-NEXT: [[LSHR1:%[0-9]+]]:_(s32) = G_LSHR [[COPY]], [[C2]](s32)
65 ; RV32I-NEXT: [[AND1:%[0-9]+]]:_(s32) = G_AND [[LSHR1]], [[C1]]
66 ; RV32I-NEXT: [[OR2:%[0-9]+]]:_(s32) = G_OR [[OR1]], [[AND1]]
67 ; RV32I-NEXT: $x10 = COPY [[OR2]](s32)
68 ; RV32I-NEXT: PseudoRET implicit $x10
70 ; RV32ZBB_OR_RV32ZBKB-LABEL: name: bswap_i32
71 ; RV32ZBB_OR_RV32ZBKB: liveins: $x10
72 ; RV32ZBB_OR_RV32ZBKB-NEXT: {{ $}}
73 ; RV32ZBB_OR_RV32ZBKB-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $x10
74 ; RV32ZBB_OR_RV32ZBKB-NEXT: [[BSWAP:%[0-9]+]]:_(s32) = G_BSWAP [[COPY]]
75 ; RV32ZBB_OR_RV32ZBKB-NEXT: $x10 = COPY [[BSWAP]](s32)
76 ; RV32ZBB_OR_RV32ZBKB-NEXT: PseudoRET implicit $x10
78 %1:_(s32) = G_BSWAP %0
80 PseudoRET implicit $x10
87 ; RV32I-LABEL: name: bswap_i64
88 ; RV32I: liveins: $x10, $x11
90 ; RV32I-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $x10
91 ; RV32I-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $x11
92 ; RV32I-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 24
93 ; RV32I-NEXT: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[COPY1]], [[C]](s32)
94 ; RV32I-NEXT: [[LSHR:%[0-9]+]]:_(s32) = G_LSHR [[COPY1]], [[C]](s32)
95 ; RV32I-NEXT: [[OR:%[0-9]+]]:_(s32) = G_OR [[LSHR]], [[SHL]]
96 ; RV32I-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 65280
97 ; RV32I-NEXT: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 8
98 ; RV32I-NEXT: [[AND:%[0-9]+]]:_(s32) = G_AND [[COPY1]], [[C1]]
99 ; RV32I-NEXT: [[SHL1:%[0-9]+]]:_(s32) = G_SHL [[AND]], [[C2]](s32)
100 ; RV32I-NEXT: [[OR1:%[0-9]+]]:_(s32) = G_OR [[OR]], [[SHL1]]
101 ; RV32I-NEXT: [[LSHR1:%[0-9]+]]:_(s32) = G_LSHR [[COPY1]], [[C2]](s32)
102 ; RV32I-NEXT: [[AND1:%[0-9]+]]:_(s32) = G_AND [[LSHR1]], [[C1]]
103 ; RV32I-NEXT: [[OR2:%[0-9]+]]:_(s32) = G_OR [[OR1]], [[AND1]]
104 ; RV32I-NEXT: [[SHL2:%[0-9]+]]:_(s32) = G_SHL [[COPY]], [[C]](s32)
105 ; RV32I-NEXT: [[LSHR2:%[0-9]+]]:_(s32) = G_LSHR [[COPY]], [[C]](s32)
106 ; RV32I-NEXT: [[OR3:%[0-9]+]]:_(s32) = G_OR [[LSHR2]], [[SHL2]]
107 ; RV32I-NEXT: [[AND2:%[0-9]+]]:_(s32) = G_AND [[COPY]], [[C1]]
108 ; RV32I-NEXT: [[SHL3:%[0-9]+]]:_(s32) = G_SHL [[AND2]], [[C2]](s32)
109 ; RV32I-NEXT: [[OR4:%[0-9]+]]:_(s32) = G_OR [[OR3]], [[SHL3]]
110 ; RV32I-NEXT: [[LSHR3:%[0-9]+]]:_(s32) = G_LSHR [[COPY]], [[C2]](s32)
111 ; RV32I-NEXT: [[AND3:%[0-9]+]]:_(s32) = G_AND [[LSHR3]], [[C1]]
112 ; RV32I-NEXT: [[OR5:%[0-9]+]]:_(s32) = G_OR [[OR4]], [[AND3]]
113 ; RV32I-NEXT: $x10 = COPY [[OR2]](s32)
114 ; RV32I-NEXT: $x11 = COPY [[OR5]](s32)
115 ; RV32I-NEXT: PseudoRET implicit $x10, implicit $x11
117 ; RV32ZBB_OR_RV32ZBKB-LABEL: name: bswap_i64
118 ; RV32ZBB_OR_RV32ZBKB: liveins: $x10, $x11
119 ; RV32ZBB_OR_RV32ZBKB-NEXT: {{ $}}
120 ; RV32ZBB_OR_RV32ZBKB-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $x10
121 ; RV32ZBB_OR_RV32ZBKB-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $x11
122 ; RV32ZBB_OR_RV32ZBKB-NEXT: [[BSWAP:%[0-9]+]]:_(s32) = G_BSWAP [[COPY1]]
123 ; RV32ZBB_OR_RV32ZBKB-NEXT: [[BSWAP1:%[0-9]+]]:_(s32) = G_BSWAP [[COPY]]
124 ; RV32ZBB_OR_RV32ZBKB-NEXT: $x10 = COPY [[BSWAP]](s32)
125 ; RV32ZBB_OR_RV32ZBKB-NEXT: $x11 = COPY [[BSWAP1]](s32)
126 ; RV32ZBB_OR_RV32ZBKB-NEXT: PseudoRET implicit $x10, implicit $x11
127 %0:_(s32) = COPY $x10
128 %1:_(s32) = COPY $x11
129 %2:_(s64) = G_MERGE_VALUES %0(s32), %1(s32)
130 %3:_(s64) = G_BSWAP %2
131 %4:_(s32), %5:_(s32) = G_UNMERGE_VALUES %3(s64)
134 PseudoRET implicit $x10, implicit $x11