From cd151d2f95eabae61b3cf8e675717d5674afbe85 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 21 Jan 2011 05:29:50 +0000 Subject: fix PR9013, an infinite loop in instcombine. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123968 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstructionCombining.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/Transforms/InstCombine/InstructionCombining.cpp') diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index 06fbaad3e4..2d5773a31f 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -538,9 +538,11 @@ Instruction *InstCombiner::FoldOpIntoPhi(Instruction &I) { if (!PN->hasOneUse()) { // Walk the use list for the instruction, comparing them to I. for (Value::use_iterator UI = PN->use_begin(), E = PN->use_end(); - UI != E; ++UI) - if (!I.isIdenticalTo(cast(*UI))) + UI != E; ++UI) { + Instruction *User = cast(*UI); + if (User != &I && !I.isIdenticalTo(User)) return 0; + } // Otherwise, we can replace *all* users with the new PHI we form. } @@ -565,6 +567,12 @@ Instruction *InstCombiner::FoldOpIntoPhi(Instruction &I) { if (InvokeInst *II = dyn_cast(InVal)) if (II->getParent() == NonConstBB) return 0; + + // If the incoming non-constant value is in I's block, we will remove one + // instruction, but insert another equivalent one, leading to infinite + // instcombine. + if (NonConstBB == I.getParent()) + return 0; } // If there is exactly one non-constant value, we can insert a copy of the -- cgit v1.2.3-70-g09d2