Skip to content

Commit

Permalink
[llvm-exegesis] Fix failing assert when creating Snippet for LAHF.
Browse files Browse the repository at this point in the history
Reviewers: courbet

Subscribers: tschuett, llvm-commits

Differential Revision: https://reviews.llvm.org/D48123

llvm-svn: 334599
  • Loading branch information
gchatelet committed Jun 13, 2018
1 parent 3e039f8 commit 60e3d58
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
16 changes: 10 additions & 6 deletions llvm/tools/llvm-exegesis/lib/MCInstrDescView.cpp
Expand Up @@ -208,13 +208,17 @@ static void randomize(const Variable &Var, llvm::MCOperand &AssignedValue) {
static void setRegisterOperandValue(const RegisterOperandAssignment &ROV,
InstructionInstance &II) {
assert(ROV.Op);
assert(ROV.Op->IsExplicit);
auto &AssignedValue = II.getValueFor(*ROV.Op);
if (AssignedValue.isValid()) {
assert(AssignedValue.isReg() && AssignedValue.getReg() == ROV.Reg);
return;
if (ROV.Op->IsExplicit) {
auto &AssignedValue = II.getValueFor(*ROV.Op);
if (AssignedValue.isValid()) {
assert(AssignedValue.isReg() && AssignedValue.getReg() == ROV.Reg);
return;
}
AssignedValue = llvm::MCOperand::createReg(ROV.Reg);
} else {
assert(ROV.Op->ImplicitReg != nullptr);
assert(ROV.Reg == *ROV.Op->ImplicitReg);
}
AssignedValue = llvm::MCOperand::createReg(ROV.Reg);
}

size_t randomBit(const llvm::BitVector &Vector) {
Expand Down
13 changes: 12 additions & 1 deletion llvm/unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp
Expand Up @@ -103,11 +103,22 @@ TEST_F(LatencySnippetGeneratorTest, DependencyThroughOtherOpcode) {

const unsigned Opcode = llvm::X86::CMP64rr;
auto Conf = checkAndGetConfiguration(Opcode);
EXPECT_THAT(Conf.Info, testing::HasSubstr("cycle through CMOVLE16rr"));
EXPECT_THAT(Conf.Info, testing::HasSubstr("cycle through"));
ASSERT_THAT(Conf.Snippet, testing::SizeIs(2));
const llvm::MCInst Instr = Conf.Snippet[0];
EXPECT_THAT(Instr.getOpcode(), Opcode);
// TODO: check that the two instructions alias each other.
}

TEST_F(LatencySnippetGeneratorTest, LAHF) {
const unsigned Opcode = llvm::X86::LAHF;
auto Conf = checkAndGetConfiguration(Opcode);
EXPECT_THAT(Conf.Info, testing::HasSubstr("cycle through"));
ASSERT_THAT(Conf.Snippet, testing::SizeIs(2));
const llvm::MCInst Instr = Conf.Snippet[0];
EXPECT_THAT(Instr.getOpcode(), Opcode);
}

class UopsSnippetGeneratorTest : public X86SnippetGeneratorTest {
protected:
UopsSnippetGeneratorTest() : Runner(State) {}
Expand Down

0 comments on commit 60e3d58

Please sign in to comment.