[llvm-commits] [llvm] r89484 - in /llvm/trunk: include/llvm/Analysis/LoopInfo.h lib/Transforms/Utils/LoopSimplify.cpp test/Transforms/LoopRotate/indirectbr.ll test/Transforms/LoopSimplify/indirectbr.ll
Dan Gohman
gohman at apple.com
Fri Nov 20 12:51:19 PST 2009
Author: djg
Date: Fri Nov 20 14:51:18 2009
New Revision: 89484
URL: http://llvm.org/viewvc/llvm-project?rev=89484&view=rev
Log:
Make Loop::getLoopLatch() work on loops which don't have preheaders, as
it may be used in contexts where preheader insertion may have failed due
to an indirectbr.
Make LoopSimplify's LoopSimplify::SeparateNestedLoop properly fail in
the case that it would require splitting an indirectbr edge.
These fix PR5502.
Added:
llvm/trunk/test/Transforms/LoopRotate/indirectbr.ll
Modified:
llvm/trunk/include/llvm/Analysis/LoopInfo.h
llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp
llvm/trunk/test/Transforms/LoopSimplify/indirectbr.ll
Modified: llvm/trunk/include/llvm/Analysis/LoopInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopInfo.h?rev=89484&r1=89483&r2=89484&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopInfo.h Fri Nov 20 14:51:18 2009
@@ -269,8 +269,6 @@
/// getLoopLatch - If there is a single latch block for this loop, return it.
/// A latch block is a block that contains a branch back to the header.
- /// A loop header in normal form has two edges into it: one from a preheader
- /// and one from a latch block.
BlockT *getLoopLatch() const {
BlockT *Header = getHeader();
typedef GraphTraits<Inverse<BlockT*> > InvBlockTraits;
@@ -278,20 +276,12 @@
InvBlockTraits::child_begin(Header);
typename InvBlockTraits::ChildIteratorType PE =
InvBlockTraits::child_end(Header);
- if (PI == PE) return 0; // no preds?
-
BlockT *Latch = 0;
- if (contains(*PI))
- Latch = *PI;
- ++PI;
- if (PI == PE) return 0; // only one pred?
-
- if (contains(*PI)) {
- if (Latch) return 0; // multiple backedges
- Latch = *PI;
- }
- ++PI;
- if (PI != PE) return 0; // more than two preds
+ for (; PI != PE; ++PI)
+ if (contains(*PI)) {
+ if (Latch) return 0;
+ Latch = *PI;
+ }
return Latch;
}
Modified: llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp?rev=89484&r1=89483&r2=89484&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp Fri Nov 20 14:51:18 2009
@@ -477,8 +477,13 @@
SmallVector<BasicBlock*, 8> OuterLoopPreds;
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
if (PN->getIncomingValue(i) != PN ||
- !L->contains(PN->getIncomingBlock(i)))
+ !L->contains(PN->getIncomingBlock(i))) {
+ // We can't split indirectbr edges.
+ if (isa<IndirectBrInst>(PN->getIncomingBlock(i)->getTerminator()))
+ return 0;
+
OuterLoopPreds.push_back(PN->getIncomingBlock(i));
+ }
BasicBlock *Header = L->getHeader();
BasicBlock *NewBB = SplitBlockPredecessors(Header, &OuterLoopPreds[0],
Added: llvm/trunk/test/Transforms/LoopRotate/indirectbr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopRotate/indirectbr.ll?rev=89484&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/LoopRotate/indirectbr.ll (added)
+++ llvm/trunk/test/Transforms/LoopRotate/indirectbr.ll Fri Nov 20 14:51:18 2009
@@ -0,0 +1,43 @@
+; RUN: opt < %s -S -loop-rotate -disable-output -verify-loop-info -verify-dom-info
+; PR5502
+
+define void @z80_do_opcodes() nounwind {
+entry:
+ br label %while.cond
+
+while.cond: ; preds = %end_opcode, %entry
+ br label %while.body
+
+while.body: ; preds = %while.cond
+ br label %indirectgoto
+
+run_opcode: ; preds = %indirectgoto
+ %tmp276 = load i8* undef ; <i8> [#uses=1]
+ br label %indirectgoto
+
+if.else295: ; preds = %divide_late
+ br label %end_opcode
+
+end_opcode: ; preds = %indirectgoto, %sw.default42406, %sw.default, %if.else295
+ %opcode.2 = phi i8 [ %opcode.0, %indirectgoto ], [ 0, %sw.default42406 ], [ undef, %sw.default ], [ %opcode.0, %if.else295 ] ; <i8> [#uses=0]
+ switch i32 undef, label %while.cond [
+ i32 221, label %sw.bb11691
+ i32 253, label %sw.bb30351
+ ]
+
+sw.bb11691: ; preds = %end_opcode
+ br label %sw.default
+
+sw.default: ; preds = %sw.bb11691
+ br label %end_opcode
+
+sw.bb30351: ; preds = %end_opcode
+ br label %sw.default42406
+
+sw.default42406: ; preds = %sw.bb30351
+ br label %end_opcode
+
+indirectgoto: ; preds = %run_opcode, %while.body
+ %opcode.0 = phi i8 [ undef, %while.body ], [ %tmp276, %run_opcode ] ; <i8> [#uses=2]
+ indirectbr i8* undef, [label %run_opcode, label %if.else295, label %end_opcode]
+}
Modified: llvm/trunk/test/Transforms/LoopSimplify/indirectbr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopSimplify/indirectbr.ll?rev=89484&r1=89483&r2=89484&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopSimplify/indirectbr.ll (original)
+++ llvm/trunk/test/Transforms/LoopSimplify/indirectbr.ll Fri Nov 20 14:51:18 2009
@@ -81,3 +81,20 @@
%y = phi i64 [ %z, %L0 ], [ 1, %entry ]
ret i64 %y
}
+
+define void @pr5502() nounwind {
+entry:
+ br label %while.cond
+
+while.cond:
+ br i1 undef, label %while.body, label %while.end
+
+while.body:
+ indirectbr i8* undef, [label %end_opcode, label %end_opcode]
+
+end_opcode:
+ br i1 false, label %end_opcode, label %while.cond
+
+while.end:
+ ret void
+}
More information about the llvm-commits
mailing list