Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 2eb3d6d

Browse files
committed
Cherry pick r281957 (see http://llvm.org/PR30463)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_39@282615 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 69e5622 commit 2eb3d6d

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

lib/CodeGen/BranchFolding.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,8 @@ bool BranchFolder::CreateCommonTailOnlyBlock(MachineBasicBlock *&PredBB,
776776
}
777777

778778
static void
779-
mergeMMOsFromMemoryOperations(MachineBasicBlock::iterator MBBIStartPos,
780-
MachineBasicBlock &MBBCommon) {
781-
// Merge MMOs from memory operations in the common block.
779+
mergeOperations(MachineBasicBlock::iterator MBBIStartPos,
780+
MachineBasicBlock &MBBCommon) {
782781
MachineBasicBlock *MBB = MBBIStartPos->getParent();
783782
// Note CommonTailLen does not necessarily matches the size of
784783
// the common BB nor all its instructions because of debug
@@ -808,8 +807,18 @@ mergeMMOsFromMemoryOperations(MachineBasicBlock::iterator MBBIStartPos,
808807
"Reached BB end within common tail length!");
809808
assert(MBBICommon->isIdenticalTo(*MBBI) && "Expected matching MIIs!");
810809

810+
// Merge MMOs from memory operations in the common block.
811811
if (MBBICommon->mayLoad() || MBBICommon->mayStore())
812812
MBBICommon->setMemRefs(MBBICommon->mergeMemRefsWith(*MBBI));
813+
// Drop undef flags if they aren't present in all merged instructions.
814+
for (unsigned I = 0, E = MBBICommon->getNumOperands(); I != E; ++I) {
815+
MachineOperand &MO = MBBICommon->getOperand(I);
816+
if (MO.isReg() && MO.isUndef()) {
817+
const MachineOperand &OtherMO = MBBI->getOperand(I);
818+
if (!OtherMO.isUndef())
819+
MO.setIsUndef(false);
820+
}
821+
}
813822

814823
++MBBI;
815824
++MBBICommon;
@@ -928,8 +937,8 @@ bool BranchFolder::TryTailMergeBlocks(MachineBasicBlock *SuccBB,
928937
continue;
929938
DEBUG(dbgs() << "BB#" << SameTails[i].getBlock()->getNumber()
930939
<< (i == e-1 ? "" : ", "));
931-
// Merge MMOs from memory operations as needed.
932-
mergeMMOsFromMemoryOperations(SameTails[i].getTailStartPos(), *MBB);
940+
// Merge operations (MMOs, undef flags)
941+
mergeOperations(SameTails[i].getTailStartPos(), *MBB);
933942
// Hack the end off BB i, making it jump to BB commonTailIndex instead.
934943
ReplaceTailWithBranchTo(SameTails[i].getTailStartPos(), MBB);
935944
// BB i is no longer a predecessor of SuccBB; remove it from the worklist.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# RUN: llc -o - %s -march=x86 -run-pass branch-folder | FileCheck %s
2+
# Test that tail merging drops undef flags that aren't present on all
3+
# instructions to be merged.
4+
--- |
5+
define void @func() { ret void }
6+
...
7+
---
8+
# CHECK-LABEL: name: func
9+
# CHECK: bb.1:
10+
# CHECK: %eax = MOV32ri 2
11+
# CHECK-NOT: RET
12+
# CHECK: bb.2:
13+
# CHECK-NOT: RET 0, undef %eax
14+
# CHECK: RET 0, %eax
15+
name: func
16+
tracksRegLiveness: true
17+
body: |
18+
bb.0:
19+
successors: %bb.1, %bb.2
20+
JE_1 %bb.1, implicit undef %eflags
21+
JMP_1 %bb.2
22+
23+
bb.1:
24+
%eax = MOV32ri 2
25+
RET 0, %eax
26+
27+
bb.2:
28+
RET 0, undef %eax
29+
...

0 commit comments

Comments
 (0)