diff options
| author | Davide Italiano <davide@freebsd.org> | 2018-05-11 15:45:36 +0000 |
|---|---|---|
| committer | Davide Italiano <davide@freebsd.org> | 2018-05-11 15:45:36 +0000 |
| commit | 6e1f7bf316424f3b3af108db4911c09cb24c421c (patch) | |
| tree | e082ae2c2be4d0207c1345eaeb9e4a0558e9f6e7 /llvm | |
| parent | 0f2a48c1ae6d982c7245efd4ceb0673ae1387b90 (diff) | |
| download | bcm5719-llvm-6e1f7bf316424f3b3af108db4911c09cb24c421c.tar.gz bcm5719-llvm-6e1f7bf316424f3b3af108db4911c09cb24c421c.zip | |
[Reassociate] Prevent infinite loops when processing PHIs.
Phi nodes can reside in live blocks but one of their incoming
arguments can come from a dead block. Dead blocks and reassociate
don't play nice together. In fact, reassociate performs an RPO
as a first step to avoid processing dead blocks.
The reason why Reassociate might not fixpoint when examining
dead blocks is that the following:
%xor0 = xor i16 %xor1, undef
%xor1 = xor i16 %xor0, undef
is perfectly valid LLVM IR (if it appears in a dead block),
so the worklist algorithm keeps pushing the two instructions for
reexamination. Note that this is not Reassociate fault, at least
not entirely. It's llvm that has a weird definition of dominance.
Fixes PR37390.
llvm-svn: 332100
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/Reassociate.cpp | 9 | ||||
| -rw-r--r-- | llvm/test/Transforms/Reassociate/infloop-deadphi.ll | 28 |
2 files changed, 36 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp index ad00552f04a..0d1d57d6486 100644 --- a/llvm/lib/Transforms/Scalar/Reassociate.cpp +++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp @@ -1905,7 +1905,14 @@ void ReassociatePass::EraseInst(Instruction *I) { while (Op->hasOneUse() && Op->user_back()->getOpcode() == Opcode && Visited.insert(Op).second) Op = Op->user_back(); - RedoInsts.insert(Op); + + // The instruction we're going to push may be coming from a + // dead block, and Reassociate skips the processing of unreachable + // blocks because it's a waste of time and also because it can + // lead to infinite loop due to LLVM's non-standard definition + // of dominance. + if (ValueRankMap.find(Op) != ValueRankMap.end()) + RedoInsts.insert(Op); } MadeChange = true; diff --git a/llvm/test/Transforms/Reassociate/infloop-deadphi.ll b/llvm/test/Transforms/Reassociate/infloop-deadphi.ll new file mode 100644 index 00000000000..c5a45a4f7eb --- /dev/null +++ b/llvm/test/Transforms/Reassociate/infloop-deadphi.ll @@ -0,0 +1,28 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -reassociate %s -S | FileCheck %s + +target triple = "x86_64-unknown-linux-gnu" + +define void @f() { +; CHECK-LABEL: @f( +; CHECK-NEXT: entry: +; CHECK-NEXT: br label [[DONE:%.*]] +; CHECK: dead: +; CHECK-NEXT: [[XOR0:%.*]] = xor i16 [[XOR1:%.*]], undef +; CHECK-NEXT: [[XOR1]] = xor i16 [[XOR0]], undef +; CHECK-NEXT: br i1 undef, label [[DEAD:%.*]], label [[DONE]] +; CHECK: done: +; CHECK-NEXT: ret void +; +entry: + br label %done + +dead: + %xor0 = xor i16 %xor1, undef + %xor1 = xor i16 %xor0, undef + br i1 undef, label %dead, label %done + +done: + %e = phi i16 [ %xor1, %dead ], [ 0, %entry ] + ret void +} |

