summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2016-09-03 21:26:36 +0000
committerXinliang David Li <davidxl@google.com>2016-09-03 21:26:36 +0000
commit241e6c70865b52d72f7e6a28194932d01c12989c (patch)
treed35ecbca767c4a097eaf5bd3a76696f4ab31c644 /llvm/lib/CodeGen
parentebb34348500aa8dd93125e71e36da779339d89a1 (diff)
downloadbcm5719-llvm-241e6c70865b52d72f7e6a28194932d01c12989c.tar.gz
bcm5719-llvm-241e6c70865b52d72f7e6a28194932d01c12989c.zip
[Profile] preserve branch metadata lowering select in CGP
CGP currently drops select's MD_prof profile data when generating conditional branch which can lead to bad code layout. The patch fixes the issue. Differential Revision: http://reviews.llvm.org/D24169 llvm-svn: 280600
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index c87f3bc9073..c6972ec3b33 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -4676,15 +4676,20 @@ bool CodeGenPrepare::optimizeSelectInst(SelectInst *SI) {
// of the condition, it means that side of the branch goes to the end block
// directly and the path originates from the start block from the point of
// view of the new PHI.
+ BasicBlock *TT, *FT;
if (TrueBlock == nullptr) {
- BranchInst::Create(EndBlock, FalseBlock, SI->getCondition(), SI);
+ TT = EndBlock;
+ FT = FalseBlock;
TrueBlock = StartBlock;
} else if (FalseBlock == nullptr) {
- BranchInst::Create(TrueBlock, EndBlock, SI->getCondition(), SI);
+ TT = TrueBlock;
+ FT = EndBlock;
FalseBlock = StartBlock;
} else {
- BranchInst::Create(TrueBlock, FalseBlock, SI->getCondition(), SI);
+ TT = TrueBlock;
+ FT = FalseBlock;
}
+ IRBuilder<>(SI).CreateCondBr(SI->getCondition(), TT, FT, SI);
// The select itself is replaced with a PHI Node.
PHINode *PN = PHINode::Create(SI->getType(), 2, "", &EndBlock->front());
OpenPOWER on IntegriCloud