[llvm] [RISCV][MC] Prioritize features in MultiMismatchFallback (PR #215737)

Garvit Gupta via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 05:25:30 PDT 2026


================
@@ -4127,35 +4147,49 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
     OS << "      // Too many invalid operands to report a single near-miss;\n";
     OS << "      // keep the first one as a fallback in case no opcode\n";
     OS << "      // matches more closely.\n";
-    OS << "      if (OperandNearMiss)\n";
-    OS << "        MultiMismatchFallback.push_back(OperandNearMiss);\n";
+    if (PrioritizeFeatureInMultipleNearMisses) {
+      OS << "      // If the opcode also has missing features, promote the\n";
+      OS << "      // feature near-miss instead of the operand near-miss so\n";
+      OS << "      // that the diagnostic points to the missing extension.\n";
+      OS << "      if (FeaturesNearMiss)\n";
+      OS << "        MultiMismatchFallback.push_back(FeaturesNearMiss);\n";
+      OS << "      else if (OperandNearMiss)\n";
+      OS << "        MultiMismatchFallback.push_back(OperandNearMiss);\n";
+    } else {
+      OS << "      if (OperandNearMiss)\n";
+      OS << "        MultiMismatchFallback.push_back(OperandNearMiss);\n";
+    }
   }
   OS << "      continue;\n";
   OS << "    }\n";
 
-  // Emit check that the required features are available.
-  OS << "    if (!HasRequiredFeatures) {\n";
-  if (!ReportMultipleNearMisses)
-    OS << "      HadMatchOtherThanFeatures = true;\n";
-  OS << "      FeatureBitset NewMissingFeatures = RequiredFeatures & "
-        "~AvailableFeatures;\n";
-  OS << "      DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Missing target "
-        "features:\";\n";
-  OS << "                      for (unsigned I = 0, E = "
-        "NewMissingFeatures.size(); I != E; ++I)\n";
-  OS << "                        if (NewMissingFeatures[I])\n";
-  OS << "                          dbgs() << ' ' << I;\n";
-  OS << "                      dbgs() << \"\\n\");\n";
-  if (ReportMultipleNearMisses) {
-    OS << "      FeaturesNearMiss = "
-          "NearMissInfo::getMissedFeature(NewMissingFeatures);\n";
-  } else {
-    OS << "      if (NewMissingFeatures.count() <=\n"
-          "          MissingFeatures.count())\n";
-    OS << "        MissingFeatures = NewMissingFeatures;\n";
-    OS << "      continue;\n";
+  if (!PrioritizeFeatureInMultipleNearMisses) {
+    // Emit check that the required features are available.
+    OS << "    if (!HasRequiredFeatures) {\n";
----------------
quic-garvgupt wrote:

>From line 4168-4191, this can be defined inside a lambda function and be called wherever it is needed because the same logic is duplicated above as well starting from line 4119.

https://github.com/llvm/llvm-project/pull/215737


More information about the llvm-commits mailing list