Skip to content

Commit

Permalink
Explicitly define df register (#263)
Browse files Browse the repository at this point in the history
Now that llvm-exegesis has support for explicitly setting the df register, we should explicitly define df rather than eflags/rflags when something in the block uses df. This fixes a MC verification error when using the loop snippet repetitor due to implicitly defined registers not being set as live-ins.
  • Loading branch information
boomanaiden154 authored Nov 18, 2024
1 parent 4c9d7b7 commit dc456ad
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
6 changes: 0 additions & 6 deletions gematria/datasets/basic_block_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ namespace gematria {

unsigned getSuperRegister(unsigned OriginalRegister,
const MCRegisterInfo &RegisterInfo) {
// Sections of EFLAGS that are explicitly modeled by LLVM as separate
// registers should all return eflags.
if (OriginalRegister == X86::EFLAGS || OriginalRegister == X86::DF) {
return X86::EFLAGS;
}

// We should be able to get the super register by getting an iterator from
// RegisterInfo and getting the back, but this always returns a value of
// zero.
Expand Down
3 changes: 1 addition & 2 deletions gematria/datasets/basic_block_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ TEST_F(BasicBlockUtilsTest, MovsqImplicitDfUsesEflags) {
std::vector<unsigned> UsedRegisters = getUsedRegs(R"asm(
movsq
)asm");
EXPECT_THAT(UsedRegisters,
UnorderedElementsAre(X86::RSI, X86::RDI, X86::EFLAGS));
EXPECT_THAT(UsedRegisters, UnorderedElementsAre(X86::RSI, X86::RDI, X86::DF));
}

TEST_F(BasicBlockUtilsTest, UnusedGPRegisterSingleInstruction) {
Expand Down
2 changes: 1 addition & 1 deletion gematria/datasets/find_accessed_addrs_exegesis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Expected<ExecutionAnnotations> ExegesisAnnotator::findAccessedAddrs(
RegVal.Value = APInt(32, kInitialRegVal);
NewRegisterValue->set_register_value(kInitialRegVal);
} else if (RegisterIndex == X86::EFLAGS || RegisterIndex == X86::MXCSR ||
RegisterIndex == X86::FPCW) {
RegisterIndex == X86::FPCW || RegisterIndex == X86::DF) {
RegVal.Value = APInt(32, 0);
NewRegisterValue->set_register_value(0);
} else if (MRI.getRegClass(X86::RFP32RegClassID).contains(RegisterIndex)) {
Expand Down
3 changes: 3 additions & 0 deletions gematria/datasets/find_accessed_addrs_exegesis_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ TEST_F(FindAccessedAddrsExegesisTest, DFRegister) {
movsq
)asm");
ASSERT_TRUE(static_cast<bool>(AddrsOrErr));
EXPECT_THAT(AddrsOrErr->initial_registers(),
Contains(Property("register_name",
&RegisterAndValue::register_name, "DF")));
}

// Test that we can annotate snippets using various different register
Expand Down

0 comments on commit dc456ad

Please sign in to comment.