This is an archive of the discontinued LLVM Phabricator instance.

[Polly] Generate more 'canonical' induction variable if we can prove there is no overflow.
ClosedPublic

Authored by etherzhhb on May 10 2017, 8:53 PM.

Details

Summary

Today Polly generates induction variable in this way:

polly.indvar = phi 0, polly.indvar.next
...
polly.indvar.next = polly.indvar + stide
polly.loop_cond = predicate polly.indvar, (UB - stride)

Instead of:

polly.indvar = phi 0, polly.indvar.next
...
polly.indvar.next = polly.indvar + stide
polly.loop_cond = predicate polly.indvar.next, UB

The way Polly generate induction variable cause some problem in the indvar simplify pass.
This patch make polly generate the later form if possible

Diff Detail

Repository
rL LLVM

Event Timeline

etherzhhb created this revision.May 10 2017, 8:53 PM
grosser edited edge metadata.May 10 2017, 11:26 PM

I don't think checking with mayOverflowOnIV is needed. The types we use today are anyway just a guess, as we have no idea what type is needed. Consequently checking for possible overflows -- while we already may have some overflows just gives a wrong sense of security.

I think we should work towards what we want:

  1. code that matches what indvars would like to see
  2. code that is typesafe

Dropping this surprising subtract goes towards 1). Maximilian worked in his bachelor thesis on deriving precise types for the ASTs we generate. As a result of this work, he will derive a type that is large enough to contain UB, LB, as well as UB + Stride. Hence, as soon as his code is upstreamed, the code produced after this patch is valid. Hence, I would just add a comment at the top of this function, that we expect the type of UB, LB, UB+Stride to be large enough for values that UB may take throughout the execution of the loop, including the computation of indvar + Stride before the final abort..

I just posted to bug reports that cover are not directly related to this patch, but touch a very similar topic: http://llvm.org/PR32997, http://llvm.org/PR32998

etherzhhb updated this revision to Diff 98648.May 11 2017, 9:44 AM

Address Tobias's comment

grosser accepted this revision.May 11 2017, 10:52 AM

LGTM, assuming you update the commit message accordingly.

lib/CodeGen/LoopGenerators.cpp
26 ↗(On Diff #98649)

No need for these includes any more.

This revision is now accepted and ready to land.May 11 2017, 10:52 AM
This revision was automatically updated to reflect the committed changes.