Skip to content

Commit 4eb4f89

Browse files
committed
[RISCV] Use sign extend for i32 arguments and returns in makeLibCall on RV64.
As far as I know 32 bits arguments and returns on RV64 are always sign extended to i64. So I think we should be taking this into account around libcalls. Reviewed By: luismarques Differential Revision: https://reviews.llvm.org/D95285
1 parent 193cda1 commit 4eb4f89

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4250,6 +4250,13 @@ bool RISCVTargetLowering::shouldExtendTypeInLibCall(EVT Type) const {
42504250
return true;
42514251
}
42524252

4253+
bool RISCVTargetLowering::shouldSignExtendTypeInLibCall(EVT Type, bool IsSigned) const {
4254+
if (Subtarget.is64Bit() && Type == MVT::i32)
4255+
return true;
4256+
4257+
return IsSigned;
4258+
}
4259+
42534260
bool RISCVTargetLowering::decomposeMulByConstant(LLVMContext &Context, EVT VT,
42544261
SDValue C) const {
42554262
// Check integral scalar types.

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ class RISCVTargetLowering : public TargetLowering {
217217
getExceptionSelectorRegister(const Constant *PersonalityFn) const override;
218218

219219
bool shouldExtendTypeInLibCall(EVT Type) const override;
220+
bool shouldSignExtendTypeInLibCall(EVT Type, bool IsSigned) const override;
220221

221222
/// Returns the register with the specified architectural or ABI name. This
222223
/// method is necessary to lower the llvm.read_register.* and

llvm/test/CodeGen/RISCV/rv64i-single-softfloat.ll

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ define i32 @flt_s(float %a, float %b) nounwind {
8080
; RV64I-NEXT: addi sp, sp, -16
8181
; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
8282
; RV64I-NEXT: call __ltsf2@plt
83-
; RV64I-NEXT: sext.w a0, a0
8483
; RV64I-NEXT: slti a0, a0, 0
8584
; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
8685
; RV64I-NEXT: addi sp, sp, 16
@@ -96,7 +95,6 @@ define i32 @fle_s(float %a, float %b) nounwind {
9695
; RV64I-NEXT: addi sp, sp, -16
9796
; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
9897
; RV64I-NEXT: call __lesf2@plt
99-
; RV64I-NEXT: sext.w a0, a0
10098
; RV64I-NEXT: slti a0, a0, 1
10199
; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
102100
; RV64I-NEXT: addi sp, sp, 16
@@ -112,7 +110,6 @@ define i32 @fcmp_ogt(float %a, float %b) nounwind {
112110
; RV64I-NEXT: addi sp, sp, -16
113111
; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
114112
; RV64I-NEXT: call __gtsf2@plt
115-
; RV64I-NEXT: sext.w a0, a0
116113
; RV64I-NEXT: sgtz a0, a0
117114
; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
118115
; RV64I-NEXT: addi sp, sp, 16
@@ -128,7 +125,6 @@ define i32 @fcmp_oge(float %a, float %b) nounwind {
128125
; RV64I-NEXT: addi sp, sp, -16
129126
; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
130127
; RV64I-NEXT: call __gesf2@plt
131-
; RV64I-NEXT: sext.w a0, a0
132128
; RV64I-NEXT: addi a1, zero, -1
133129
; RV64I-NEXT: slt a0, a1, a0
134130
; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
@@ -214,8 +210,7 @@ define float @fcvt_s_wu(i32 %a) nounwind {
214210
; RV64I: # %bb.0:
215211
; RV64I-NEXT: addi sp, sp, -16
216212
; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
217-
; RV64I-NEXT: slli a0, a0, 32
218-
; RV64I-NEXT: srli a0, a0, 32
213+
; RV64I-NEXT: sext.w a0, a0
219214
; RV64I-NEXT: call __floatunsisf@plt
220215
; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
221216
; RV64I-NEXT: addi sp, sp, 16
@@ -675,8 +670,7 @@ define float @fpowi_s(float %a, i32 %b) nounwind {
675670
; RV64I: # %bb.0:
676671
; RV64I-NEXT: addi sp, sp, -16
677672
; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
678-
; RV64I-NEXT: slli a1, a1, 32
679-
; RV64I-NEXT: srli a1, a1, 32
673+
; RV64I-NEXT: sext.w a1, a1
680674
; RV64I-NEXT: call __powisf2@plt
681675
; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
682676
; RV64I-NEXT: addi sp, sp, 16

0 commit comments

Comments
 (0)