llvm.org GIT mirror llvm / 2eb3d6d
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 Matthias Braun 3 years ago
2 changed file(s) with 43 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
775775 }
776776
777777 static void
778 mergeMMOsFromMemoryOperations(MachineBasicBlock::iterator MBBIStartPos,
779 MachineBasicBlock &MBBCommon) {
780 // Merge MMOs from memory operations in the common block.
778 mergeOperations(MachineBasicBlock::iterator MBBIStartPos,
779 MachineBasicBlock &MBBCommon) {
781780 MachineBasicBlock *MBB = MBBIStartPos->getParent();
782781 // Note CommonTailLen does not necessarily matches the size of
783782 // the common BB nor all its instructions because of debug
807806 "Reached BB end within common tail length!");
808807 assert(MBBICommon->isIdenticalTo(*MBBI) && "Expected matching MIIs!");
809808
809 // Merge MMOs from memory operations in the common block.
810810 if (MBBICommon->mayLoad() || MBBICommon->mayStore())
811811 MBBICommon->setMemRefs(MBBICommon->mergeMemRefsWith(*MBBI));
812 // Drop undef flags if they aren't present in all merged instructions.
813 for (unsigned I = 0, E = MBBICommon->getNumOperands(); I != E; ++I) {
814 MachineOperand &MO = MBBICommon->getOperand(I);
815 if (MO.isReg() && MO.isUndef()) {
816 const MachineOperand &OtherMO = MBBI->getOperand(I);
817 if (!OtherMO.isUndef())
818 MO.setIsUndef(false);
819 }
820 }
812821
813822 ++MBBI;
814823 ++MBBICommon;
927936 continue;
928937 DEBUG(dbgs() << "BB#" << SameTails[i].getBlock()->getNumber()
929938 << (i == e-1 ? "" : ", "));
930 // Merge MMOs from memory operations as needed.
931 mergeMMOsFromMemoryOperations(SameTails[i].getTailStartPos(), *MBB);
939 // Merge operations (MMOs, undef flags)
940 mergeOperations(SameTails[i].getTailStartPos(), *MBB);
932941 // Hack the end off BB i, making it jump to BB commonTailIndex instead.
933942 ReplaceTailWithBranchTo(SameTails[i].getTailStartPos(), MBB);
934943 // BB i is no longer a predecessor of SuccBB; remove it from the worklist.
0 # RUN: llc -o - %s -march=x86 -run-pass branch-folder | FileCheck %s
1 # Test that tail merging drops undef flags that aren't present on all
2 # instructions to be merged.
3 --- |
4 define void @func() { ret void }
5 ...
6 ---
7 # CHECK-LABEL: name: func
8 # CHECK: bb.1:
9 # CHECK: %eax = MOV32ri 2
10 # CHECK-NOT: RET
11 # CHECK: bb.2:
12 # CHECK-NOT: RET 0, undef %eax
13 # CHECK: RET 0, %eax
14 name: func
15 tracksRegLiveness: true
16 body: |
17 bb.0:
18 successors: %bb.1, %bb.2
19 JE_1 %bb.1, implicit undef %eflags
20 JMP_1 %bb.2
21
22 bb.1:
23 %eax = MOV32ri 2
24 RET 0, %eax
25
26 bb.2:
27 RET 0, undef %eax
28 ...