@@ -776,9 +776,8 @@ bool BranchFolder::CreateCommonTailOnlyBlock(MachineBasicBlock *&PredBB,
776
776
}
777
777
778
778
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) {
782
781
MachineBasicBlock *MBB = MBBIStartPos->getParent ();
783
782
// Note CommonTailLen does not necessarily matches the size of
784
783
// the common BB nor all its instructions because of debug
@@ -808,8 +807,18 @@ mergeMMOsFromMemoryOperations(MachineBasicBlock::iterator MBBIStartPos,
808
807
" Reached BB end within common tail length!" );
809
808
assert (MBBICommon->isIdenticalTo (*MBBI) && " Expected matching MIIs!" );
810
809
810
+ // Merge MMOs from memory operations in the common block.
811
811
if (MBBICommon->mayLoad () || MBBICommon->mayStore ())
812
812
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
+ }
813
822
814
823
++MBBI;
815
824
++MBBICommon;
@@ -928,8 +937,8 @@ bool BranchFolder::TryTailMergeBlocks(MachineBasicBlock *SuccBB,
928
937
continue ;
929
938
DEBUG (dbgs () << " BB#" << SameTails[i].getBlock ()->getNumber ()
930
939
<< (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);
933
942
// Hack the end off BB i, making it jump to BB commonTailIndex instead.
934
943
ReplaceTailWithBranchTo (SameTails[i].getTailStartPos (), MBB);
935
944
// BB i is no longer a predecessor of SuccBB; remove it from the worklist.
0 commit comments