Skip to content

Commit 61c9f97

Browse files
topperctru
authored andcommitted
[RISCV] Don't create BuildPairF64 or SplitF64 nodes without D or Zdinx. (#116159)
The fix in ReplaceNodeResults is the only one really required for the known crash. I couldn't hit the case in LowerOperation because that requires (f64 (bitcast i64)), but the result type is softened before the input so we don't get a chance to legalize the input. The change to the setOperationAction call was an observation that a i64<->vector cast should not be custom legalized on RV32. The custom code already calls isTypeLegal on the scalar type.
1 parent 07b4f63 commit 61c9f97

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,8 +1396,9 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
13961396
}
13971397

13981398
// Custom-legalize bitcasts from fixed-length vectors to scalar types.
1399-
setOperationAction(ISD::BITCAST, {MVT::i8, MVT::i16, MVT::i32, MVT::i64},
1400-
Custom);
1399+
setOperationAction(ISD::BITCAST, {MVT::i8, MVT::i16, MVT::i32}, Custom);
1400+
if (Subtarget.is64Bit())
1401+
setOperationAction(ISD::BITCAST, MVT::i64, Custom);
14011402
if (Subtarget.hasStdExtZfhminOrZhinxmin())
14021403
setOperationAction(ISD::BITCAST, MVT::f16, Custom);
14031404
if (Subtarget.hasStdExtFOrZfinx())
@@ -6317,7 +6318,8 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op,
63176318
DAG.getNode(RISCVISD::FMV_W_X_RV64, DL, MVT::f32, NewOp0);
63186319
return FPConv;
63196320
}
6320-
if (VT == MVT::f64 && Op0VT == MVT::i64 && XLenVT == MVT::i32) {
6321+
if (VT == MVT::f64 && Op0VT == MVT::i64 && !Subtarget.is64Bit() &&
6322+
Subtarget.hasStdExtDOrZdinx()) {
63216323
SDValue Lo, Hi;
63226324
std::tie(Lo, Hi) = DAG.SplitScalar(Op0, DL, MVT::i32, MVT::i32);
63236325
SDValue RetReg =
@@ -12616,7 +12618,8 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
1261612618
SDValue FPConv =
1261712619
DAG.getNode(RISCVISD::FMV_X_ANYEXTW_RV64, DL, MVT::i64, Op0);
1261812620
Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, FPConv));
12619-
} else if (VT == MVT::i64 && Op0VT == MVT::f64 && XLenVT == MVT::i32) {
12621+
} else if (VT == MVT::i64 && Op0VT == MVT::f64 && !Subtarget.is64Bit() &&
12622+
Subtarget.hasStdExtDOrZdinx()) {
1262012623
SDValue NewReg = DAG.getNode(RISCVISD::SplitF64, DL,
1262112624
DAG.getVTList(MVT::i32, MVT::i32), Op0);
1262212625
SDValue RetReg = DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2+
; RUN: llc < %s -mtriple=riscv32 -mattr=+zve32f,+zvl128b | FileCheck %s
3+
4+
; This bitcast previously incorrectly produce a SplitF64 node.
5+
6+
define i64 @foo(double %x) {
7+
; CHECK-LABEL: foo:
8+
; CHECK: # %bb.0:
9+
; CHECK-NEXT: addi sp, sp, -16
10+
; CHECK-NEXT: .cfi_def_cfa_offset 16
11+
; CHECK-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
12+
; CHECK-NEXT: .cfi_offset ra, -4
13+
; CHECK-NEXT: lui a3, 261888
14+
; CHECK-NEXT: li a2, 0
15+
; CHECK-NEXT: call __adddf3
16+
; CHECK-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
17+
; CHECK-NEXT: addi sp, sp, 16
18+
; CHECK-NEXT: ret
19+
%a = fadd double %x, 1.0
20+
%b = bitcast double %a to i64
21+
ret i64 %b
22+
}

0 commit comments

Comments
 (0)