]> granicus.if.org Git - clang/commitdiff
Use EmitBranchOnBoolExpr in VisitConditionalOperator. This
authorChris Lattner <sabre@nondot.org>
Wed, 12 Nov 2008 08:08:13 +0000 (08:08 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 12 Nov 2008 08:08:13 +0000 (08:08 +0000)
shrinks code yet again by a bit.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59114 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprScalar.cpp

index e64ae9ddce1700a37b9409b1693ae3d207743f28..8097e586146161ecb11154a7d556f5ab7c0d70ca 100644 (file)
@@ -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);