[LLVMdev] Removing metadata in a pass

Benjamin Kramer benny.kra at gmail.com
Fri Jul 18 02:25:39 PDT 2014


On Thu, Jul 17, 2014 at 11:48 PM, Mark Heffernan <meheff at google.com> wrote:
> Is it OK to remove metadata in an optimization pass?  The context is patch
> http://reviews.llvm.org/D4571 which removes loop unrolling hint metadata
> after using it to avoid unrolling more than the hint suggests.  This is a
> potential problem because loop unrolling can be run more than once.
> Example: a loop annotated with "#pragma clang loop unroll_count(2)" which
> adds hint metadata to the loop would be unrolled twice every time the loop
> unrolling pass is run.  Anyway, I ask about metadata removal because Eli who
> is reviewing the patch wasn't sure whether this was acceptable.
>
> Loop unrolling metadata can take the following forms:
> llvm.loop.unroll.enable false  // don't unroll
> llvm.loop.unroll.enable true  // try to fully unroll
> llvm.loop.unroll.count N  // try to unroll N times
>
> An alternative implementation to deleting nodes would be to just add a
> "llvm.loop.unroll.enable false" metadata node after unrolling.  It's a
> little funny because you could then have, say, both "llvm.loop.unroll.enable
> false" and "llvm.loop.unroll.enable true" attached to a loop which is a bit
> funny.  Yet another alternative is to make up some new metadata node type
> like "llvm.loop.unroll.already_unrolled" and add it to the loop.

In general metadata is designed so it can be safely dropped without
changing behavior of the resulting code. It can, however have an
effect on the optimizer. IMO dropping it is also the right thing to do
in your case as you fulfilled the request to unroll the loop.

- Ben



More information about the llvm-dev mailing list