[llvm] r177713 - Fix llvm::removeUnreachableBlocks to handle unreachable loops.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Fri Mar 22 01:43:04 PDT 2013
Author: eugenis
Date: Fri Mar 22 03:43:04 2013
New Revision: 177713
URL: http://llvm.org/viewvc/llvm-project?rev=177713&view=rev
Log:
Fix llvm::removeUnreachableBlocks to handle unreachable loops.
Modified:
llvm/trunk/lib/Transforms/Utils/Local.cpp
llvm/trunk/test/Instrumentation/MemorySanitizer/unreachable.ll
Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=177713&r1=177712&r2=177713&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Fri Mar 22 03:43:04 2013
@@ -985,22 +985,17 @@ bool llvm::removeUnreachableBlocks(Funct
if (Reachable.count(I))
continue;
- // Remove the block as predecessor of all its reachable successors.
- // Unreachable successors don't matter as they'll soon be removed, too.
for (succ_iterator SI = succ_begin(I), SE = succ_end(I); SI != SE; ++SI)
if (Reachable.count(*SI))
(*SI)->removePredecessor(I);
+ I->dropAllReferences();
+ }
- // Zap all instructions in this basic block.
- while (!I->empty()) {
- Instruction &Inst = I->back();
- if (!Inst.use_empty())
- Inst.replaceAllUsesWith(UndefValue::get(Inst.getType()));
- I->getInstList().pop_back();
- }
+ for (Function::iterator I = llvm::next(F.begin()), E=F.end(); I != E;)
+ if (!Reachable.count(I))
+ I = F.getBasicBlockList().erase(I);
+ else
+ ++I;
- --I;
- llvm::next(I)->eraseFromParent();
- }
return true;
}
Modified: llvm/trunk/test/Instrumentation/MemorySanitizer/unreachable.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/MemorySanitizer/unreachable.ll?rev=177713&r1=177712&r2=177713&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/MemorySanitizer/unreachable.ll (original)
+++ llvm/trunk/test/Instrumentation/MemorySanitizer/unreachable.ll Fri Mar 22 03:43:04 2013
@@ -21,3 +21,19 @@ exit:
; CHECK: @Func
; CHECK: store i32 0, {{.*}} @__msan_retval_tls
; CHECK: ret i32 42
+
+
+define i32 @UnreachableLoop() nounwind uwtable {
+entry:
+ ret i32 0
+
+zzz:
+ br label %xxx
+
+xxx:
+ br label %zzz
+}
+
+; CHECK: @UnreachableLoop
+; CHECK: store i32 0, {{.*}} @__msan_retval_tls
+; CHECK: ret i32 0
More information about the llvm-commits
mailing list