Skip to content

Commit 0019565

Browse files
authored
[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 ed5aadd commit 0019565

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

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

14401440
// Custom-legalize bitcasts from fixed-length vectors to scalar types.
1441-
setOperationAction(ISD::BITCAST, {MVT::i8, MVT::i16, MVT::i32, MVT::i64},
1442-
Custom);
1441+
setOperationAction(ISD::BITCAST, {MVT::i8, MVT::i16, MVT::i32}, Custom);
1442+
if (Subtarget.is64Bit())
1443+
setOperationAction(ISD::BITCAST, MVT::i64, Custom);
14431444
if (Subtarget.hasStdExtZfhminOrZhinxmin())
14441445
setOperationAction(ISD::BITCAST, MVT::f16, Custom);
14451446
if (Subtarget.hasStdExtZfbfmin())
@@ -6422,7 +6423,8 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op,
64226423
SDValue NewOp0 = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, Op0);
64236424
return DAG.getNode(RISCVISD::FMV_W_X_RV64, DL, MVT::f32, NewOp0);
64246425
}
6425-
if (VT == MVT::f64 && Op0VT == MVT::i64 && XLenVT == MVT::i32) {
6426+
if (VT == MVT::f64 && Op0VT == MVT::i64 && !Subtarget.is64Bit() &&
6427+
Subtarget.hasStdExtDOrZdinx()) {
64266428
SDValue Lo, Hi;
64276429
std::tie(Lo, Hi) = DAG.SplitScalar(Op0, DL, MVT::i32, MVT::i32);
64286430
return DAG.getNode(RISCVISD::BuildPairF64, DL, MVT::f64, Lo, Hi);
@@ -12940,7 +12942,8 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
1294012942
SDValue FPConv =
1294112943
DAG.getNode(RISCVISD::FMV_X_ANYEXTW_RV64, DL, MVT::i64, Op0);
1294212944
Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, FPConv));
12943-
} else if (VT == MVT::i64 && Op0VT == MVT::f64 && XLenVT == MVT::i32) {
12945+
} else if (VT == MVT::i64 && Op0VT == MVT::f64 && !Subtarget.is64Bit() &&
12946+
Subtarget.hasStdExtDOrZdinx()) {
1294412947
SDValue NewReg = DAG.getNode(RISCVISD::SplitF64, DL,
1294512948
DAG.getVTList(MVT::i32, MVT::i32), Op0);
1294612949
SDValue RetReg = DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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: .cfi_restore ra
18+
; CHECK-NEXT: addi sp, sp, 16
19+
; CHECK-NEXT: .cfi_def_cfa_offset 0
20+
; CHECK-NEXT: ret
21+
%a = fadd double %x, 1.0
22+
%b = bitcast double %a to i64
23+
ret i64 %b
24+
}

0 commit comments

Comments
 (0)