From 97bd89ece3fff29ab7e0eaa38f85183abd962f42 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 13 Dec 2010 05:34:18 +0000 Subject: [PATCH] fix a bug in r121680 that upset the various buildbots. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121687 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/SimplifyCFG.cpp | 7 +++++ test/Transforms/SimplifyCFG/switch_create.ll | 29 ++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index e16125e8326..9187a0f1752 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1899,6 +1899,13 @@ static bool SimplifyBranchOnICmpChain(BranchInst *BI, const TargetData *TD) { BranchInst::Create(EdgeBB, NewBB, ExtraCase, OldTI); OldTI->eraseFromParent(); + + // If there are PHI nodes in EdgeBB, then we need to add a new entry to them + // for the edge we just added. + for (BasicBlock::iterator I = EdgeBB->begin(); isa(I); ++I) { + PHINode *PN = cast(I); + PN->addIncoming(PN->getIncomingValueForBlock(NewBB), BB); + } BB = NewBB; } diff --git a/test/Transforms/SimplifyCFG/switch_create.ll b/test/Transforms/SimplifyCFG/switch_create.ll index bac457cd9f0..d5347e8afff 100644 --- a/test/Transforms/SimplifyCFG/switch_create.ll +++ b/test/Transforms/SimplifyCFG/switch_create.ll @@ -176,3 +176,32 @@ if.end: ; preds = %entry ; CHECK: i8 97, label %if.then ; CHECK: ] } + +define i32 @test8(i8 zeroext %c, i32 %x, i1 %C) nounwind ssp noredzone { +entry: + br i1 %C, label %N, label %if.then +N: + %cmp = icmp ult i32 %x, 32 + %cmp4 = icmp eq i8 %c, 97 + %or.cond = or i1 %cmp, %cmp4 + %cmp9 = icmp eq i8 %c, 99 + %or.cond11 = or i1 %or.cond, %cmp9 + br i1 %or.cond11, label %if.then, label %if.end + +if.then: ; preds = %entry + %A = phi i32 [0, %entry], [42, %N] + tail call void @foo1() nounwind noredzone + ret i32 %A + +if.end: ; preds = %entry + ret i32 0 + +; CHECK: @test8 +; CHECK: switch.early.test: +; CHECK: switch i8 %c, label %if.end [ +; CHECK: i8 99, label %if.then +; CHECK: i8 97, label %if.then +; CHECK: ] +; CHECK: %A = phi i32 [ 0, %entry ], [ 42, %switch.early.test ], [ 42, %N ], [ 42, %switch.early.test ] + +} -- 2.34.1