Index: llvm/lib/Target/X86/X86CmovConversion.cpp =================================================================== --- llvm/lib/Target/X86/X86CmovConversion.cpp +++ llvm/lib/Target/X86/X86CmovConversion.cpp @@ -115,6 +115,7 @@ MachineRegisterInfo *MRI = nullptr; const TargetInstrInfo *TII = nullptr; const TargetRegisterInfo *TRI = nullptr; + MachineLoopInfo *MLI = nullptr; TargetSchedModel TSchedModel; /// List of consecutive CMOV instructions. @@ -165,7 +166,7 @@ << "**********\n"); bool Changed = false; - MachineLoopInfo &MLI = getAnalysis(); + MLI = &getAnalysis(); const TargetSubtargetInfo &STI = MF.getSubtarget(); MRI = &MF.getRegInfo(); TII = STI.getInstrInfo(); @@ -221,7 +222,7 @@ //===--------------------------------------------------------------------===// // Build up the loops in pre-order. - SmallVector Loops(MLI.begin(), MLI.end()); + SmallVector Loops(MLI->begin(), MLI->end()); // Note that we need to check size on each iteration as we accumulate child // loops. for (int i = 0; i < (int)Loops.size(); ++i) @@ -848,6 +849,12 @@ // Now remove the CMOV(s). MBB->erase(MIItBegin, MIItEnd); + + // Add new basic blocks to MachineLoopInfo. + if (MachineLoop *L = MLI->getLoopFor(MBB)) { + L->addBasicBlockToLoop(FalseMBB, MLI->getBase()); + L->addBasicBlockToLoop(SinkMBB, MLI->getBase()); + } } INITIALIZE_PASS_BEGIN(X86CmovConverterPass, DEBUG_TYPE, "X86 cmov Conversion", Index: llvm/test/CodeGen/X86/x86-cmov-converter.ll =================================================================== --- llvm/test/CodeGen/X86/x86-cmov-converter.ll +++ llvm/test/CodeGen/X86/x86-cmov-converter.ll @@ -513,7 +513,12 @@ ; CHECK-NEXT: movl %edi, (%rcx) ; CHECK-NEXT: addq $8, %rcx ; CHECK-NEXT: cmpq %rdx, %rcx -; CHECK-NEXT: cmovbeq %rax, %rcx +; CHECK-NEXT: ja .LBB13_5 +; CHECK-NEXT: # %bb.4: # %loop.body +; CHECK-NEXT: # in Loop: Header=BB13_1 Depth=1 +; CHECK-NEXT: movq %rax, %rcx +; CHECK-NEXT: .LBB13_5: # %loop.body +; CHECK-NEXT: # in Loop: Header=BB13_1 Depth=1 ; CHECK-NEXT: movl %edi, (%rcx) ; CHECK-NEXT: addl $1, %esi ; CHECK-NEXT: cmpl $1024, %esi # imm = 0x400 @@ -534,7 +539,7 @@ %cond = icmp slt i32 %iv.next, 1024 br i1 %cond, label %loop.body, label %exit -; CHECK-NEXT: # %bb.4: # %exit +; CHECK-NEXT: # %bb.6: # %exit ; CHECK-NEXT: retq exit: ret void