Skip to content

Commit 71b6f6b

Browse files
authored
[RISCV] Add missing hasPostISelHook = 1 to vector pseudos that might read FRM. (#114186)
We need an implicit FRM read operand anytime the rounding mode is dynamic. The post isel hook is responsible for this when isel creates an instruction with dynamic rounding mode. Add a MachineVerifier check to verify the operand is present.
1 parent c3724ba commit 71b6f6b

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,6 +2630,13 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
26302630
}
26312631
}
26322632

2633+
if (int Idx = RISCVII::getFRMOpNum(Desc);
2634+
Idx >= 0 && MI.getOperand(Idx).getImm() == RISCVFPRndMode::DYN &&
2635+
!MI.readsRegister(RISCV::FRM, /*TRI=*/nullptr)) {
2636+
ErrInfo = "dynamic rounding mode should read FRM";
2637+
return false;
2638+
}
2639+
26332640
return true;
26342641
}
26352642

llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6483,7 +6483,7 @@ defm PseudoVFRDIV : VPseudoVFRDIV_VF_RM;
64836483
//===----------------------------------------------------------------------===//
64846484
// 13.5. Vector Widening Floating-Point Multiply
64856485
//===----------------------------------------------------------------------===//
6486-
let mayRaiseFPException = true, hasSideEffects = 0 in {
6486+
let mayRaiseFPException = true, hasSideEffects = 0, hasPostISelHook = 1 in {
64876487
defm PseudoVFWMUL : VPseudoVWMUL_VV_VF_RM;
64886488
}
64896489

@@ -6516,7 +6516,7 @@ defm PseudoVFWMACCBF16 : VPseudoVWMAC_VV_VF_BF_RM;
65166516
//===----------------------------------------------------------------------===//
65176517
// 13.8. Vector Floating-Point Square-Root Instruction
65186518
//===----------------------------------------------------------------------===//
6519-
let mayRaiseFPException = true, hasSideEffects = 0 in
6519+
let mayRaiseFPException = true, hasSideEffects = 0, hasPostISelHook = 1 in
65206520
defm PseudoVFSQRT : VPseudoVSQR_V_RM;
65216521

65226522
//===----------------------------------------------------------------------===//
@@ -6528,7 +6528,7 @@ defm PseudoVFRSQRT7 : VPseudoVRCP_V;
65286528
//===----------------------------------------------------------------------===//
65296529
// 13.10. Vector Floating-Point Reciprocal Estimate Instruction
65306530
//===----------------------------------------------------------------------===//
6531-
let mayRaiseFPException = true, hasSideEffects = 0 in
6531+
let mayRaiseFPException = true, hasSideEffects = 0, hasPostISelHook = 1 in
65326532
defm PseudoVFREC7 : VPseudoVRCP_V_RM;
65336533

65346534
//===----------------------------------------------------------------------===//
@@ -6640,9 +6640,10 @@ defm PseudoVFNCVT_F_X : VPseudoVNCVTF_W_RM;
66406640
defm PseudoVFNCVT_RM_F_XU : VPseudoVNCVTF_RM_W;
66416641
defm PseudoVFNCVT_RM_F_X : VPseudoVNCVTF_RM_W;
66426642

6643-
let hasSideEffects = 0, hasPostISelHook = 1 in
6643+
let hasSideEffects = 0, hasPostISelHook = 1 in {
66446644
defm PseudoVFNCVT_F_F : VPseudoVNCVTD_W_RM;
66456645
defm PseudoVFNCVTBF16_F_F : VPseudoVNCVTD_W_RM;
6646+
}
66466647

66476648
defm PseudoVFNCVT_ROD_F_F : VPseudoVNCVTD_W;
66486649
} // mayRaiseFPException = true
@@ -6678,8 +6679,7 @@ let Predicates = [HasVInstructionsAnyF] in {
66786679
//===----------------------------------------------------------------------===//
66796680
// 14.3. Vector Single-Width Floating-Point Reduction Instructions
66806681
//===----------------------------------------------------------------------===//
6681-
let mayRaiseFPException = true,
6682-
hasSideEffects = 0 in {
6682+
let mayRaiseFPException = true, hasSideEffects = 0, hasPostISelHook = 1 in {
66836683
defm PseudoVFREDOSUM : VPseudoVFREDO_VS_RM;
66846684
defm PseudoVFREDUSUM : VPseudoVFRED_VS_RM;
66856685
}
@@ -6691,9 +6691,8 @@ defm PseudoVFREDMAX : VPseudoVFREDMINMAX_VS;
66916691
//===----------------------------------------------------------------------===//
66926692
// 14.4. Vector Widening Floating-Point Reduction Instructions
66936693
//===----------------------------------------------------------------------===//
6694-
let IsRVVWideningReduction = 1,
6695-
hasSideEffects = 0,
6696-
mayRaiseFPException = true in {
6694+
let IsRVVWideningReduction = 1, hasSideEffects = 0, mayRaiseFPException = true,
6695+
hasPostISelHook = 1 in {
66976696
defm PseudoVFWREDUSUM : VPseudoVFWRED_VS_RM;
66986697
defm PseudoVFWREDOSUM : VPseudoVFWREDO_VS_RM;
66996698
}

0 commit comments

Comments
 (0)