From 15520db9adce8413ef02fd6ffc68ee6aa8d182f0 Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Tue, 2 Dec 2014 18:31:53 +0000 Subject: [PATCH] [SwitchLowering] Handle destinations on multiple phi instructions Follow up from r222926. Also handle multiple destinations from merged cases on multiple and subsequent phi instructions. rdar://problem/19106978 llvm-svn: 223135 --- llvm/lib/Transforms/Utils/LowerSwitch.cpp | 5 +++-- llvm/test/Transforms/Util/lowerswitch.ll | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Transforms/Utils/LowerSwitch.cpp b/llvm/lib/Transforms/Utils/LowerSwitch.cpp index e259562..35cd917 100644 --- a/llvm/lib/Transforms/Utils/LowerSwitch.cpp +++ b/llvm/lib/Transforms/Utils/LowerSwitch.cpp @@ -149,6 +149,7 @@ static void fixPhis(BasicBlock *SuccBB, BasicBlock *OrigBB, BasicBlock *NewBB, // Only update the first occurence. unsigned Idx = 0, E = PN->getNumIncomingValues(); + unsigned LocalNumMergedCases = NumMergedCases; for (; Idx != E; ++Idx) { if (PN->getIncomingBlock(Idx) == OrigBB) { PN->setIncomingBlock(Idx, NewBB); @@ -158,10 +159,10 @@ static void fixPhis(BasicBlock *SuccBB, BasicBlock *OrigBB, BasicBlock *NewBB, // Remove additional occurences coming from condensed cases and keep the // number of incoming values equal to the number of branches to SuccBB. - for (++Idx; NumMergedCases > 0 && Idx != E; ++Idx) + for (++Idx; LocalNumMergedCases > 0 && Idx < E; ++Idx) if (PN->getIncomingBlock(Idx) == OrigBB) { PN->removeIncomingValue(Idx); - NumMergedCases--; + LocalNumMergedCases--; } } } diff --git a/llvm/test/Transforms/Util/lowerswitch.ll b/llvm/test/Transforms/Util/lowerswitch.ll index adbfbda..17c1202 100644 --- a/llvm/test/Transforms/Util/lowerswitch.ll +++ b/llvm/test/Transforms/Util/lowerswitch.ll @@ -45,6 +45,8 @@ bb3: ; CHECK-LABEL: bb3 ; CHECK: %tmp = phi i32 [ 1, %NodeBlock ], [ 0, %bb2 ], [ 1, %LeafBlock3 ] %tmp = phi i32 [ 1, %bb1 ], [ 0, %bb2 ], [ 1, %bb1 ], [ 1, %bb1 ] +; CHECK-NEXT: %tmp2 = phi i32 [ 2, %NodeBlock ], [ 5, %bb2 ], [ 2, %LeafBlock3 ] + %tmp2 = phi i32 [ 2, %bb1 ], [ 2, %bb1 ], [ 5, %bb2 ], [ 2, %bb1 ] br label %exit exit: -- 2.7.4