summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Transforms/Utils/LoopUnroll.cpp8
-rw-r--r--llvm/test/Transforms/LoopUnroll/rebuild_lcssa.ll34
2 files changed, 40 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
index 5c83cef573b..5152220e626 100644
--- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
@@ -142,9 +142,13 @@ static bool needToInsertPhisForLCSSA(Loop *L, std::vector<BasicBlock *> Blocks,
continue;
for (Instruction &I : *BB) {
for (Use &U : I.operands()) {
- if (auto Def = dyn_cast<Instruction>(U))
- if (LI->getLoopFor(Def->getParent()) == L)
+ if (auto Def = dyn_cast<Instruction>(U)) {
+ Loop *DefLoop = LI->getLoopFor(Def->getParent());
+ if (!DefLoop)
+ continue;
+ if (DefLoop->contains(L))
return true;
+ }
}
}
}
diff --git a/llvm/test/Transforms/LoopUnroll/rebuild_lcssa.ll b/llvm/test/Transforms/LoopUnroll/rebuild_lcssa.ll
index 49498492344..9de638ce4f8 100644
--- a/llvm/test/Transforms/LoopUnroll/rebuild_lcssa.ll
+++ b/llvm/test/Transforms/LoopUnroll/rebuild_lcssa.ll
@@ -117,3 +117,37 @@ Exit:
%a_lcssa2 = phi i8* [ %a_lcssa1, %L2_exit ]
ret void
}
+
+; PR26688
+; CHECK-LABEL: @foo4
+define i8 @foo4() {
+entry:
+ br label %L1_header
+
+L1_header:
+ %x = icmp eq i32 1, 0
+ br label %L2_header
+
+L2_header:
+ br label %L3_header
+
+L3_header:
+ br i1 true, label %L2_header, label %L3_exiting
+
+L3_exiting:
+ br i1 true, label %L3_body, label %L1_latch
+
+; CHECK: L3_body:
+; CHECK-NEXT: %x.lcssa = phi i1
+L3_body:
+ br i1 %x, label %L3_latch, label %L3_latch
+
+L3_latch:
+ br i1 false, label %L3_header, label %exit
+
+L1_latch:
+ br label %L1_header
+
+exit:
+ ret i8 0
+}
OpenPOWER on IntegriCloud