[llvm-branch-commits] [llvm-branch] r278827 - Merging r278575 (with changes to the test):
Hans Wennborg via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Aug 16 10:51:13 PDT 2016
Author: hans
Date: Tue Aug 16 12:51:12 2016
New Revision: 278827
URL: http://llvm.org/viewvc/llvm-project?rev=278827&view=rev
Log:
Merging r278575 (with changes to the test):
------------------------------------------------------------------------
r278575 | haicheng | 2016-08-12 16:13:38 -0700 (Fri, 12 Aug 2016) | 6 lines
Reapply [BranchFolding] Restrict tail merging loop blocks after MBP
Fixed a bug in the test case.
To fix PR28104, this patch restricts tail merging to blocks that belong to the
same loop after MBP.
------------------------------------------------------------------------
I had to adjust the test as it wasn't passing on the branch, presumably
due to different machine block placement.
Added:
llvm/branches/release_39/test/CodeGen/X86/tail-merge-after-mbp.ll
- copied, changed from r278575, llvm/trunk/test/CodeGen/X86/tail-merge-after-mbp.ll
Modified:
llvm/branches/release_39/ (props changed)
llvm/branches/release_39/lib/CodeGen/BranchFolding.cpp
llvm/branches/release_39/test/CodeGen/ARM/arm-and-tst-peephole.ll
Propchange: llvm/branches/release_39/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug 16 12:51:12 2016
@@ -1,3 +1,3 @@
/llvm/branches/Apple/Pertwee:110850,110961
/llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,275868-275870,275879,275898,275928,275935,275946,275978,275981,276015,276051,276077,276109,276119,276181,276209,276236-276237,276358,276364,276368,276389,276435,276438,276479,276510,276648,276676,276712,276740,276823,276956,276980,277093,277114,277135,277371,277399,277500,277504,277625,277691,277693,277773,278002,278086,278133,278157,278370,278413,278558,278569,278573,278584
+/llvm/trunk:155241,275868-275870,275879,275898,275928,275935,275946,275978,275981,276015,276051,276077,276109,276119,276181,276209,276236-276237,276358,276364,276368,276389,276435,276438,276479,276510,276648,276676,276712,276740,276823,276956,276980,277093,277114,277135,277371,277399,277500,277504,277625,277691,277693,277773,278002,278086,278133,278157,278370,278413,278558,278569,278573,278575,278584
Modified: llvm/branches/release_39/lib/CodeGen/BranchFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/lib/CodeGen/BranchFolding.cpp?rev=278827&r1=278826&r2=278827&view=diff
==============================================================================
--- llvm/branches/release_39/lib/CodeGen/BranchFolding.cpp (original)
+++ llvm/branches/release_39/lib/CodeGen/BranchFolding.cpp Tue Aug 16 12:51:12 2016
@@ -996,6 +996,24 @@ bool BranchFolder::TailMergeBlocks(Machi
MachineBasicBlock *IBB = &*I;
MachineBasicBlock *PredBB = &*std::prev(I);
MergePotentials.clear();
+ MachineLoop *ML;
+
+ // Bail if merging after placement and IBB is the loop header because
+ // -- If merging predecessors that belong to the same loop as IBB, the
+ // common tail of merged predecessors may become the loop top if block
+ // placement is called again and the predecessors may branch to this common
+ // tail and require more branches. This can be relaxed if
+ // MachineBlockPlacement::findBestLoopTop is more flexible.
+ // --If merging predecessors that do not belong to the same loop as IBB, the
+ // loop info of IBB's loop and the other loops may be affected. Calling the
+ // block placement again may make big change to the layout and eliminate the
+ // reason to do tail merging here.
+ if (AfterBlockPlacement && MLI) {
+ ML = MLI->getLoopFor(IBB);
+ if (ML && IBB == ML->getHeader())
+ continue;
+ }
+
for (MachineBasicBlock *PBB : I->predecessors()) {
if (MergePotentials.size() == TailMergeThreshold)
break;
@@ -1015,16 +1033,12 @@ bool BranchFolder::TailMergeBlocks(Machi
if (PBB->hasEHPadSuccessor())
continue;
- // Bail out if the loop header (IBB) is not the top of the loop chain
- // after the block placement. Otherwise, the common tail of IBB's
- // predecessors may become the loop top if block placement is called again
- // and the predecessors may branch to this common tail.
- // FIXME: Relaxed this check if the algorithm of finding loop top is
- // changed in MBP.
+ // After block placement, only consider predecessors that belong to the
+ // same loop as IBB. The reason is the same as above when skipping loop
+ // header.
if (AfterBlockPlacement && MLI)
- if (MachineLoop *ML = MLI->getLoopFor(IBB))
- if (IBB == ML->getHeader() && ML == MLI->getLoopFor(PBB))
- continue;
+ if (ML != MLI->getLoopFor(PBB))
+ continue;
MachineBasicBlock *TBB = nullptr, *FBB = nullptr;
SmallVector<MachineOperand, 4> Cond;
Modified: llvm/branches/release_39/test/CodeGen/ARM/arm-and-tst-peephole.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/test/CodeGen/ARM/arm-and-tst-peephole.ll?rev=278827&r1=278826&r2=278827&view=diff
==============================================================================
--- llvm/branches/release_39/test/CodeGen/ARM/arm-and-tst-peephole.ll (original)
+++ llvm/branches/release_39/test/CodeGen/ARM/arm-and-tst-peephole.ll Tue Aug 16 12:51:12 2016
@@ -49,7 +49,7 @@ tailrecurse.switch:
; V8-NEXT: beq
; V8-NEXT: %tailrecurse.switch
; V8: cmp
-; V8-NEXT: beq
+; V8-NEXT: bne
; V8-NEXT: b
; The trailing space in the last line checks that the branch is unconditional
switch i32 %and, label %sw.epilog [
Copied: llvm/branches/release_39/test/CodeGen/X86/tail-merge-after-mbp.ll (from r278575, llvm/trunk/test/CodeGen/X86/tail-merge-after-mbp.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/test/CodeGen/X86/tail-merge-after-mbp.ll?p2=llvm/branches/release_39/test/CodeGen/X86/tail-merge-after-mbp.ll&p1=llvm/trunk/test/CodeGen/X86/tail-merge-after-mbp.ll&r1=278575&r2=278827&rev=278827&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/tail-merge-after-mbp.ll (original)
+++ llvm/branches/release_39/test/CodeGen/X86/tail-merge-after-mbp.ll Tue Aug 16 12:51:12 2016
@@ -9,25 +9,23 @@
declare i32 @Up(...)
declare i32 @f(i32, i32)
-; check loop block BB#10 is not merged with LBB0_12
-; check loop block LBB0_9 is not merged with BB#11, BB#13
define i32 @foo(%0* nocapture readonly, i32, i1 %c, i8* %p1, %2** %p2) {
; CHECK-LABEL: foo:
-; CHECK: LBB0_9:
+; CHECK: BB#6:
; CHECK-NEXT: movq (%r14), %rax
; CHECK-NEXT: testq %rax, %rax
; CHECK-NEXT: je
-; CHECK-NEXT:# BB#10:
+; CHECK-NEXT:# BB#7:
; CHECK-NEXT: cmpq $0, 8(%rax)
; CHECK-NEXT: jne
-; CHECK-NEXT:# BB#11:
+; CHECK-NEXT:# BB#8:
; CHECK-NEXT: movq (%r14), %rax
; CHECK-NEXT: testq %rax, %rax
; CHECK-NEXT: je
-; CHECK-NEXT:LBB0_12:
+; CHECK-NEXT:LBB0_9:
; CHECK-NEXT: cmpq $0, 8(%rax)
; CHECK-NEXT: jne
-; CHECK-NEXT:# BB#13:
+; CHECK-NEXT:# BB#10:
; CHECK-NEXT: movq (%r14), %rax
; CHECK-NEXT: testq %rax, %rax
; CHECK-NEXT: jne
More information about the llvm-branch-commits
mailing list