@@ -612,13 +612,10 @@ void SPIRVAsmPrinter::outputExecutionMode(const Module &M) {
612612 // Collect the SPIRVTypes for fp16, fp32, and fp64 and the constant of
613613 // type int32 with 0 value to represent the FP Fast Math Mode.
614614 std::vector<const MachineInstr *> SPIRVFloatTypes;
615- const MachineInstr *ConstZero = nullptr ;
615+ const MachineInstr *ConstZeroInt32 = nullptr ;
616616 for (const MachineInstr *MI :
617617 MAI->getMSInstrs (SPIRV::MB_TypeConstVars)) {
618- // Skip if the instruction is not OpTypeFloat or OpConstant.
619618 unsigned OpCode = MI->getOpcode ();
620- if (OpCode != SPIRV::OpTypeFloat && OpCode != SPIRV::OpConstantNull)
621- continue ;
622619
623620 // Collect the SPIRV type if it's a float.
624621 if (OpCode == SPIRV::OpTypeFloat) {
@@ -629,14 +626,18 @@ void SPIRVAsmPrinter::outputExecutionMode(const Module &M) {
629626 continue ;
630627 }
631628 SPIRVFloatTypes.push_back (MI);
632- } else {
629+ continue ;
630+ }
631+
632+ if (OpCode != SPIRV::OpConstantNull) {
633633 // Check if the constant is int32, if not skip it.
634634 const MachineRegisterInfo &MRI = MI->getMF ()->getRegInfo ();
635635 MachineInstr *TypeMI = MRI.getVRegDef (MI->getOperand (1 ).getReg ());
636- if (!TypeMI || TypeMI->getOperand (1 ).getImm () != 32 )
637- continue ;
638-
639- ConstZero = MI;
636+ bool IsInt32Ty = TypeMI &&
637+ TypeMI->getOpcode () == SPIRV::OpTypeInt &&
638+ TypeMI->getOperand (1 ).getImm () == 32 ;
639+ if (IsInt32Ty)
640+ ConstZeroInt32 = MI;
640641 }
641642 }
642643
@@ -657,9 +658,9 @@ void SPIRVAsmPrinter::outputExecutionMode(const Module &M) {
657658 MCRegister TypeReg =
658659 MAI->getRegisterAlias (MF, MI->getOperand (0 ).getReg ());
659660 Inst.addOperand (MCOperand::createReg (TypeReg));
660- assert (ConstZero && " There should be a constant zero." );
661+ assert (ConstZeroInt32 && " There should be a constant zero." );
661662 MCRegister ConstReg = MAI->getRegisterAlias (
662- ConstZero ->getMF (), ConstZero ->getOperand (0 ).getReg ());
663+ ConstZeroInt32 ->getMF (), ConstZeroInt32 ->getOperand (0 ).getReg ());
663664 Inst.addOperand (MCOperand::createReg (ConstReg));
664665 outputMCInst (Inst);
665666 }
0 commit comments