[llvm] [CodeGen] Fix InstructionCount remarks for MI bundles (PR #107621)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 11 06:07:07 PDT 2024


================
@@ -1845,12 +1844,23 @@ void AsmPrinter::emitFunctionBody() {
         break;
       default:
         emitInstruction(&MI);
-        if (CanDoExtraAnalysis) {
-          MCInst MCI;
-          MCI.setOpcode(MI.getOpcode());
-          auto Name = OutStreamer->getMnemonic(MCI);
-          auto I = MnemonicCounts.insert({Name, 0u});
-          I.first->second++;
+        auto CountInstruction = [&](unsigned Opcode) {
+          ++NumInstsInFunction;
+          if (CanDoExtraAnalysis) {
+            MCInst MCI;
+            MCI.setOpcode(Opcode);
+            auto Name = OutStreamer->getMnemonic(MCI);
+            ++MnemonicCounts[Name];
+          }
+        };
+        if (!MI.isBundle()) {
+          CountInstruction(MI.getOpcode());
+          break;
+        }
+        // Separately count all the instructions in a bundle.
----------------
arsenm wrote:

It's not clear to me what this remark is supposed to mean exactly, but this is probably fine.

There's a few more consistency bugs here. This is not skipping implicit_def/kill/debug instrs like the code above. But the code above is also buggy, since it should be using isMetaInstruction 

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


More information about the llvm-commits mailing list