case RISCV::SUBW:
case RISCV::MULW:
case RISCV::SLLIW:
+ case RISCV::PACKW:
// Result is already sign extended just remove the sext.w.
// NOTE: We only handle the nodes that are selected with hasAllWUsers.
ReplaceUses(N, N0.getNode());
def : Pat<(i64 (or (and GPR:$rs1, 0x00000000FFFFFFFF), (shl GPR:$rs2, (i64 32)))),
(PACK GPR:$rs1, GPR:$rs2)>;
-def : Pat<(i64 (sext_inreg (or (shl GPR:$rs2, (i64 16)),
+def : Pat<(binop_allwusers<or> (shl GPR:$rs2, (i64 16)),
(zexti16 GPR:$rs1)),
- i32)),
(PACKW GPR:$rs1, GPR:$rs2)>;
def : Pat<(i64 (or (sext_inreg (shl GPR:$rs2, (i64 16)), i32),
(zexti16 GPR:$rs1))),
ret i32 %or
}
+define i32 @pack_i32_3(i16 zeroext %0, i16 zeroext %1, i32 %2) {
+; RV32I-LABEL: pack_i32_3:
+; RV32I: # %bb.0:
+; RV32I-NEXT: slli a0, a0, 16
+; RV32I-NEXT: or a0, a0, a1
+; RV32I-NEXT: add a0, a0, a2
+; RV32I-NEXT: ret
+;
+; RV32ZBKB-LABEL: pack_i32_3:
+; RV32ZBKB: # %bb.0:
+; RV32ZBKB-NEXT: pack a0, a1, a0
+; RV32ZBKB-NEXT: add a0, a0, a2
+; RV32ZBKB-NEXT: ret
+ %4 = zext i16 %0 to i32
+ %5 = shl nuw i32 %4, 16
+ %6 = zext i16 %1 to i32
+ %7 = or i32 %5, %6
+ %8 = add i32 %7, %2
+ ret i32 %8
+}
+
; As we are not matching directly i64 code patterns on RV32 some i64 patterns
; don't have yet any matching bit manipulation instructions on RV32.
; This test is presented here in case future expansions of the Bitmanip
ret i32 %or
}
+; Test case where we don't have a sign_extend_inreg after the or.
+define signext i32 @pack_i32_3(i16 zeroext %0, i16 zeroext %1, i32 signext %2) {
+; RV64I-LABEL: pack_i32_3:
+; RV64I: # %bb.0:
+; RV64I-NEXT: slli a0, a0, 16
+; RV64I-NEXT: or a0, a0, a1
+; RV64I-NEXT: addw a0, a0, a2
+; RV64I-NEXT: ret
+;
+; RV64ZBKB-LABEL: pack_i32_3:
+; RV64ZBKB: # %bb.0:
+; RV64ZBKB-NEXT: packw a0, a1, a0
+; RV64ZBKB-NEXT: addw a0, a0, a2
+; RV64ZBKB-NEXT: ret
+ %4 = zext i16 %0 to i32
+ %5 = shl nuw i32 %4, 16
+ %6 = zext i16 %1 to i32
+ %7 = or i32 %5, %6
+ %8 = add i32 %7, %2
+ ret i32 %8
+}
+
define i64 @pack_i64(i64 %a, i64 %b) nounwind {
; RV64I-LABEL: pack_i64:
; RV64I: # %bb.0: