From 53c29531ff81e428cfe88a70f6612ee21baf5ccc Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Mon, 4 Aug 2025 15:04:09 -0700 Subject: [PATCH] [RISCV] Simplify one of the RV32 PACK isel patterns. This pattern previously checked a specific variant of 4 bytes being packed that is generated by unaligned load expansion. Our simplest PACK patterns misses this case because we don't have a single shift left by 16. We have two shift lefts hidden behind another OR. We only need the pattern to find the 2 shifts in the upper part, for the lower part we only care that the upper 16 bits are zero. If the lower bits can also be a PACKH that can be selected separately after. I believe this allows tablegen to create more patterns for permutations of this pattern. The associative and commutative variant expansion is limited to 3 children. --- llvm/lib/Target/RISCV/RISCVInstrInfoZb.td | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td index d2a651444169c..94fb23d554f1a 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td @@ -641,13 +641,13 @@ def : Pat<(binop_allhusers (shl GPR:$rs2, (XLenVT 8)), let Predicates = [HasStdExtZbkb, IsRV32] in { def : Pat<(i32 (or (zexti16 (i32 GPR:$rs1)), (shl GPR:$rs2, (i32 16)))), (PACK GPR:$rs1, GPR:$rs2)>; +// Match a packh for the high half with a zero extended value in the low half. +// If the low half also happens to be a packh, it can be matched separately. def : Pat<(or (or (shl (zexti8 (XLenVT GPR:$op1rs2)), (XLenVT 24)), (shl (zexti8 (XLenVT GPR:$op1rs1)), (XLenVT 16))), - (or - (shl (zexti8 (XLenVT GPR:$op0rs2)), (XLenVT 8)), - (zexti8 (XLenVT GPR:$op0rs1)))), - (PACK (XLenVT (PACKH GPR:$op0rs1, GPR:$op0rs2)), + (zexti16 (XLenVT GPR:$op0))), + (PACK (XLenVT GPR:$op0), (XLenVT (PACKH GPR:$op1rs1, GPR:$op1rs2)))>; }