From dd35df15a296ca7a6722dc6eb04702e687652c45 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 5 Jan 2012 22:54:35 +0000 Subject: [PATCH] Revert r56315. When the instruction to speculate is a load, this code can incorrectly move the load across a store. This never happens in practice today, but only because the current heuristics accidentally preclude it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147623 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/SimplifyCFG.cpp | 28 ++----------------- .../Transforms/SimplifyCFG/SpeculativeExec.ll | 2 +- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 421156cdf9b..28d3988acc1 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1063,32 +1063,8 @@ static bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *BB1) { return false; } - // If we get here, we can hoist the instruction. Try to place it - // before the icmp instruction preceding the conditional branch. - BasicBlock::iterator InsertPos = BI; - if (InsertPos != BIParent->begin()) - --InsertPos; - // Skip debug info between condition and branch. - while (InsertPos != BIParent->begin() && isa(InsertPos)) - --InsertPos; - if (InsertPos == BrCond && !isa(BrCond)) { - SmallPtrSet BB1Insns; - for(BasicBlock::iterator BB1I = BB1->begin(), BB1E = BB1->end(); - BB1I != BB1E; ++BB1I) - BB1Insns.insert(BB1I); - for(Value::use_iterator UI = BrCond->use_begin(), UE = BrCond->use_end(); - UI != UE; ++UI) { - Instruction *Use = cast(*UI); - if (!BB1Insns.count(Use)) continue; - - // If BrCond uses the instruction that place it just before - // branch instruction. - InsertPos = BI; - break; - } - } else - InsertPos = BI; - BIParent->getInstList().splice(InsertPos, BB1->getInstList(), HInst); + // If we get here, we can hoist the instruction. + BIParent->getInstList().splice(BI, BB1->getInstList(), HInst); // Create a select whose true value is the speculatively executed value and // false value is the previously determined FalseV. diff --git a/test/Transforms/SimplifyCFG/SpeculativeExec.ll b/test/Transforms/SimplifyCFG/SpeculativeExec.ll index 4fbb64a4582..a61867fe89c 100644 --- a/test/Transforms/SimplifyCFG/SpeculativeExec.ll +++ b/test/Transforms/SimplifyCFG/SpeculativeExec.ll @@ -13,8 +13,8 @@ bb1: ; preds = %entry %tmp2 = icmp sgt i32 %c, 1 br i1 %tmp2, label %bb2, label %bb3 ; CHECK: bb1: -; CHECK-NEXT: add i32 %a, 1 ; CHECK-NEXT: icmp sgt i32 %c, 1 +; CHECK-NEXT: add i32 %a, 1 ; CHECK-NEXT: select i1 %tmp2, i32 %tmp3, i32 %a ; CHECK-NEXT: br label %bb3