This is an archive of the discontinued LLVM Phabricator instance.

Add new llvm.loop.unroll.enable metadata which is now generated by "#pragma unroll" directive
ClosedPublic

Authored by meheff on Aug 3 2015, 3:37 PM.

Details

Summary

This change adds the new unroll metadata "llvm.loop.unroll.enable" which directs
the optimizer to unroll a loop fully if the trip count is known at compile time, and
unroll partially if the trip count is not known at compile time. This differs from
"llvm.loop.unroll.full" which explicitly does not unroll a loop if the trip count is not
known at compile time

With this change "#pragma unroll" generates "llvm.loop.unroll.enable" rather than
"llvm.loop.unroll.full" metadata. This changes the semantics of "#pragma unroll" slightly
to mean "unroll aggressively (fully or partially)" rather than "unroll fully or not at all".

The motivating example for this change was some internal code with a loop marked
with "#pragma unroll" which only sometimes had a compile-time trip count depending
on template magic. When the trip count was a compile-time constant, everything works
as expected and the loop is fully unrolled. However, when the trip count was not a
compile-time constant the "#pragma unroll" explicitly disabled unrolling of the loop(!).
Removing "#pragma unroll" caused the loop to be unrolled partially which was desirable
from a performance perspective.

Optimizer patch will follow shortly.

Diff Detail

Event Timeline

meheff updated this revision to Diff 31277.Aug 3 2015, 3:37 PM
meheff retitled this revision from to Add new llvm.loop.unroll.enable metadata which is now generated by "#pragma unroll" directive .
meheff updated this object.
meheff added reviewers: tyler.nowicki, hfinkel.
meheff added subscribers: cfe-commits, llvm-commits.
tyler.nowicki edited edge metadata.Aug 5 2015, 2:13 AM
tyler.nowicki added a subscriber: tyler.nowicki.

Hi Mark,

The patch LGTM!

Tyler

meheff added a comment.Aug 7 2015, 5:02 PM

Ping, Hal? Thanks!

hfinkel accepted this revision.Aug 9 2015, 9:17 PM
hfinkel edited edge metadata.

LGTM, but obviously any necessary CodeGen changes must be done first (or at the same time).

This revision is now accepted and ready to land.Aug 9 2015, 9:17 PM
meheff closed this revision.Aug 10 2015, 10:31 AM

Thanks!