[llvm] r206860 - blockfreq: Skip irreducible backedges inside functions

Duncan P. N. Exon Smith dexonsmith at apple.com
Mon Apr 21 20:31:53 PDT 2014


Author: dexonsmith
Date: Mon Apr 21 22:31:53 2014
New Revision: 206860

URL: http://llvm.org/viewvc/llvm-project?rev=206860&view=rev
Log:
blockfreq: Skip irreducible backedges inside functions

The branch that skips irreducible backedges was only active when
propagating mass at the top-level.  In particular, when propagating mass
through a loop recognized by `LoopInfo` with irreducible control flow
inside, irreducible backedges would not be skipped.

Not sure where that idea came from, but the result was that mass was
lost until after loop exit.  Added a testcase that covers this case.

Modified:
    llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp
    llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible.ll

Modified: llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp?rev=206860&r1=206859&r2=206860&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp (original)
+++ llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp Mon Apr 21 22:31:53 2014
@@ -687,7 +687,7 @@ void BlockFrequencyInfoImplBase::addToDi
     return;
   }
 
-  if (!LoopHead.isValid() && Resolved < Pred) {
+  if (Resolved < Pred) {
     // Irreducible backedge.  Skip this edge in the distribution.
     DEBUG(debugSuccessor("skipped ", Resolved));
     return;

Modified: llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible.ll?rev=206860&r1=206859&r2=206860&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible.ll (original)
+++ llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible.ll Mon Apr 21 22:31:53 2014
@@ -195,3 +195,34 @@ declare i32 @choose(i32)
 
 !2 = metadata !{metadata !"branch_weights", i32 3, i32 1}
 !3 = metadata !{metadata !"branch_weights", i32 2, i32 2, i32 2}
+
+; A reducible loop with irreducible control flow inside should still have
+; correct exit frequency.
+;
+; CHECK-LABEL: Printing analysis {{.*}} for function 'loop_around_irreducible':
+; CHECK-NEXT: block-frequency-info: loop_around_irreducible
+define void @loop_around_irreducible(i1 %x) {
+; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]]
+entry:
+  br label %loop
+
+; CHECK-NEXT: loop: float = [[HEAD:[0-9.]+]], int = [[HEADINT:[0-9]+]]
+loop:
+  br i1 %x, label %left, label %right
+
+; CHECK-NEXT: left:
+left:
+  br i1 %x, label %right, label %loop.end
+
+; CHECK-NEXT: right:
+right:
+  br i1 %x, label %left, label %loop.end
+
+; CHECK-NEXT: loop.end: float = [[HEAD]], int = [[HEADINT]]
+loop.end:
+  br i1 %x, label %loop, label %exit
+
+; CHECK-NEXT: float = 1.0, int = [[ENTRY]]
+exit:
+  ret void
+}





More information about the llvm-commits mailing list