@@ -612,18 +612,23 @@ void GIMatchTreeOpcodePartitioner::emitPartitionResults(
612612
613613void GIMatchTreeOpcodePartitioner::generatePartitionSelectorCode (
614614 raw_ostream &OS, StringRef Indent) const {
615- OS << Indent << " Partition = -1;\n "
616- << Indent << " switch (MIs[" << InstrID << " ]->getOpcode()) {\n " ;
617- for (const auto &EnumInstr : enumerate(PartitionToInstr)) {
618- if (EnumInstr.value () == nullptr )
619- OS << Indent << " default:" ;
620- else
621- OS << Indent << " case " << EnumInstr.value ()->Namespace
622- << " ::" << EnumInstr.value ()->TheDef ->getName () << " :" ;
623- OS << " Partition = " << EnumInstr.index () << " ; break;\n " ;
615+ // Make sure not to emit empty switch or switch with just default
616+ if (PartitionToInstr.size () == 1 && PartitionToInstr[0 ] == nullptr ) {
617+ OS << Indent << " Partition = 0;\n " ;
618+ } else if (PartitionToInstr.size ()) {
619+ OS << Indent << " Partition = -1;\n "
620+ << Indent << " switch (MIs[" << InstrID << " ]->getOpcode()) {\n " ;
621+ for (const auto &EnumInstr : enumerate(PartitionToInstr)) {
622+ if (EnumInstr.value () == nullptr )
623+ OS << Indent << " default:" ;
624+ else
625+ OS << Indent << " case " << EnumInstr.value ()->Namespace
626+ << " ::" << EnumInstr.value ()->TheDef ->getName () << " :" ;
627+ OS << " Partition = " << EnumInstr.index () << " ; break;\n " ;
628+ }
629+ OS << Indent << " }\n " ;
624630 }
625- OS << Indent << " }\n "
626- << Indent
631+ OS << Indent
627632 << " // Default case but without conflicting with potential default case "
628633 " in selection.\n "
629634 << Indent << " if (Partition == -1) return false;\n " ;
@@ -775,4 +780,3 @@ void GIMatchTreeVRegDefPartitioner::generatePartitionSelectorCode(
775780
776781 OS << Indent << " if (Partition == -1) return false;\n " ;
777782}
778-
0 commit comments