Skip to content

[AMDGPU] Fix mode register pass for constrained FP operations #90085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llvm/lib/Target/AMDGPU/SIModeRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,14 @@ void SIModeRegister::processBlockPhase3(MachineBasicBlock &MBB,
}

bool SIModeRegister::runOnMachineFunction(MachineFunction &MF) {
// Constrained FP intrinsics are used to support non-default rounding modes.
// strictfp attribute is required to mark functions with strict FP semantics
// having constrained FP intrinsics. This pass fixes up operations that uses
// a non-default rounding mode for non-strictfp functions. But it should not
// assume or modify any default rounding modes in case of strictfp functions.
const Function &F = MF.getFunction();
if (F.hasFnAttribute(llvm::Attribute::StrictFP))
return Changed;
BlockInfo.resize(MF.getNumBlockIDs());
const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
const SIInstrInfo *TII = ST.getInstrInfo();
Expand Down
4 changes: 0 additions & 4 deletions llvm/test/CodeGen/AMDGPU/mode-register-fpconstrain.ll
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ define double @ignoreStrictfp(double noundef %a, double noundef %b) #0 {
; GCN: ; %bb.0:
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
; GCN-NEXT: s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), 1
; GCN-NEXT: s_nop 1
; GCN-NEXT: s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 1), 0
; GCN-NEXT: v_add_f64 v[0:1], v[0:1], v[2:3]
; GCN-NEXT: s_setpc_b64 s[30:31]
tail call void @llvm.amdgcn.s.setreg(i32 2177, i32 1)
Expand All @@ -24,8 +22,6 @@ define double @set_fpenv(double noundef %a, double noundef %b) #0 {
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
; GCN-NEXT: s_setreg_imm32_b32 hwreg(HW_REG_MODE, 0, 23), 4
; GCN-NEXT: s_setreg_imm32_b32 hwreg(HW_REG_TRAPSTS, 0, 5), 0
; GCN-NEXT: s_nop 0
; GCN-NEXT: s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 1), 0
; GCN-NEXT: v_add_f64 v[0:1], v[0:1], v[2:3]
; GCN-NEXT: s_setpc_b64 s[30:31]
entry:
Expand Down