Skip to content

Commit 49660e5

Browse files
authored
[RISCV] Pass f32/f64 directly without a bitcast for Zfinx/Zdinx. (#107464)
With Zfinx/Zdinx, f32/f64 are legal types for a GPR, we don't need a bitcast. This avoids turning fneg/fabs into bitwise operations purely because of these bitcasts. If the bitwise operations are faster for some reason on a Zfinx CPU, then that seems like it should be done for all fneg/fabs, not just ones near function arguments/returns. I don't have much interest in Zfinx, this just makes the code more similar to what I proposed for Zhinx in #107446.
1 parent 9700ca0 commit 49660e5

12 files changed

+645
-681
lines changed

llvm/lib/Target/RISCV/RISCVCallingConv.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,14 @@ bool llvm::CC_RISCV(unsigned ValNo, MVT ValVT, MVT LocVT,
312312

313313
ArrayRef<MCPhysReg> ArgGPRs = RISCV::getArgGPRs(ABI);
314314

315+
if ((ValVT == MVT::f32 && XLen == 32 && Subtarget.hasStdExtZfinx()) ||
316+
(ValVT == MVT::f64 && XLen == 64 && Subtarget.hasStdExtZdinx())) {
317+
if (MCRegister Reg = State.AllocateReg(ArgGPRs)) {
318+
State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
319+
return false;
320+
}
321+
}
322+
315323
if (UseGPRForF16_F32 && (ValVT == MVT::f16 || ValVT == MVT::bf16 ||
316324
(ValVT == MVT::f32 && XLen == 64))) {
317325
MCRegister Reg = State.AllocateReg(ArgGPRs);
@@ -571,8 +579,6 @@ bool llvm::CC_RISCV_FastCC(unsigned ValNo, MVT ValVT, MVT LocVT,
571579
CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
572580
return false;
573581
}
574-
LocVT = Subtarget.getXLenVT();
575-
LocInfo = CCValAssign::BCvt;
576582
State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
577583
return false;
578584
}

llvm/test/CodeGen/RISCV/double-arith.ll

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,7 @@ define double @fsgnjn_d(double %a, double %b) nounwind {
320320
;
321321
; RV64IZFINXZDINX-LABEL: fsgnjn_d:
322322
; RV64IZFINXZDINX: # %bb.0:
323-
; RV64IZFINXZDINX-NEXT: not a1, a1
324-
; RV64IZFINXZDINX-NEXT: fsgnj.d a0, a0, a1
323+
; RV64IZFINXZDINX-NEXT: fsgnjn.d a0, a0, a1
325324
; RV64IZFINXZDINX-NEXT: ret
326325
;
327326
; RV32I-LABEL: fsgnjn_d:
@@ -852,9 +851,7 @@ define double @fnmadd_d_3(double %a, double %b, double %c) nounwind {
852851
; RV64IZFINXZDINX-LABEL: fnmadd_d_3:
853852
; RV64IZFINXZDINX: # %bb.0:
854853
; RV64IZFINXZDINX-NEXT: fmadd.d a0, a0, a1, a2
855-
; RV64IZFINXZDINX-NEXT: li a1, -1
856-
; RV64IZFINXZDINX-NEXT: slli a1, a1, 63
857-
; RV64IZFINXZDINX-NEXT: xor a0, a0, a1
854+
; RV64IZFINXZDINX-NEXT: fneg.d a0, a0
858855
; RV64IZFINXZDINX-NEXT: ret
859856
;
860857
; RV32I-LABEL: fnmadd_d_3:
@@ -900,10 +897,7 @@ define double @fnmadd_nsz(double %a, double %b, double %c) nounwind {
900897
;
901898
; RV64IZFINXZDINX-LABEL: fnmadd_nsz:
902899
; RV64IZFINXZDINX: # %bb.0:
903-
; RV64IZFINXZDINX-NEXT: fmadd.d a0, a0, a1, a2
904-
; RV64IZFINXZDINX-NEXT: li a1, -1
905-
; RV64IZFINXZDINX-NEXT: slli a1, a1, 63
906-
; RV64IZFINXZDINX-NEXT: xor a0, a0, a1
900+
; RV64IZFINXZDINX-NEXT: fnmadd.d a0, a0, a1, a2
907901
; RV64IZFINXZDINX-NEXT: ret
908902
;
909903
; RV32I-LABEL: fnmadd_nsz:

llvm/test/CodeGen/RISCV/double-bitmanip-dagcombines.ll

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ define double @fneg(double %a) nounwind {
5656
;
5757
; RV64IZFINXZDINX-LABEL: fneg:
5858
; RV64IZFINXZDINX: # %bb.0:
59-
; RV64IZFINXZDINX-NEXT: li a1, -1
60-
; RV64IZFINXZDINX-NEXT: slli a1, a1, 63
61-
; RV64IZFINXZDINX-NEXT: xor a0, a0, a1
59+
; RV64IZFINXZDINX-NEXT: fneg.d a0, a0
6260
; RV64IZFINXZDINX-NEXT: ret
6361
%1 = fneg double %a
6462
ret double %1
@@ -99,8 +97,7 @@ define double @fabs(double %a) nounwind {
9997
;
10098
; RV64IZFINXZDINX-LABEL: fabs:
10199
; RV64IZFINXZDINX: # %bb.0:
102-
; RV64IZFINXZDINX-NEXT: slli a0, a0, 1
103-
; RV64IZFINXZDINX-NEXT: srli a0, a0, 1
100+
; RV64IZFINXZDINX-NEXT: fabs.d a0, a0
104101
; RV64IZFINXZDINX-NEXT: ret
105102
%1 = call double @llvm.fabs.f64(double %a)
106103
ret double %1
@@ -165,8 +162,7 @@ define double @fcopysign_fneg(double %a, double %b) nounwind {
165162
;
166163
; RV64IZFINXZDINX-LABEL: fcopysign_fneg:
167164
; RV64IZFINXZDINX: # %bb.0:
168-
; RV64IZFINXZDINX-NEXT: not a1, a1
169-
; RV64IZFINXZDINX-NEXT: fsgnj.d a0, a0, a1
165+
; RV64IZFINXZDINX-NEXT: fsgnjn.d a0, a0, a1
170166
; RV64IZFINXZDINX-NEXT: ret
171167
%1 = fneg double %b
172168
%2 = call double @llvm.copysign.f64(double %a, double %1)

llvm/test/CodeGen/RISCV/double-imm.ll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ define double @double_negative_zero(ptr %pd) nounwind {
115115
;
116116
; CHECKRV64ZDINX-LABEL: double_negative_zero:
117117
; CHECKRV64ZDINX: # %bb.0:
118-
; CHECKRV64ZDINX-NEXT: li a0, -1
119-
; CHECKRV64ZDINX-NEXT: slli a0, a0, 63
118+
; CHECKRV64ZDINX-NEXT: fneg.d a0, zero
120119
; CHECKRV64ZDINX-NEXT: ret
121120
ret double -0.0
122121
}
@@ -160,12 +159,11 @@ define dso_local double @negzero_sel(i16 noundef %a, double noundef %d) nounwind
160159
; CHECKRV64ZDINX-LABEL: negzero_sel:
161160
; CHECKRV64ZDINX: # %bb.0: # %entry
162161
; CHECKRV64ZDINX-NEXT: slli a2, a0, 48
162+
; CHECKRV64ZDINX-NEXT: mv a0, a1
163163
; CHECKRV64ZDINX-NEXT: beqz a2, .LBB4_2
164164
; CHECKRV64ZDINX-NEXT: # %bb.1: # %entry
165165
; CHECKRV64ZDINX-NEXT: fneg.d a0, zero
166-
; CHECKRV64ZDINX-NEXT: ret
167-
; CHECKRV64ZDINX-NEXT: .LBB4_2:
168-
; CHECKRV64ZDINX-NEXT: mv a0, a1
166+
; CHECKRV64ZDINX-NEXT: .LBB4_2: # %entry
169167
; CHECKRV64ZDINX-NEXT: ret
170168
entry:
171169
%tobool.not = icmp eq i16 %a, 0

llvm/test/CodeGen/RISCV/double-intrinsics.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,7 @@ define double @fabs_f64(double %a) nounwind {
684684
;
685685
; RV64IZFINXZDINX-LABEL: fabs_f64:
686686
; RV64IZFINXZDINX: # %bb.0:
687-
; RV64IZFINXZDINX-NEXT: slli a0, a0, 1
688-
; RV64IZFINXZDINX-NEXT: srli a0, a0, 1
687+
; RV64IZFINXZDINX-NEXT: fabs.d a0, a0
689688
; RV64IZFINXZDINX-NEXT: ret
690689
;
691690
; RV32I-LABEL: fabs_f64:

0 commit comments

Comments
 (0)