Skip to content

Commit 0d8144c

Browse files
committed
[RISCV] Add another packh+packw pattern.
If the upper 32 bits are demanded, we might have a sext_inreg in the pattern on the byte shifted by 24. We can also match this case since packw sign extends from bit 31.
1 parent fb8f9d6 commit 0d8144c

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoZb.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,11 @@ def : Pat<(binop_allwusers<or>
692692
(shl GPR:$op1rs1, (XLenVT 24))),
693693
(shl (zexti8 (XLenVT GPR:$op1rs2)), (XLenVT 16))),
694694
(PACKW GPR:$rs1, (XLenVT (PACKH GPR:$op1rs1, GPR:$op1rs2)))>;
695+
696+
def : Pat<(i64 (or (or (zexti16 (XLenVT GPR:$rs1)),
697+
(shl (zexti8 (XLenVT GPR:$op1rs2)), (XLenVT 16))),
698+
(sext_inreg (shl GPR:$op1rs1, (XLenVT 24)), i32))),
699+
(PACKW GPR:$rs1, (XLenVT (PACKH GPR:$op1rs1, GPR:$op1rs2)))>;
695700
} // Predicates = [HasStdExtZbkb, IsRV64]
696701

697702
let Predicates = [HasStdExtZbb, IsRV32] in

llvm/test/CodeGen/RISCV/rv64zbkb.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,9 @@ define i32 @pack_lo_packh_hi_packh_4(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2
508508
;
509509
; RV64ZBKB-LABEL: pack_lo_packh_hi_packh_4:
510510
; RV64ZBKB: # %bb.0:
511-
; RV64ZBKB-NEXT: slli a2, a2, 16
512-
; RV64ZBKB-NEXT: slliw a3, a3, 24
513511
; RV64ZBKB-NEXT: packh a0, a0, a1
514-
; RV64ZBKB-NEXT: or a0, a0, a2
515-
; RV64ZBKB-NEXT: or a0, a0, a3
512+
; RV64ZBKB-NEXT: packh a1, a3, a2
513+
; RV64ZBKB-NEXT: packw a0, a0, a1
516514
; RV64ZBKB-NEXT: ret
517515
%a = zext i8 %0 to i32
518516
%b = zext i8 %1 to i32

0 commit comments

Comments
 (0)