This is an archive of the discontinued LLVM Phabricator instance.

[x86] machine combiner reassociation: mark EFLAGS operand as 'dead'
ClosedPublic

Authored by spatel on Jul 31 2015, 3:28 PM.

Details

Summary

In the commentary for D11660, I noted that I wasn't sure if it was alright to create new integer machine instructions without also creating the implicit EFLAGS operand. From what I can see, the implicit operand is always created by the MachineInstrBuilder based on the instruction type, so we don't have to do that explicitly. However, in reviewing the debug output, I noticed that the operand was not marked as 'dead'. I think the machine combiner should do that to preserve future optimization opportunities that may be checking for that dead EFLAGS operand themselves.

Diff Detail

Repository
rL LLVM

Event Timeline

spatel updated this revision to Diff 31173.Jul 31 2015, 3:28 PM
spatel retitled this revision from to [x86] machine combiner reassociation: mark EFLAGS operand as 'dead'.
spatel updated this object.
spatel added reviewers: Gerolf, kbsmith1, qcolombet.
spatel added a subscriber: llvm-commits.
Gerolf edited edge metadata.Jul 31 2015, 4:01 PM
Gerolf added a subscriber: Gerolf.

Why would reassociation result in dead eflags again? Because it can kick-in only when eflags are dead before reassoc, so they must be dead after? The comment should be clear about why setting the attribute is correct.

-Gerolf

kbsmith1 edited edge metadata.Jul 31 2015, 5:26 PM

LGTM after addressing Gerolf's comment.

kbsmith1 accepted this revision.Jul 31 2015, 5:26 PM
kbsmith1 edited edge metadata.
This revision is now accepted and ready to land.Jul 31 2015, 5:26 PM
spatel updated this revision to Diff 31241.Aug 3 2015, 9:09 AM
spatel edited edge metadata.

Patch updated:

  1. Added comment to better explain why the new operands must be dead.
  2. Added more asserts to verify that assumptions are intact.
  3. Split the EFLAGS check into its own function because eventually we'll want to hoist the non-architecture-specific logic into the MachineCombiner itself (there's already a TODO comment about this).
arphaman added inline comments.
test/CodeGen/X86/machine-combiner-int.ll
2 ↗(On Diff #31241)

Is there a specific reason you're using '-print-machineinstrs' instead of '-stop-after machine-combiner' here?

28 ↗(On Diff #31241)

This line would not be needed if you use the stop-after option that I mentioned above.

spatel added inline comments.Aug 3 2015, 3:06 PM
test/CodeGen/X86/machine-combiner-int.ll
2 ↗(On Diff #31241)

Nope - just wasn't aware of that option. I'll update the patch. Thanks for the suggestion!

spatel updated this revision to Diff 31274.Aug 3 2015, 3:09 PM

Patch updated: test case now uses '-stop-after machine-combiner' to be more efficient.

Gerolf accepted this revision.Aug 3 2015, 4:41 PM
Gerolf edited edge metadata.

Thanks for your follow-ups. I leave it up to you if you want to address my remaining comments.
LGTM.

lib/Target/X86/X86InstrInfo.cpp
6441 ↗(On Diff #31274)

How about: This is an ..... Set special operand attributes post re-association?

6443 ↗(On Diff #31274)

Would setSpecialOperandAttributes() be a better name?

6450 ↗(On Diff #31274)

Looks a bit of an overkill here.

spatel marked 2 inline comments as done.Aug 4 2015, 7:41 AM
spatel added inline comments.
lib/Target/X86/X86InstrInfo.cpp
6443 ↗(On Diff #31274)

Yes, that's a better name. Thanks!

6450 ↗(On Diff #31274)

Agree - it's assert-heavy. But I wanted to be extra safe for when some of the code gets hoisted up to the machine combiner. It may not be so obvious what the architecture-specific assumptions are at that point. I'll leave this in for now, and if it feels unnecessary later, we can get rid of it.

This revision was automatically updated to reflect the committed changes.
spatel marked an inline comment as done.