Skip to content

Commit 3140f6e

Browse files
toppercmemfrob
authored and
memfrob
committed
[RISCV] Have customLegalizeToWOp truncate to the original type instead of i32 now that we use it for i8/i16 as well.
239cfbccb0509da1a08d9e746706013b732e646b add support for legalizing i8/i16 UDIV/UREM/SDIV to use *W instructions. So we need to truncate to i8/i16 if we're legalizing one of those.
1 parent 4509d48 commit 3140f6e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ static SDValue customLegalizeToWOp(SDNode *N, SelectionDAG &DAG,
16191619
SDValue NewOp1 = DAG.getNode(ExtOpc, DL, MVT::i64, N->getOperand(1));
16201620
SDValue NewRes = DAG.getNode(WOpcode, DL, MVT::i64, NewOp0, NewOp1);
16211621
// ReplaceNodeResults requires we maintain the same type for the return value.
1622-
return DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, NewRes);
1622+
return DAG.getNode(ISD::TRUNCATE, DL, N->getValueType(0), NewRes);
16231623
}
16241624

16251625
// Converts the given 32-bit operation to a i64 operation with signed extension

llvm/test/CodeGen/RISCV/rv64m-exhaustive-w-insts.ll

+4
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,8 @@ define signext i8 @sext_divw_sext_sext_i8(i8 signext %a, i8 signext %b) nounwind
809809
; RV64IM-LABEL: sext_divw_sext_sext_i8:
810810
; RV64IM: # %bb.0:
811811
; RV64IM-NEXT: divw a0, a0, a1
812+
; RV64IM-NEXT: slli a0, a0, 56
813+
; RV64IM-NEXT: srai a0, a0, 56
812814
; RV64IM-NEXT: ret
813815
%1 = sdiv i8 %a, %b
814816
ret i8 %1
@@ -818,6 +820,8 @@ define signext i16 @sext_divw_sext_sext_i16(i16 signext %a, i16 signext %b) noun
818820
; RV64IM-LABEL: sext_divw_sext_sext_i16:
819821
; RV64IM: # %bb.0:
820822
; RV64IM-NEXT: divw a0, a0, a1
823+
; RV64IM-NEXT: slli a0, a0, 48
824+
; RV64IM-NEXT: srai a0, a0, 48
821825
; RV64IM-NEXT: ret
822826
%1 = sdiv i16 %a, %b
823827
ret i16 %1

0 commit comments

Comments
 (0)