[llvm] [SPIR-V] Implement SPV_KHR_float_controls2 (PR #146941)
Marcos Maronas via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 25 09:40:06 PDT 2025
================
@@ -606,6 +664,73 @@ void SPIRVAsmPrinter::outputAnnotations(const Module &M) {
}
}
+void SPIRVAsmPrinter::outputFPFastMathDefaultInfo() {
+ // Collect the SPIRVTypes that are OpTypeFloat.
+ std::vector<const MachineInstr *> SPIRVFloatTypes;
+ for (const MachineInstr *MI : MAI->getMSInstrs(SPIRV::MB_TypeConstVars)) {
+ // Skip if the instruction is not OpTypeFloat.
+ if (MI->getOpcode() != SPIRV::OpTypeFloat)
+ continue;
+
+ // Collect the SPIRV type.
+ SPIRVFloatTypes.push_back(MI);
+ }
+
+ for (const auto &[Func, FPFastMathDefaultInfoVec] :
+ MAI->FPFastMathDefaultInfoMap) {
+ if (FPFastMathDefaultInfoVec.empty())
+ continue;
+
+ for (const MachineInstr *MI : SPIRVFloatTypes) {
+ unsigned OpTypeFloatSize = MI->getOperand(1).getImm();
+ unsigned Index = computeFPFastMathDefaultInfoVecIndex(OpTypeFloatSize);
+ assert(Index < FPFastMathDefaultInfoVec.size() &&
+ "Index out of bounds for FPFastMathDefaultInfoVec");
+ const auto &FPFastMathDefaultInfo = FPFastMathDefaultInfoVec[Index];
+ assert(FPFastMathDefaultInfo.Ty &&
+ "Expected target type for FPFastMathDefaultInfo");
+ assert(FPFastMathDefaultInfo.Ty->getScalarSizeInBits() ==
+ OpTypeFloatSize &&
+ "Mismatched float type size");
+ MCInst Inst;
+ Inst.setOpcode(SPIRV::OpExecutionMode);
+ MCRegister FuncReg = MAI->getFuncReg(Func);
+ assert(FuncReg.isValid());
+ Inst.addOperand(MCOperand::createReg(FuncReg));
+ Inst.addOperand(
+ MCOperand::createImm(SPIRV::ExecutionMode::FPFastMathDefault));
+ MCRegister TypeReg =
+ MAI->getRegisterAlias(MI->getMF(), MI->getOperand(0).getReg());
+ Inst.addOperand(MCOperand::createReg(TypeReg));
+ unsigned Flags = FPFastMathDefaultInfo.FastMathFlags;
+ if (FPFastMathDefaultInfo.ContractionOff &&
+ (Flags & SPIRV::FPFastMathMode::AllowContract) &&
+ FPFastMathDefaultInfo.FPFastMathDefault)
----------------
maarquitos14 wrote:
It's been a while since I updated this. I _think_ my point here was to make sure we only emitted the error if the `SPIRV::FPFastMathMode::AllowContract` bit was set actively by `FPFastMathDefault`. However, on a second thought, I don't see any other way it would be enabled, so I think you're right, checking `FPFastMathDefaultInfo.FPFastMathDefault` is redundant. I'll go change that, and hopefully it doesn't break anything.
https://github.com/llvm/llvm-project/pull/146941
More information about the llvm-commits
mailing list