[llvm] fd52305 - [exegesis] SnippetRepetitor: Don't access liveness if we disabled it

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


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

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

LOG: [exegesis] SnippetRepetitor: Don't access liveness if we disabled it

Otherwise, we get:
```
llvm-exegesis: /repositories/llvm-project/llvm/lib/CodeGen/MachineBasicBlock.cpp:1628: MachineBasicBlock::livein_iterator llvm::MachineBasicBlock::livein_begin() const: Assertion `getParent()->getProperties().hasProperty( MachineFunctionProperties::Property::TracksLiveness) && "Liveness information is accurate"' failed.
```

Added: 
    llvm/test/tools/llvm-exegesis/X86/latency/latency-CVTSD2SI64rr.s

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

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-exegesis/X86/latency/latency-CVTSD2SI64rr.s b/llvm/test/tools/llvm-exegesis/X86/latency/latency-CVTSD2SI64rr.s
new file mode 100644
index 0000000000000..ecc0853b2be96
--- /dev/null
+++ b/llvm/test/tools/llvm-exegesis/X86/latency/latency-CVTSD2SI64rr.s
@@ -0,0 +1,11 @@
+# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --skip-measurements -opcode-name=CVTSD2SI64rr -repetition-mode=loop --max-configs-per-opcode=8192 | FileCheck %s
+
+# We used to fail to setup the snippet, and that disabled liveness tracking
+# which we'd then tried to access during this run-line.
+# Just check that we don't crash
+
+CHECK:      ---
+CHECK-NEXT: mode: latency
+CHECK-NEXT: key:
+CHECK-NEXT:   instructions:
+CHECK-NEXT:     CVTSD2SI64rr

diff  --git a/llvm/tools/llvm-exegesis/lib/Assembler.cpp b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
index 84fd9295c76a8..0f8b765ab9613 100644
--- a/llvm/tools/llvm-exegesis/lib/Assembler.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
@@ -209,6 +209,7 @@ Error assembleToStream(const ExegesisTarget &ET,
 
   // If the snippet setup is not complete, we disable liveliness tracking. This
   // means that we won't know what values are in the registers.
+  // FIXME: this should probably be an assertion.
   if (!IsSnippetSetupComplete)
     Properties.reset(MachineFunctionProperties::Property::TracksLiveness);
 

diff  --git a/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp b/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
index 1851cb4674339..1156b1c8eb3ad 100644
--- a/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
+++ b/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
@@ -81,13 +81,17 @@ class LoopSnippetRepetitor : public SnippetRepetitor {
       // Set up the loop basic block.
       Entry.MBB->addSuccessor(Loop.MBB, BranchProbability::getOne());
       Loop.MBB->addSuccessor(Loop.MBB, BranchProbability::getOne());
-      // The live ins are: the loop counter, the registers that were setup by
-      // the entry block, and entry block live ins.
-      Loop.MBB->addLiveIn(LoopCounter);
-      for (unsigned Reg : Filler.getRegistersSetUp())
-        Loop.MBB->addLiveIn(Reg);
-      for (const auto &LiveIn : Entry.MBB->liveins())
-        Loop.MBB->addLiveIn(LiveIn);
+      // If the snippet setup completed, then we can track liveness.
+      if (Loop.MF.getProperties().hasProperty(
+              MachineFunctionProperties::Property::TracksLiveness)) {
+        // The live ins are: the loop counter, the registers that were setup by
+        // the entry block, and entry block live ins.
+        Loop.MBB->addLiveIn(LoopCounter);
+        for (unsigned Reg : Filler.getRegistersSetUp())
+          Loop.MBB->addLiveIn(Reg);
+        for (const auto &LiveIn : Entry.MBB->liveins())
+          Loop.MBB->addLiveIn(LiveIn);
+      }
       for (auto _ : seq(0U, LoopUnrollFactor)) {
         (void)_;
         Loop.addInstructions(Instructions);


        


More information about the llvm-commits mailing list