Skip to content

Commit 7fb8630

Browse files
authored
[RISCV] Add another packh+packw pattern. (#152744)
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 92a966b commit 7fb8630

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,36 @@ define void @pack_lo_packh_hi_packh_3(i8 %0, i8 %1, i8 %2, i8 %3, ptr %p) nounwi
495495
ret void
496496
}
497497

498+
define i32 @pack_lo_packh_hi_packh_4(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3, ptr %p) nounwind {
499+
; RV64I-LABEL: pack_lo_packh_hi_packh_4:
500+
; RV64I: # %bb.0:
501+
; RV64I-NEXT: slli a1, a1, 8
502+
; RV64I-NEXT: slli a2, a2, 16
503+
; RV64I-NEXT: slliw a3, a3, 24
504+
; RV64I-NEXT: or a0, a0, a1
505+
; RV64I-NEXT: or a2, a2, a3
506+
; RV64I-NEXT: or a0, a0, a2
507+
; RV64I-NEXT: ret
508+
;
509+
; RV64ZBKB-LABEL: pack_lo_packh_hi_packh_4:
510+
; RV64ZBKB: # %bb.0:
511+
; RV64ZBKB-NEXT: packh a0, a0, a1
512+
; RV64ZBKB-NEXT: packh a1, a3, a2
513+
; RV64ZBKB-NEXT: packw a0, a0, a1
514+
; RV64ZBKB-NEXT: ret
515+
%a = zext i8 %0 to i32
516+
%b = zext i8 %1 to i32
517+
%c = zext i8 %2 to i32
518+
%d = zext i8 %3 to i32
519+
%e = shl i32 %b, 8
520+
%f = shl i32 %c, 16
521+
%g = shl i32 %d, 24
522+
%h = or i32 %a, %e
523+
%i = or i32 %h, %f
524+
%j = or i32 %i, %g
525+
ret i32 %j
526+
}
527+
498528
define void @pack_lo_zext_hi_packh(i16 zeroext %0, i8 zeroext %1, i8 zeroext %2, ptr %p) nounwind {
499529
; RV64I-LABEL: pack_lo_zext_hi_packh:
500530
; RV64I: # %bb.0:

0 commit comments

Comments
 (0)