[LLVMdev] llvm.loop metadata placement and critical edge splitting

hadi sadeghi hasadegh at elis.ugent.be
Tue Oct 7 05:39:29 PDT 2014


> > >> I think fixing this may be an easy change to LoopInfo get/setLoopID.
> > >> The rule would be simple, if the loop back branch is unconditional, 
> > >> and it has a single predecessor, the metadata is expected on the 
> > >> predecessaor's conditional branch:
> > >>
> > >> loop.body:
> > >>    ...
> > >>    br i1 %c, label %loop.tail, label %exit, !llvm.loop
> > >>
> > >> loop.tail:
> > >>    ...
> > >>    br label %loop.body
> > >>
> > >> exit:
> > >>    ret
> > >>
> > >> If the loop tail does not have a single predecessor (complex control 
> > >> flow occurs after the loop test), then the metadata can still be 
> > >> placed on the unconditional branch. Either way, we don't need to 
> > >> worry about edge splitting. Only a signficant loop restructuring will 
> > >> invalidate the metadata.
> > >>
> > >> I don't think any change is necessary when clang emits a loop with an 
> > >> unconditional backedge, but someone will want to verify with some 
> > >> test cases. If a change is needed it should also be easy.
> > >>

I have couple of questions regarding this proposal, does not it change
llvm's standard Loop structure ? I guess some optimizations working around 
standard loop structure. another issue could be that simplify-cfg might
optimize out such an unconditional branch (I am not sure about it). 
I was working around preserving loop metadata for while, our proposal was to
attach loop metadata to both, back-edge and loop's phi nodes (phi nodes at
the start of loop Header), since in SSA from, a loop can be identified by
its phi nodes. this solution worked for us, but our benchmarks were limited
to MPEG and H264. do you think this could be considered as a general solution ?

Best,
Hadi 





More information about the llvm-dev mailing list