This is an archive of the discontinued LLVM Phabricator instance.

[ForwardOpTree] Introduce the -polly-optree pass.
ClosedPublic

Authored by Meinersbur on Jul 21 2017, 6:57 PM.

Details

Summary

This pass 'forwards' operand trees into statements that use them in order to avoid scalar dependencies.

This minimal implementation handles only the case of speculatable instructions. We will successively add support for:

  • Hoisted loads
  • Read-only values
  • Synthesizable values
  • Loads
  • PHIs
  • Forwarding only parts of the tree

Diff Detail

Event Timeline

Meinersbur created this revision.Jul 21 2017, 6:57 PM
grosser accepted this revision.Jul 21 2017, 10:40 PM
grosser added inline comments.
lib/Transform/ForwardOpTree.cpp
47

and ALL THE operand tree

This revision is now accepted and ready to land.Jul 21 2017, 10:40 PM

One more typo.

lib/Transform/ForwardOpTree.cpp
296

increases

This revision was automatically updated to reflect the committed changes.

Could you please explain what is the meaning of 'forwarding' of operand trees?

polly/trunk/include/polly/ScopInfo.h
1595 ↗(On Diff #107785)

*Instruction

bollu added inline comments.Jul 24 2017, 2:26 AM
polly/trunk/lib/Transform/ForwardOpTree.cpp
108 ↗(On Diff #107785)

@Meinersbur - Is the comment incorrect?

When DoIt == true, does it not return FD_DidForward / FD_DidNotFowrard

And when DoIt == false, it returns FD_CanForward ?

I am basing this off of this piece of code:

snippet-with-do-it-returns.cpp
if (DoIt)
  return FD_DidForward;
return FD_CanForward;

Could you please explain what is the meaning of 'forwarding' of operand trees?

Suppose you have two statements:

StmtA:
  %add = fadd double 21.0,21.0
  bl label %StmtB

StmtB:
  store double %add, double*A

This would induce a scalar dependency from %StmtA to %StmtB. To avoid, we can recompute %add in %StmtB instead:

StmtA:
  %add = fadd double 21.0,21.0
  bl label %StmtB

StmtB:
  %add_ = fadd double 21.0,21.0
  store double %add_, double*A

This "forwards" %add (and its operand tree/DAG) to StmtB.

I am open to naming it differently. I considered "reverse code motion".

polly/trunk/include/polly/ScopInfo.h
1595 ↗(On Diff #107785)

Thanks.

Could you please explain what is the meaning of 'forwarding' of operand trees?

Suppose you have two statements:

StmtA:
  %add = fadd double 21.0,21.0
  bl label %StmtB

StmtB:
  store double %add, double*A

This would induce a scalar dependency from %StmtA to %StmtB. To avoid, we can recompute %add in %StmtB instead:

StmtA:
  %add = fadd double 21.0,21.0
  bl label %StmtB

StmtB:
  %add_ = fadd double 21.0,21.0
  store double %add_, double*A

This "forwards" %add (and its operand tree/DAG) to StmtB.

Thank you. This is really nice idea. Do you have some cost modeling for when to allow this forwarding?

I am open to naming it differently. I considered "reverse code motion".

Thank you. This is really nice idea. Do you have some cost modeling for when to allow this forwarding?

There is no cost modeling (yet), it is assumed to be always beneficial. The GVN pass should later be able do remove instruction duplication and move them back to cheaper places again.