Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp =================================================================== --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -196,6 +196,9 @@ "Number of common instruction 'blocks' hoisted up to the begin block"); STATISTIC(NumHoistCommonInstrs, "Number of common instructions hoisted up to the begin block"); +STATISTIC( + NumHoistCommonCodeNonContiguous, + "Number of non-contiguous common instruction 'blocks' hoisted up to the begin block"); STATISTIC(NumSinkCommonCode, "Number of common instruction 'blocks' sunk down to the end block"); STATISTIC(NumSinkCommonInstrs, @@ -1505,12 +1508,6 @@ BasicBlock *BIParent = BI->getParent(); - bool Changed = false; - - auto _ = make_scope_exit([&]() { - if (Changed) - ++NumHoistCommonCode; - }); // Check if only hoisting terminators is allowed. This does not add new // instructions to the hoist location. @@ -1530,7 +1527,11 @@ // many instructions we skip, serving as a compilation time control as well as // preventing excessive increase of life ranges. unsigned NumSkipped = 0; - + + // Count how many instructions were reordered over other instructions, for + // statistics. + unsigned NumReordered = 0; + // Record if any non-hoisted instruction contains side-effects, as it could // make it illegal to reorder some instructions across. bool ForceNoReadMemOrSideEffectsBB1 = false; @@ -1542,6 +1543,16 @@ bool ForceNoSpeculationBB1 = false; bool ForceNoSpeculationBB2 = false; + bool Changed = false; + + auto _ = make_scope_exit([&]() { + if (Changed) { + ++NumHoistCommonCode; + if (NumReordered) + ++NumHoistCommonCodeNonContiguous; + } + }); + for (;;) { // If we are hoisting the terminator instruction, don't move one (making a // broken BB), instead clone it, and remove BI. @@ -1627,6 +1638,8 @@ } Changed = true; ++NumHoistCommonInstrs; + if (NumSkipped) + ++NumReordered; } else { if (NumSkipped >= HoistCommonSkipLimit) return Changed;