Index: llvm/trunk/lib/Transforms/Scalar/LoopSink.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/LoopSink.cpp +++ llvm/trunk/lib/Transforms/Scalar/LoopSink.cpp @@ -202,6 +202,13 @@ if (BBsToSinkInto.empty()) return false; + // Return if any of the candidate blocks to sink into is non-cold. + if (BBsToSinkInto.size() > 1) { + for (auto *BB : BBsToSinkInto) + if (!LoopBlockNumber.count(BB)) + return false; + } + // Copy the final BBs into a vector and sort them using the total ordering // of the loop block numbers as iterating the set doesn't give a useful // order. No need to stable sort as the block numbers are a total ordering. Index: llvm/trunk/test/Transforms/LICM/loopsink-pr39570.ll =================================================================== --- llvm/trunk/test/Transforms/LICM/loopsink-pr39570.ll +++ llvm/trunk/test/Transforms/LICM/loopsink-pr39570.ll @@ -0,0 +1,112 @@ +; RUN: opt -S -loop-sink < %s | FileCheck %s + +; CHECK: pr39570 +; Make sure not to assert. + +%0 = type { i32, %1*, %2, %6*, %33* } +%1 = type { i32 (...)** } +%2 = type { %3* } +%3 = type { %4, i32, %5* } +%4 = type { i32 (...)**, i32 } +%5 = type opaque +%6 = type { %7, %1*, %31*, i8, %2, %32* } +%7 = type <{ %8, %9*, %10, i32, %33*, %33*, %33*, %27, %28, i16 }> +%8 = type { i32 (...)** } +%9 = type opaque +%10 = type { %11, %16, %18, %19 } +%11 = type { %12*, i32, i32, %13* } +%12 = type { i32 (...)** } +%13 = type { %14*, %14* } +%14 = type { %15, i32 } +%15 = type { %12*, i32, i32, i16* } +%16 = type { %12*, i32, i32, %17* } +%17 = type { %13, %14* } +%18 = type { %12*, i32, i32, %14** } +%19 = type { %20, %21, %12*, float, i32, i32, %22, %22, %24, i32, i32 } +%20 = type { i8 } +%21 = type { i8 } +%22 = type { %12*, %23*, %23* } +%23 = type opaque +%24 = type { %12*, i32, i32, %25* } +%25 = type { %12*, i32, i32, %26* } +%26 = type opaque +%27 = type { %33* } +%28 = type { %29, i32, i32, %14* } +%29 = type { %30 } +%30 = type { i32 (...)** } +%31 = type opaque +%32 = type { i32 (...)** } +%33 = type <{ %8, %9*, %10, i32, %33*, %33*, %33*, %27, %28, i16, [2 x i8] }> + +define dso_local void @pr39570() local_unnamed_addr align 2 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) !prof !1 { + br i1 undef, label %8, label %1, !prof !2 + +;