OSDN Git Service

[LoopRotate] Detect loops with indirect branches better (we're giving up on them).
authorMichael Zolotukhin <mzolotukhin@apple.com>
Tue, 9 Jan 2018 23:54:35 +0000 (23:54 +0000)
committerMichael Zolotukhin <mzolotukhin@apple.com>
Tue, 9 Jan 2018 23:54:35 +0000 (23:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322137 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopRotation.cpp
test/Transforms/LoopRotate/indirectbr.ll

index a91f53b..0f35fcc 100644 (file)
@@ -268,7 +268,7 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
 
   // If the loop could not be converted to canonical form, it must have an
   // indirectbr in it, just give up.
-  if (!OrigPreheader)
+  if (!OrigPreheader || !L->hasDedicatedExits())
     return false;
 
   // Anything ScalarEvolution may know about this loop or the PHI nodes
index 2ccc546..8f059d5 100644 (file)
@@ -1,6 +1,6 @@
-; RUN: opt < %s -S -loop-rotate -disable-output -verify-loop-info -verify-dom-info
-; PR5502
+; RUN: opt < %s -S -loop-rotate -o - -verify-loop-info -verify-dom-info | FileCheck %s
 
+; PR5502
 define void @z80_do_opcodes() nounwind {
 entry:
   br label %while.cond
@@ -41,3 +41,34 @@ indirectgoto:                                     ; preds = %run_opcode, %while.
   %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]
 }
+
+; CHECK-LABEL: @foo
+define void @foo(i1 %a, i1 %b, i8* %c) {
+; CHECK: entry
+; CHECK-NEXT: br i1 %a, label %return, label %preheader
+entry:
+  br i1 %a, label %return, label %preheader
+
+; CHECK: preheader:
+; CHECK-NEXT:  br label %header
+preheader:
+  br label %header
+
+; CHECK: header:
+; CHECK-NEXT:  br i1 %b, label %return, label %body
+header:
+  br i1 %b, label %return, label %body
+
+; CHECK: body:
+; CHECK-NEXT:  indirectbr i8* %c, [label %return, label %latch]
+body:
+  indirectbr i8* %c, [label %return, label %latch]
+
+; CHECK: latch:
+; CHECK-NEXT:  br label %header
+latch:
+  br label %header
+
+return:
+  ret void
+}