Skip to content

Commit 76508dc

Browse files
authored
[AMDGPU] Fix mode register pass for constrained FP operations (#90085)
This PR will fix the si-mode-register pass which is inserting an extra setreg instruction in case of constrained FP operations. This pass will be ignored for strictfp functions.
1 parent fc398a1 commit 76508dc

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

llvm/lib/Target/AMDGPU/SIModeRegister.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,14 @@ void SIModeRegister::processBlockPhase3(MachineBasicBlock &MBB,
430430
}
431431

432432
bool SIModeRegister::runOnMachineFunction(MachineFunction &MF) {
433+
// Constrained FP intrinsics are used to support non-default rounding modes.
434+
// strictfp attribute is required to mark functions with strict FP semantics
435+
// having constrained FP intrinsics. This pass fixes up operations that uses
436+
// a non-default rounding mode for non-strictfp functions. But it should not
437+
// assume or modify any default rounding modes in case of strictfp functions.
438+
const Function &F = MF.getFunction();
439+
if (F.hasFnAttribute(llvm::Attribute::StrictFP))
440+
return Changed;
433441
BlockInfo.resize(MF.getNumBlockIDs());
434442
const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
435443
const SIInstrInfo *TII = ST.getInstrInfo();

llvm/test/CodeGen/AMDGPU/mode-register-fpconstrain.ll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ define double @ignoreStrictfp(double noundef %a, double noundef %b) #0 {
99
; GCN: ; %bb.0:
1010
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1111
; GCN-NEXT: s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), 1
12-
; GCN-NEXT: s_nop 1
13-
; GCN-NEXT: s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 1), 0
1412
; GCN-NEXT: v_add_f64 v[0:1], v[0:1], v[2:3]
1513
; GCN-NEXT: s_setpc_b64 s[30:31]
1614
tail call void @llvm.amdgcn.s.setreg(i32 2177, i32 1)
@@ -24,8 +22,6 @@ define double @set_fpenv(double noundef %a, double noundef %b) #0 {
2422
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2523
; GCN-NEXT: s_setreg_imm32_b32 hwreg(HW_REG_MODE, 0, 23), 4
2624
; GCN-NEXT: s_setreg_imm32_b32 hwreg(HW_REG_TRAPSTS, 0, 5), 0
27-
; GCN-NEXT: s_nop 0
28-
; GCN-NEXT: s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 1), 0
2925
; GCN-NEXT: v_add_f64 v[0:1], v[0:1], v[2:3]
3026
; GCN-NEXT: s_setpc_b64 s[30:31]
3127
entry:

0 commit comments

Comments
 (0)