[llvm] r216911 - LICM: Don't crash when an instruction is used by an unreachable BB
David Majnemer
david.majnemer at gmail.com
Tue Sep 2 09:22:00 PDT 2014
Author: majnemer
Date: Tue Sep 2 11:22:00 2014
New Revision: 216911
URL: http://llvm.org/viewvc/llvm-project?rev=216911&view=rev
Log:
LICM: Don't crash when an instruction is used by an unreachable BB
Summary:
BBs might contain non-LCSSA'd values after the LCSSA pass is run if they
are unreachable from the entry block.
Normally, the users of the instruction would be PHIs but the unreachable
BBs have normal users; rewrite their uses to be undef values.
An alternative fix could involve fixing this at LCSSA but that would
require this invariant to hold after subsequent transforms. If a BB
created an unreachable block, they would be in violation of this.
This fixes PR19798.
Differential Revision: http://reviews.llvm.org/D5146
Added:
llvm/trunk/test/Transforms/LICM/PR19798.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/LICM.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/LICM.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LICM.cpp?rev=216911&r1=216910&r2=216911&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LICM.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LICM.cpp Tue Sep 2 11:22:00 2014
@@ -597,8 +597,13 @@ void LICM::sink(Instruction &I) {
// PHI nodes in exit blocks due to LCSSA form. Just RAUW them with clones of
// the instruction.
while (!I.use_empty()) {
+ Instruction *User = I.user_back();
+ if (!DT->isReachableFromEntry(User->getParent())) {
+ User->replaceUsesOfWith(&I, UndefValue::get(I.getType()));
+ continue;
+ }
// The user must be a PHI node.
- PHINode *PN = cast<PHINode>(I.user_back());
+ PHINode *PN = cast<PHINode>(User);
BasicBlock *ExitBlock = PN->getParent();
assert(ExitBlockSet.count(ExitBlock) &&
Added: llvm/trunk/test/Transforms/LICM/PR19798.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LICM/PR19798.ll?rev=216911&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/LICM/PR19798.ll (added)
+++ llvm/trunk/test/Transforms/LICM/PR19798.ll Tue Sep 2 11:22:00 2014
@@ -0,0 +1,22 @@
+; RUN: opt -licm -S < %s | FileCheck %s
+
+define void @f() {
+; CHECK-LABEL: @f(
+entry:
+ br label %bb0
+
+bb0:
+ %tobool7 = icmp eq i1 undef, undef
+ br label %bb1
+
+bb1:
+ br i1 undef, label %bb0, label %bb0
+
+unreachable:
+; CHECK-LABEL: unreachable:
+; CHECK: br i1 undef, label %unreachable, label %unreachable
+ br i1 %tobool7, label %unreachable, label %unreachable
+
+bb3:
+ unreachable
+}
More information about the llvm-commits
mailing list