This is an archive of the discontinued LLVM Phabricator instance.

[X86] Fix updating LiveVariables in convertToThreeAddress
ClosedPublic

Authored by foad on Jul 13 2022, 5:22 AM.

Details

Summary

Fix all instances of:

  • Bad machine code: Kill missing from LiveVariables ***

in the X86 CodeGen tests with D129213 applied, which adds verification
of LiveIntervals after the TwoAddressInstruction pass runs.

Diff Detail

Event Timeline

foad created this revision.Jul 13 2022, 5:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 13 2022, 5:22 AM
foad requested review of this revision.Jul 13 2022, 5:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 13 2022, 5:22 AM
foad added inline comments.
llvm/lib/Target/X86/X86InstrInfo.cpp
1390–1393

I'm not proud of this patch because it adds duplicated code like this after almost every call to classifyLEAReg. There may be better ways to do this, by completely rethinking the way that convertToThreeAddress updates LiveVariables.

On the other hand LiveVariables is supposed to go away in favour of LiveIntervals, so does it really matter?

MatzeB accepted this revision.Jul 18 2022, 9:58 AM

Added some suggestions. Either way LGTM

llvm/lib/Target/X86/X86InstrInfo.cpp
1390–1394

Can't we just use the already computed isKill here?

1425–1426

as above

1450–1454

as above

1502–1505

Shouldn't this just correspond to the kill flags used in line 1494?

1548
This revision is now accepted and ready to land.Jul 18 2022, 9:58 AM
foad added inline comments.Jul 25 2022, 5:17 AM
llvm/lib/Target/X86/X86InstrInfo.cpp
1390–1394

Yes this works. I didn't do it that way because it will add duplicates in the Kills lists, because the call to replaceKillInstruction below will also add them (in the case that SrcReg == Src.getReg(), i.e. classifyLEAReg did not create a new register), but that does not seem to cause any problems in practice. What do you prefer?

MatzeB added inline comments.Jul 25 2022, 8:43 AM
llvm/lib/Target/X86/X86InstrInfo.cpp
1390–1394

I see, makes sense. Maybe hint at it with a comment then?

// Record kill in cases where we don't call `replaceKillInstruction` later.
if (LV && SrcReg != Src.getReg())
  LV->getVarInfo(SrcReg).Kills.push_back(NewMI);
foad updated this revision to Diff 447642.Jul 26 2022, 4:15 AM

Add comments.

This revision was landed with ongoing or failed builds.Aug 1 2022, 5:52 AM
This revision was automatically updated to reflect the committed changes.