From 20da1f07dac4d771e55ee5c7f105ccedfa4caaaa Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Fri, 3 Oct 2008 18:57:37 +0000 Subject: [PATCH] Nick Lewycky's patch. While hosting instruction check PHI node. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57025 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/SimplifyCFG.cpp | 2 +- ...008-10-03-SpeculativelyExecuteBeforePHI.ll | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/Transforms/SimplifyCFG/2008-10-03-SpeculativelyExecuteBeforePHI.ll diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 604a7173845..7f4133630d8 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1051,7 +1051,7 @@ static bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *BB1) { BasicBlock::iterator InsertPos = BI; if (InsertPos != BIParent->begin()) --InsertPos; - if (InsertPos == BrCond) { + if (InsertPos == BrCond && !isa(BrCond)) { SmallPtrSet BB1Insns; for(BasicBlock::iterator BB1I = BB1->begin(), BB1E = BB1->end(); BB1I != BB1E; ++BB1I) diff --git a/test/Transforms/SimplifyCFG/2008-10-03-SpeculativelyExecuteBeforePHI.ll b/test/Transforms/SimplifyCFG/2008-10-03-SpeculativelyExecuteBeforePHI.ll new file mode 100644 index 00000000000..a061a82954b --- /dev/null +++ b/test/Transforms/SimplifyCFG/2008-10-03-SpeculativelyExecuteBeforePHI.ll @@ -0,0 +1,36 @@ +; RUN: llvm-as < %s | opt -simplifycfg +; PR2855 + +define i32 @_Z1fPii(i32* %b, i32 %f) nounwind { +entry: + br label %bb + +bb: ; preds = %bb9, %bb7, %bb, %entry + %__c2.2 = phi i32 [ undef, %entry ], [ %__c2.1, %bb7 ], [ %__c2.1, %bb9 ] ; [#uses=2] + %s.0 = phi i32 [ 0, %entry ], [ 0, %bb7 ], [ %2, %bb9 ] ; [#uses=1] + br label %bb1 + +bb1: ; preds = %bb + %0 = icmp slt i32 0, %f ; [#uses=1] + br i1 %0, label %bb3, label %bb6 + +bb3: ; preds = %bb1 + %1 = icmp eq i32 0, 0 ; [#uses=1] + br i1 %1, label %bb6, label %bb5 + +bb5: ; preds = %bb3 + br label %bb7 + +bb6: ; preds = %bb3, %bb1 + %__c2.0 = phi i32 [ 0, %bb3 ], [ %__c2.2, %bb1 ] ; [#uses=1] + br label %bb7 + +bb7: ; preds = %bb6, %bb5 + %__c2.1 = phi i32 [ 0, %bb5 ], [ %__c2.0, %bb6 ] ; [#uses=2] + %iftmp.1.0 = phi i1 [ false, %bb5 ], [ true, %bb6 ] ; [#uses=1] + br i1 %iftmp.1.0, label %bb, label %bb9 + +bb9: ; preds = %bb7 + %2 = add i32 %s.0, 2 ; [#uses=1] + br label %bb +}