aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-11-12 08:08:13 +0000
committerChris Lattner <sabre@nondot.org>2008-11-12 08:08:13 +0000
commit035cf4294319271ad19ddcc5ba327c8365f3575e (patch)
tree4d0d6a28d110716f349ca9001e684606c5c27278
parent31a0984b5cb4af99d2407c0f25bf5af68df681c6 (diff)
Use EmitBranchOnBoolExpr in VisitConditionalOperator. This
shrinks code yet again by a bit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59114 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGExprScalar.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index e64ae9ddce..8097e58614 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -1129,14 +1129,23 @@ VisitConditionalOperator(const ConditionalOperator *E) {
llvm::BasicBlock *LHSBlock = CGF.createBasicBlock("cond.?");
llvm::BasicBlock *RHSBlock = CGF.createBasicBlock("cond.:");
llvm::BasicBlock *ContBlock = CGF.createBasicBlock("cond.cont");
-
- // Evaluate the conditional, then convert it to bool. We do this explicitly
- // because we need the unconverted value if this is a GNU ?: expression with
- // missing middle value.
- Value *CondVal = CGF.EmitScalarExpr(E->getCond());
- Value *CondBoolVal =CGF.EmitScalarConversion(CondVal, E->getCond()->getType(),
- CGF.getContext().BoolTy);
- Builder.CreateCondBr(CondBoolVal, LHSBlock, RHSBlock);
+ Value *CondVal = 0;
+
+ // If we have the GNU missing condition extension, evaluate the conditional
+ // and then convert it to bool the hard way. We do this explicitly
+ // because we need the unconverted value for the missing middle value of
+ // the ?:.
+ if (E->getLHS() == 0) {
+ CondVal = CGF.EmitScalarExpr(E->getCond());
+ Value *CondBoolVal =
+ CGF.EmitScalarConversion(CondVal, E->getCond()->getType(),
+ CGF.getContext().BoolTy);
+ Builder.CreateCondBr(CondBoolVal, LHSBlock, RHSBlock);
+ } else {
+ // Otherwise, just use EmitBranchOnBoolExpr to get small and simple code for
+ // the branch on bool.
+ CGF.EmitBranchOnBoolExpr(E->getCond(), LHSBlock, RHSBlock);
+ }
CGF.EmitBlock(LHSBlock);