Skip to content

Commit ea23b64

Browse files
committed
AMDGPU: Be explicit about denormal mode in MIR tests
Start checking the machine function in GlobalISel instead of the target directly. This temporarily breaks fcanonicalize selection in GlobalISel.
1 parent c9b8798 commit ea23b64

File tree

8 files changed

+1965
-873
lines changed

8 files changed

+1965
-873
lines changed

llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,13 +1720,15 @@ bool AMDGPULegalizerInfo::legalizeFMad(
17201720
LLT Ty = MRI.getType(MI.getOperand(0).getReg());
17211721
assert(Ty.isScalar());
17221722

1723+
MachineFunction &MF = B.getMF();
1724+
const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();
1725+
17231726
// TODO: Always legal with future ftz flag.
1724-
if (Ty == LLT::scalar(32) && !ST.hasFP32Denormals())
1727+
if (Ty == LLT::scalar(32) && !MFI->getMode().FP32Denormals)
17251728
return true;
1726-
if (Ty == LLT::scalar(16) && !ST.hasFP16Denormals())
1729+
if (Ty == LLT::scalar(16) && !MFI->getMode().FP64FP16Denormals)
17271730
return true;
17281731

1729-
MachineFunction &MF = B.getMF();
17301732

17311733
MachineIRBuilder HelperBuilder(MI);
17321734
GISelObserverWrapper DummyObserver;
@@ -1897,7 +1899,8 @@ bool AMDGPULegalizerInfo::legalizeFastUnsafeFDIV(MachineInstr &MI,
18971899
if (!MF.getTarget().Options.UnsafeFPMath && ResTy == S64)
18981900
return false;
18991901

1900-
if (!Unsafe && ResTy == S32 && ST.hasFP32Denormals())
1902+
if (!Unsafe && ResTy == S32 &&
1903+
MF.getInfo<SIMachineFunctionInfo>()->getMode().FP32Denormals)
19011904
return false;
19021905

19031906
if (auto CLHS = getConstantFPVRegVal(LHS, MRI)) {
@@ -1973,15 +1976,16 @@ bool AMDGPULegalizerInfo::legalizeFDIV16(MachineInstr &MI,
19731976
// Enable or disable FP32 denorm mode. When 'Enable' is true, emit instructions
19741977
// to enable denorm mode. When 'Enable' is false, disable denorm mode.
19751978
static void toggleSPDenormMode(bool Enable,
1979+
MachineIRBuilder &B,
19761980
const GCNSubtarget &ST,
1977-
MachineIRBuilder &B) {
1981+
AMDGPU::SIModeRegisterDefaults Mode) {
19781982
// Set SP denorm mode to this value.
19791983
unsigned SPDenormMode =
19801984
Enable ? FP_DENORM_FLUSH_NONE : FP_DENORM_FLUSH_IN_FLUSH_OUT;
19811985

19821986
if (ST.hasDenormModeInst()) {
19831987
// Preserve default FP64FP16 denorm mode while updating FP32 mode.
1984-
unsigned DPDenormModeDefault = ST.hasFP64Denormals()
1988+
unsigned DPDenormModeDefault = Mode.FP64FP16Denormals
19851989
? FP_DENORM_FLUSH_NONE
19861990
: FP_DENORM_FLUSH_IN_FLUSH_OUT;
19871991

@@ -2008,6 +2012,8 @@ bool AMDGPULegalizerInfo::legalizeFDIV32(MachineInstr &MI,
20082012
Register Res = MI.getOperand(0).getReg();
20092013
Register LHS = MI.getOperand(1).getReg();
20102014
Register RHS = MI.getOperand(2).getReg();
2015+
const SIMachineFunctionInfo *MFI = B.getMF().getInfo<SIMachineFunctionInfo>();
2016+
AMDGPU::SIModeRegisterDefaults Mode = MFI->getMode();
20112017

20122018
uint16_t Flags = MI.getFlags();
20132019

@@ -2036,8 +2042,8 @@ bool AMDGPULegalizerInfo::legalizeFDIV32(MachineInstr &MI,
20362042

20372043
// FIXME: Doesn't correctly model the FP mode switch, and the FP operations
20382044
// aren't modeled as reading it.
2039-
if (!ST.hasFP32Denormals())
2040-
toggleSPDenormMode(true, ST, B);
2045+
if (!Mode.FP32Denormals)
2046+
toggleSPDenormMode(true, B, ST, Mode);
20412047

20422048
auto Fma0 = B.buildFMA(S32, NegDivScale0, ApproxRcp, One, Flags);
20432049
auto Fma1 = B.buildFMA(S32, Fma0, ApproxRcp, ApproxRcp, Flags);
@@ -2046,8 +2052,8 @@ bool AMDGPULegalizerInfo::legalizeFDIV32(MachineInstr &MI,
20462052
auto Fma3 = B.buildFMA(S32, Fma2, Fma1, Mul, Flags);
20472053
auto Fma4 = B.buildFMA(S32, NegDivScale0, Fma3, NumeratorScaled, Flags);
20482054

2049-
if (!ST.hasFP32Denormals())
2050-
toggleSPDenormMode(false, ST, B);
2055+
if (!Mode.FP32Denormals)
2056+
toggleSPDenormMode(false, B, ST, Mode);
20512057

20522058
auto Fmas = B.buildIntrinsic(Intrinsic::amdgcn_div_fmas, {S32}, false)
20532059
.addUse(Fma4.getReg(0))

0 commit comments

Comments
 (0)