diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp index 4e220bb6f94b..97f46d9731b1 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -1619,7 +1619,7 @@ static SDValue customLegalizeToWOp(SDNode *N, SelectionDAG &DAG, SDValue NewOp1 = DAG.getNode(ExtOpc, DL, MVT::i64, N->getOperand(1)); SDValue NewRes = DAG.getNode(WOpcode, DL, MVT::i64, NewOp0, NewOp1); // ReplaceNodeResults requires we maintain the same type for the return value. - return DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, NewRes); + return DAG.getNode(ISD::TRUNCATE, DL, N->getValueType(0), NewRes); } // Converts the given 32-bit operation to a i64 operation with signed extension diff --git a/llvm/test/CodeGen/RISCV/rv64m-exhaustive-w-insts.ll b/llvm/test/CodeGen/RISCV/rv64m-exhaustive-w-insts.ll index 734d2bb21cc3..e2bd2cbb30d3 100644 --- a/llvm/test/CodeGen/RISCV/rv64m-exhaustive-w-insts.ll +++ b/llvm/test/CodeGen/RISCV/rv64m-exhaustive-w-insts.ll @@ -809,6 +809,8 @@ define signext i8 @sext_divw_sext_sext_i8(i8 signext %a, i8 signext %b) nounwind ; RV64IM-LABEL: sext_divw_sext_sext_i8: ; RV64IM: # %bb.0: ; RV64IM-NEXT: divw a0, a0, a1 +; RV64IM-NEXT: slli a0, a0, 56 +; RV64IM-NEXT: srai a0, a0, 56 ; RV64IM-NEXT: ret %1 = sdiv i8 %a, %b ret i8 %1 @@ -818,6 +820,8 @@ define signext i16 @sext_divw_sext_sext_i16(i16 signext %a, i16 signext %b) noun ; RV64IM-LABEL: sext_divw_sext_sext_i16: ; RV64IM: # %bb.0: ; RV64IM-NEXT: divw a0, a0, a1 +; RV64IM-NEXT: slli a0, a0, 48 +; RV64IM-NEXT: srai a0, a0, 48 ; RV64IM-NEXT: ret %1 = sdiv i16 %a, %b ret i16 %1