Skip to content

Commit 6ba6dff

Browse files
author
Francis Visoiu Mistrih
committed
[CodeGen] Fix InstructionCount remarks for MI bundles
For MI bundles, the instruction count remark doesn't count the instructions inside the bundle.
1 parent 2bf2468 commit 6ba6dff

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,6 @@ void AsmPrinter::emitFunctionBody() {
17241724
if (!MI.isPosition() && !MI.isImplicitDef() && !MI.isKill() &&
17251725
!MI.isDebugInstr()) {
17261726
HasAnyRealCode = true;
1727-
++NumInstsInFunction;
17281727
}
17291728

17301729
// If there is a pre-instruction symbol, emit a label for it here.
@@ -1816,11 +1815,22 @@ void AsmPrinter::emitFunctionBody() {
18161815
default:
18171816
emitInstruction(&MI);
18181817
if (CanDoExtraAnalysis) {
1819-
MCInst MCI;
1820-
MCI.setOpcode(MI.getOpcode());
1821-
auto Name = OutStreamer->getMnemonic(MCI);
1822-
auto I = MnemonicCounts.insert({Name, 0u});
1823-
I.first->second++;
1818+
auto CountInstruction = [&](unsigned Opcode) {
1819+
MCInst MCI;
1820+
MCI.setOpcode(Opcode);
1821+
auto Name = OutStreamer->getMnemonic(MCI);
1822+
++MnemonicCounts[Name];
1823+
++NumInstsInFunction;
1824+
};
1825+
if (!MI.isBundle()) {
1826+
CountInstruction(MI.getOpcode());
1827+
break;
1828+
}
1829+
// Separately count all the instructions in a bundle.
1830+
for (auto It = std::next(MI.getIterator());
1831+
It != MBB.end() && It->isInsideBundle(); ++It) {
1832+
CountInstruction(It->getOpcode());
1833+
}
18241834
}
18251835
break;
18261836
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# RUN: llc -mtriple=riscv32 -verify-machineinstrs -start-before=riscv-expand-pseudo -simplify-mir -o /dev/null -pass-remarks-analysis=asm-printer %s 2>&1 | FileCheck %s
2+
---
3+
name: instrs
4+
tracksRegLiveness: true
5+
body: |
6+
bb.0:
7+
$x0 = ADDI $x0, 0
8+
$x0 = ADDI $x0, 0
9+
$x0 = ADDI $x0, 0
10+
$x0 = LW $x0, 0
11+
$x0 = LW $x0, 0
12+
$x0 = XORI $x0, 0
13+
; CHECK: addi : 3
14+
; CHECK-NEXT: lw : 2
15+
; CHECK-NEXT: xori : 1
16+
; CHECK: 6 instructions in function
17+
...
18+
---
19+
name: bundles
20+
tracksRegLiveness: true
21+
body: |
22+
bb.0:
23+
$x0 = ADDI $x0, 0
24+
BUNDLE {
25+
$x0 = ADDI $x0, 0
26+
$x0 = ADDI $x0, 0
27+
$x0 = LW $x0, 0
28+
}
29+
$x0 = LW $x0, 0
30+
$x0 = XORI $x0, 0
31+
; CHECK: addi : 3
32+
; CHECK-NEXT: lw : 2
33+
; CHECK-NEXT: xori : 1
34+
; CHECK: 6 instructions in function
35+
...

0 commit comments

Comments
 (0)