Index: include/llvm/Transforms/Scalar/SROA.h =================================================================== --- include/llvm/Transforms/Scalar/SROA.h +++ include/llvm/Transforms/Scalar/SROA.h @@ -130,7 +130,7 @@ bool splitAlloca(AllocaInst &AI, sroa::AllocaSlices &AS); bool runOnAlloca(AllocaInst &AI); void clobberUse(Use &U); - void deleteDeadInstructions(SmallPtrSetImpl &DeletedAllocas); + bool deleteDeadInstructions(SmallPtrSetImpl &DeletedAllocas); bool promoteAllocas(Function &F); }; Index: lib/Transforms/Scalar/SROA.cpp =================================================================== --- lib/Transforms/Scalar/SROA.cpp +++ lib/Transforms/Scalar/SROA.cpp @@ -4243,8 +4243,9 @@ /// /// We also record the alloca instructions deleted here so that they aren't /// subsequently handed to mem2reg to promote. -void SROA::deleteDeadInstructions( +bool SROA::deleteDeadInstructions( SmallPtrSetImpl &DeletedAllocas) { + bool Changed = false; while (!DeadInsts.empty()) { Instruction *I = DeadInsts.pop_back_val(); DEBUG(dbgs() << "Deleting dead instruction: " << *I << "\n"); @@ -4270,7 +4271,9 @@ ++NumDeleted; I->eraseFromParent(); + Changed = true; } + return Changed; } /// \brief Promote the allocas, using the best available technique. @@ -4312,7 +4315,7 @@ do { while (!Worklist.empty()) { Changed |= runOnAlloca(*Worklist.pop_back_val()); - deleteDeadInstructions(DeletedAllocas); + Changed |= deleteDeadInstructions(DeletedAllocas); // Remove the deleted allocas from various lists so that we don't try to // continue processing them. Index: test/Transforms/SROA/dead-inst.ll =================================================================== --- /dev/null +++ test/Transforms/SROA/dead-inst.ll @@ -0,0 +1,99 @@ +; SROA fails to rewrite allocs but does rewrite some phis and delete +; dead instructions. Ensure that this invalidates analyses required +; for other passes. +; RUN: opt < %s -passes=bdce,sroa,bdce -o %t -debug-pass-manager 2>&1 | FileCheck %s +; CHECK: Running pass: BDCEPass on H +; CHECK: Running analysis: DemandedBitsAnalysis on H +; CHECK: Running pass: SROA on H +; CHECK: Invalidating all non-preserved analyses for: H +; CHECK: Invalidating analysis: DemandedBitsAnalysis on H +; CHECK: Running pass: BDCEPass on H +; CHECK: Running analysis: DemandedBitsAnalysis on H +; CHECK: Finished llvm::Function pass manager run. + +; ModuleID = 'bugpoint-reduced-simplified.bc' +source_filename = "bugpoint-output-7a27a2b.bc" +target datalayout = "e-m:e-i64:64-n32:64" +target triple = "powerpc64le-grtev4-linux-gnu" + +%class.b = type { i64 } + +declare void @D(%class.b* sret, %class.b* dereferenceable(32)) local_unnamed_addr + +; Function Attrs: nounwind +define hidden fastcc void @H(%class.b* noalias nocapture readnone, [2 x i64]) unnamed_addr { + %3 = alloca %class.b, align 8 + %.sroa.0 = alloca i64, align 8 + store i64 0, i64* %.sroa.0, align 8 + %4 = extractvalue [2 x i64] %1, 1 + switch i64 %4, label %6 [ + i64 4, label %foo + i64 5, label %5 + ] + +;