This is an archive of the discontinued LLVM Phabricator instance.

[OpenCL] Generate 'unroll.enable' metadata for __attribute__((opencl_unroll_hint))
ClosedPublic

Authored by sidorovd on Mar 18 2019, 8:20 AM.

Details

Summary

[OpenCL] Generate 'unroll.enable' metadata for attribute((opencl_unroll_hint))

For both !{!"llvm.loop.unroll.enable"} and !{!"llvm.loop.unroll.full"} the unroller
will try to fully unroll a loop unless the trip count is not known at compile time.
In that case for '.full' metadata no unrolling will be processed, while for '.enable'
the loop will be partially unrolled with a heuristically chosen unroll factor.

See: docs/LanguageExtensions.rst

From https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/attributes-loopUnroll.html

__attribute__((opencl_unroll_hint))
for (int i=0; i<2; i++)
{
    ...
}

In the example above, the compiler will determine how much to unroll the loop.

Before the patch for attribute((opencl_unroll_hint)) was generated metadata
!{!"llvm.loop.unroll.full"}, which limits ability of loop unroller to decide, how
much to unroll the loop.

Diff Detail

Repository
rC Clang

Event Timeline

sidorovd created this revision.Mar 18 2019, 8:20 AM
sidorovd edited the summary of this revision. (Show Details)Mar 18 2019, 8:21 AM
Anastasia accepted this revision.Mar 18 2019, 8:37 AM

LGTM! Thanks!

The wording in spec is confusing btw because it says:

This attribute qualifier can be used to specify full unrolling or partial unrolling by a specified amount.

May be we should fix this.

This revision is now accepted and ready to land.Mar 18 2019, 8:37 AM

PS, I am just saying that I guess leaving this to the compiler is more helpful than explicitly requiring the full unroll. However, spec contradicts itself by first mentioning the full unroll and then stating that compiler will determines the unrolling factor.

This revision was automatically updated to reflect the committed changes.