[PATCH] D28460: getLoopEstimatedTripCount should really be called getLoopEstimatedBackedgeTakeCount.

Xin Tong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 9 16:17:24 PST 2017


trentxintong added a comment.

In https://reviews.llvm.org/D28460#639985, @mkuper wrote:

> > In case the loop is bottom tested (rotated), there would be an off-by-1, as the loop body is executed backedge-count + 1 times.
> >  If its not bottom tested, we would not have this profile data on the latch, right ? I would assume the latch simply branches back to the header and the test is in the header.
>
> Hm, yes, that sounds right.
>
> I'm still not sure why we get seemingly correct results with the current code, though. :-)
>  One option is that we don't. But if we do - maybe we don't update profile metadata correctly in loop rotation?


I am pretty sure its a problem with loop rotation, basically when we duplicate and move the terminator in the header, we did not update the prof metadata correctly. With the example @danielcdh gives me, right after rotation I am getting this. The !prof in guard block is definitely incorrect, the one in the latch block is not correct either I think. I am working on fixing this.

define void @_Z3fooi(i32 %a) local_unnamed_addr #0 !prof !29 {
entry:

  %tobool2 = icmp eq i32 %a, 0
  br i1 %tobool2, label %while.end, label %while.body, !prof !30

while.body:                                       ; preds = %entry, %while.body

  %a.addr.03 = phi i32 [ %call, %while.body ], [ %a, %entry ]
  %call = tail call i32 @_Z3bari(i32 %a.addr.03)
  %tobool = icmp eq i32 %call, 0
  br i1 %tobool, label %while.end, label %while.body, !prof !30

while.end:                                        ; preds = %while.body, %entry

  ret void 

}

!30 = !{!"branch_weights", i32 2, i32 10}


https://reviews.llvm.org/D28460





More information about the llvm-commits mailing list