[llvm] 7c36fcf - [exegesis] SnippetRepetitor: don't deal with terminator instructions

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 7 18:15:17 PST 2022


Author: Roman Lebedev
Date: 2022-12-08T05:14:52+03:00
New Revision: 7c36fcfbbae1fc9b55257f621dbb0bc8d241e5c9

URL: https://github.com/llvm/llvm-project/commit/7c36fcfbbae1fc9b55257f621dbb0bc8d241e5c9
DIFF: https://github.com/llvm/llvm-project/commit/7c36fcfbbae1fc9b55257f621dbb0bc8d241e5c9.diff

LOG: [exegesis] SnippetRepetitor: don't deal with terminator instructions

These appear to be the only two crashing issues.
Afterwards, we seem to not crash for all opcodes in all repetition modes
in all measurement modes.

Otherwise, we get:
```
#
# Machine code for function foo: NoPHIs, TracksLiveness, NoVRegs

bb.0:
  successors: %bb.1(0x80000000); %bb.1(100.00%)

  $r8 = MOV64ri 2

bb.1:
; predecessors: %bb.0, %bb.1
  successors: %bb.1(0x80000000), %bb.2(0x00000000); %bb.1(100.00%), %bb.2(0.00%)
  liveins: $r8
  HLT
  HLT
  $r8 = ADD64ri8 $r8(tied-def 0), -1, implicit-def $eflags
  JCC_1 %bb.1, 5, implicit $eflags

bb.2:
; predecessors: %bb.1

  RET64

# End machine code for function foo.

*** Bad machine code: Non-terminator instruction after the first terminator ***
- function:    foo
- basic block: %bb.1  (0x55df06791048)
- instruction: $r8 = ADD64ri8 $r8(tied-def 0), -1, implicit-def $eflags
First terminator was:   HLT
LLVM ERROR: Found 1 machine code errors.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: bin/llvm-exegesis --skip-measurements -mode=uops --dump-object-to-disk=0 --repetition-mode=loop --loop-body-size=1000 --result-aggregation-mode=min --opcode-name=HLT --max-configs-per-opcode=8192
1.      Running pass 'Function Pass Manager' on module 'ExegesisInfoTest'.
2.      Running pass 'Verify generated machine code' on function '@foo'

```

Added: 
    llvm/test/tools/llvm-exegesis/X86/uops/uops-HLT.s

Modified: 
    llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-exegesis/X86/uops/uops-HLT.s b/llvm/test/tools/llvm-exegesis/X86/uops/uops-HLT.s
new file mode 100644
index 0000000000000..2b9a23e917b2c
--- /dev/null
+++ b/llvm/test/tools/llvm-exegesis/X86/uops/uops-HLT.s
@@ -0,0 +1,10 @@
+# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=uops -skip-measurements --dump-object-to-disk=0 --repetition-mode=loop --loop-body-size=1000 --result-aggregation-mode=min --opcode-name=HLT --max-configs-per-opcode=8192 | FileCheck %s
+
+# By definition, loop repetitor can not be used for terminator instructions.
+# Just check that we do not crash.
+
+CHECK:      ---
+CHECK-NEXT: mode: uops
+CHECK-NEXT: key:
+CHECK-NEXT:   instructions:
+CHECK-NEXT:     HLT

diff  --git a/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp b/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
index 1156b1c8eb3ad..bf05131e762d9 100644
--- a/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
+++ b/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
@@ -60,6 +60,17 @@ class LoopSnippetRepetitor : public SnippetRepetitor {
             LoopBodySize](FunctionFiller &Filler) {
       const auto &ET = State.getExegesisTarget();
       auto Entry = Filler.getEntry();
+
+      // We can not use loop snippet repetitor for terminator instructions.
+      for (const MCInst &Inst : Instructions) {
+        const unsigned Opcode = Inst.getOpcode();
+        const MCInstrDesc &MCID = Filler.MCII->get(Opcode);
+        if (!MCID.isTerminator())
+          continue;
+        Entry.addReturn();
+        return;
+      }
+
       auto Loop = Filler.addBasicBlock();
       auto Exit = Filler.addBasicBlock();
 


        


More information about the llvm-commits mailing list