summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2006-02-16 08:27:56 +0000
committerEvan Cheng <evan.cheng@apple.com>2006-02-16 08:27:56 +0000
commit42c01c8d393eb87558b5fb1c99b00a10cdbd3f08 (patch)
treeeae7f92b27f82a011c166af2c9fc0c2b559cd121 /llvm/lib/CodeGen
parent471627c49df22df437694fb3881172e2c771d843 (diff)
downloadbcm5719-llvm-42c01c8d393eb87558b5fb1c99b00a10cdbd3f08.tar.gz
bcm5719-llvm-42c01c8d393eb87558b5fb1c99b00a10cdbd3f08.zip
If the false case is the current basic block, then this is a self loop.
We do not want to emit "Loop: ... brcond Out; br Loop", as it adds an extra instruction in the loop. Instead, invert the condition and emit "Loop: ... br!cond Loop; br Out. Generalize the fix by moving it from PPCDAGToDAGISel to SelectionDAGLowering. llvm-svn: 26231
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index 766f8469689..78f5623aed9 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -562,6 +562,15 @@ void SelectionDAGLowering::visitBr(BranchInst &I) {
} else {
std::vector<SDOperand> Ops;
Ops.push_back(getRoot());
+ // If the false case is the current basic block, then this is a self
+ // loop. We do not want to emit "Loop: ... brcond Out; br Loop", as it
+ // adds an extra instruction in the loop. Instead, invert the
+ // condition and emit "Loop: ... br!cond Loop; br Out.
+ if (CurMBB == Succ1MBB) {
+ std::swap(Succ0MBB, Succ1MBB);
+ SDOperand True = DAG.getConstant(1, Cond.getValueType());
+ Cond = DAG.getNode(ISD::XOR, Cond.getValueType(), Cond, True);
+ }
Ops.push_back(Cond);
Ops.push_back(DAG.getBasicBlock(Succ0MBB));
Ops.push_back(DAG.getBasicBlock(Succ1MBB));
OpenPOWER on IntegriCloud