[llvm] [SPIR-V] Implement SPV_KHR_float_controls2 (PR #146941)
Nathan Gauër via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 9 02:55:52 PDT 2025
================
@@ -665,15 +696,34 @@ void SPIRVAsmPrinter::outputAnnotations(const Module &M) {
}
void SPIRVAsmPrinter::outputFPFastMathDefaultInfo() {
- // Collect the SPIRVTypes that are OpTypeFloat.
+ // Collect the SPIRVTypes that are OpTypeFloat and the constants of type
+ // int32, that might be used as FP Fast Math Mode.
std::vector<const MachineInstr *> SPIRVFloatTypes;
+ // Hashtable to associate immediate values with the constant holding them.
+ std::unordered_map<unsigned, const MachineInstr *> ConstMap;
for (const MachineInstr *MI : MAI->getMSInstrs(SPIRV::MB_TypeConstVars)) {
- // Skip if the instruction is not OpTypeFloat.
- if (MI->getOpcode() != SPIRV::OpTypeFloat)
+ // Skip if the instruction is not OpTypeFloat or OpConstant.
+ unsigned OpCode = MI->getOpcode();
+ if (OpCode != SPIRV::OpTypeFloat && OpCode != SPIRV::OpConstantI &&
+ OpCode != SPIRV::OpConstantNull)
continue;
- // Collect the SPIRV type.
- SPIRVFloatTypes.push_back(MI);
+ // Collect the SPIRV type if it's a float.
+ if (OpCode == SPIRV::OpTypeFloat) {
+ SPIRVFloatTypes.push_back(MI);
+ } else {
+ // Check if the constant is int32, if not skip it.
+ const MachineRegisterInfo &MRI = MI->getMF()->getRegInfo();
+ MachineInstr *TypeMI = MRI.getVRegDef(MI->getOperand(1).getReg());
+ if (!TypeMI || TypeMI->getOpcode() != SPIRV::OpTypeInt ||
+ TypeMI->getOperand(1).getImm() != 32)
+ continue;
+
+ if (OpCode == SPIRV::OpConstantI)
+ ConstMap[MI->getOperand(2).getImm()] = MI;
----------------
Keenuts wrote:
Ints could be signed, so here seems like you could end up with a `-1` being added as a max_uint or something like that no?
https://github.com/llvm/llvm-project/pull/146941
More information about the llvm-commits
mailing list