Index: lib/Transforms/IPO/PassManagerBuilder.cpp =================================================================== --- lib/Transforms/IPO/PassManagerBuilder.cpp +++ lib/Transforms/IPO/PassManagerBuilder.cpp @@ -661,6 +661,11 @@ MPM.add(createLoopSinkPass()); // Get rid of LCSSA nodes. MPM.add(createInstructionSimplifierPass()); + + // LoopSink (and other loop passes since the last simplifyCFG) might have + // resulted in single-entry-single-exit or empty blocks. Clean up the CFG. + MPM.add(createCFGSimplificationPass()); + addExtensionsToPM(EP_OptimizerLast, MPM); } Index: test/Other/pass-pipelines.ll =================================================================== --- test/Other/pass-pipelines.ll +++ test/Other/pass-pipelines.ll @@ -85,6 +85,7 @@ ; CHECK-O2: FunctionPass Manager ; CHECK-O2: Loop Pass Manager ; CHECK-O2-NEXT: Loop Sink +; CHECK-O2: Simplify the CFG ; CHECK-O2-NOT: Manager ; ; FIXME: There really shouldn't be another pass manager, especially one that Index: test/Other/pr32085.ll =================================================================== --- /dev/null +++ test/Other/pr32085.ll @@ -0,0 +1,119 @@ +; RUN: opt -O2 -S < %s | FileCheck %s +; In PR32085 we were getting single-entry-single-exit basic blocks due to the +; lack of cleanup after some loop transformations. +; Make sure we end up with a single basic block, no branches +; CHECK-NOT: br label + +; ModuleID = 'a.cpp' +source_filename = "a.cpp" +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.12.0" + +; Function Attrs: ssp uwtable +define i8* @_Z3go4i(i32) #0 { + %2 = alloca i32, align 4 + %3 = alloca i32*, align 8 + %4 = alloca i32, align 4 + %5 = alloca i32 + %6 = alloca i32, align 4 + store i32 %0, i32* %2, align 4, !tbaa !2 + %7 = bitcast i32** %3 to i8* + call void @llvm.lifetime.start(i64 8, i8* %7) #3 + %8 = call i8* @_Znam(i64 4096) #4 + %9 = bitcast i8* %8 to i32* + store i32* %9, i32** %3, align 8, !tbaa !6 + %10 = bitcast i32* %4 to i8* + call void @llvm.lifetime.start(i64 4, i8* %10) #3 + store i32 0, i32* %4, align 4, !tbaa !2 + br label %11 + +;