This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombine] Deduplicate addcarry node using commutativity.
ClosedPublic

Authored by deadalnix on Jan 28 2019, 2:34 AM.

Details

Summary

The first two parameters of addcarry are commutative. We may face a situation where both variant are present in the DAG, in which case we benefit from using just one.

Depends on D57302 and D33587

Diff Detail

Event Timeline

deadalnix created this revision.Jan 28 2019, 2:34 AM
RKSimon added inline comments.Jan 28 2019, 4:31 AM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
2527 ↗(On Diff #183811)

We already do this in DAGCombiner::combine for plain commutative binops, is it worth generalizing that code?

deadalnix marked an inline comment as done.Jan 28 2019, 6:10 AM
deadalnix added inline comments.
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
2527 ↗(On Diff #183811)

The problem is that this is not a binary operation so it doesn't fit in the existing machinery. If this end up being common enough, we can generalize.

RKSimon added inline comments.Jan 28 2019, 6:56 AM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
2527 ↗(On Diff #183811)

OK - please add a TODO suggesting this. Should the ConstantSDNode handling be done here as well?

deadalnix marked an inline comment as done.Jan 28 2019, 10:30 AM
deadalnix added inline comments.
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
2527 ↗(On Diff #183811)

You mean moving a constant argument on RHS when it is on RHS ?

RKSimon added inline comments.Jan 28 2019, 10:37 AM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
2527 ↗(On Diff #183811)

yes

deadalnix updated this revision to Diff 183965.Jan 28 2019, 2:52 PM

Add a comment about existing commutative ops deduplication logic.

This revision is now accepted and ready to land.Jan 29 2019, 12:51 AM

@deadalnix Can this go in now or would you prefer to wait for D33587?

Herald added a project: Restricted Project. · View Herald TranscriptFeb 7 2019, 4:44 AM

@RKSimon This can go now, but has no effect in isolation in any of the test cases I have, mainly because DAGCombine is fairly powerless when faced with addcarry as most of the work involve 'deep' patterns. Do you think I should land anyways ?

@RKSimon This can go now, but has no effect in isolation in any of the test cases I have, mainly because DAGCombine is fairly powerless when faced with addcarry as most of the work involve 'deep' patterns. Do you think I should land anyways ?

Unless you can add test coverage now I think this will have to wait.

@deadalnix What is the state of this patch now?

deadalnix updated this revision to Diff 207928.Jul 3 2019, 5:00 PM

Rebased on top of D64174 , which expose many instances of this pattern.

deadalnix updated this revision to Diff 426311.May 1 2022, 2:11 PM

Update for the monorepo

Herald added a project: Restricted Project. · View Herald TranscriptMay 1 2022, 2:11 PM

@deadalnix Is this likely to be committed anytime soon ?

@RKSimon It is good to go, the main problem here is that I don't have a test case for it in isolation, and I have been struggling to get the pieces in where this really shines (mostly related to process the DAG topologically).

chfast added a subscriber: chfast.Aug 23 2022, 12:08 AM
chfast updated this revision to Diff 464508.Oct 1 2022, 10:34 AM

Rebased.

chfast accepted this revision.Oct 1 2022, 10:38 AM
RKSimon accepted this revision.Oct 1 2022, 1:59 PM

Thanks @chfast!

Is it fine I commit this?

Is it fine I commit this?

Sure, but please make sure you tag it by Amaury Séchet <deadalnix@gmail.com>

This revision was landed with ongoing or failed builds.Oct 7 2022, 3:55 PM
This revision was automatically updated to reflect the committed changes.