Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ class DuplicateSnippetRepetitor : public SnippetRepetitor {
if (!Instructions.empty()) {
// Add the whole snippet at least once.
Entry.addInstructions(Instructions);
for (unsigned I = Instructions.size(); I < MinInstructions; ++I) {
unsigned FullInstructionCount = MinInstructions;
if (FullInstructionCount % Instructions.size() != 0)
FullInstructionCount +=
Instructions.size() - (MinInstructions % Instructions.size());
for (unsigned I = Instructions.size(); I < FullInstructionCount; ++I) {
Entry.addInstruction(Instructions[I % Instructions.size()]);
}
}
Expand Down
18 changes: 16 additions & 2 deletions llvm/unittests/tools/llvm-exegesis/X86/SnippetRepetitorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ class X86SnippetRepetitorTest : public X86TestBase {
MF = &createVoidVoidPtrMachineFunction("TestFn", Mod.get(), MMI.get());
}

void TestCommon(Benchmark::RepetitionModeE RepetitionMode) {
void TestCommon(Benchmark::RepetitionModeE RepetitionMode,
unsigned SnippetInstructions = 1) {
const auto Repetitor = SnippetRepetitor::Create(RepetitionMode, State);
const std::vector<MCInst> Instructions = {MCInstBuilder(X86::NOOP)};
const std::vector<MCInst> Instructions(SnippetInstructions,
MCInstBuilder(X86::NOOP));
FunctionFiller Sink(*MF, {X86::EAX});
const auto Fill =
Repetitor->Repeat(Instructions, kMinInstructions, kLoopBodySize, false);
Expand Down Expand Up @@ -74,6 +76,18 @@ TEST_F(X86SnippetRepetitorTest, Duplicate) {
HasOpcode(X86::NOOP), HasOpcode(X86::RET64)));
}

TEST_F(X86SnippetRepetitorTest, DuplicateSnippetInstructionCount) {
TestCommon(Benchmark::Duplicate, 2);
// Duplicating a snippet of two instructions with the minimum number of
// instructions set to three duplicates the snippet twice for a total of
// four instructions.
ASSERT_EQ(MF->getNumBlockIDs(), 1u);
EXPECT_THAT(MF->getBlockNumbered(0)->instrs(),
ElementsAre(HasOpcode(X86::NOOP), HasOpcode(X86::NOOP),
HasOpcode(X86::NOOP), HasOpcode(X86::NOOP),
HasOpcode(X86::RET64)));
}

TEST_F(X86SnippetRepetitorTest, Loop) {
TestCommon(Benchmark::Loop);
// Duplicating creates an entry block, a loop body and a ret block.
Expand Down