r195438 - Revert r193994 and part of r193995

Justin Bogner mail at justinbogner.com
Fri Nov 22 02:20:44 PST 2013


Author: bogner
Date: Fri Nov 22 04:20:43 2013
New Revision: 195438

URL: http://llvm.org/viewvc/llvm-project?rev=195438&view=rev
Log:
Revert r193994 and part of r193995

Not long ago I made the CodeGen of for loops simplify the condition at
-O0 in the same way we do for if and conditionals. Unfortunately this
ties how loops and simple conditions work together too tightly, which
makes features such as instrumentation based PGO awkward.

Ultimately, we should find a more general way to simplify the logic in
a given condition, but for now we'll just avoid using EmitBranchOnBool
for loops, like we already do for while and do loops.

Modified:
    cfe/trunk/lib/CodeGen/CGStmt.cpp
    cfe/trunk/test/CodeGen/branch-on-bool.c

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=195438&r1=195437&r2=195438&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Fri Nov 22 04:20:43 2013
@@ -657,7 +657,8 @@ void CodeGenFunction::EmitForStmt(const
 
     // C99 6.8.5p2/p4: The first substatement is executed if the expression
     // compares unequal to 0.  The condition must be a scalar type.
-    EmitBranchOnBoolExpr(S.getCond(), ForBody, ExitBlock);
+    llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
+    Builder.CreateCondBr(BoolCondVal, ForBody, ExitBlock);
 
     if (ExitBlock != LoopExit.getBlock()) {
       EmitBlock(ExitBlock);
@@ -737,7 +738,8 @@ void CodeGenFunction::EmitCXXForRangeStm
 
   // The body is executed if the expression, contextually converted
   // to bool, is true.
-  EmitBranchOnBoolExpr(S.getCond(), ForBody, ExitBlock);
+  llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
+  Builder.CreateCondBr(BoolCondVal, ForBody, ExitBlock);
 
   if (ExitBlock != LoopExit.getBlock()) {
     EmitBlock(ExitBlock);

Modified: cfe/trunk/test/CodeGen/branch-on-bool.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/branch-on-bool.c?rev=195438&r1=195437&r2=195438&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/branch-on-bool.c (original)
+++ cfe/trunk/test/CodeGen/branch-on-bool.c Fri Nov 22 04:20:43 2013
@@ -12,11 +12,3 @@ void fold_if(int a, int b) {
   else
     bar();
 }
-
-void fold_for(int a, int b) {
-  // CHECK: define {{.*}} @fold_for(
-  // CHECK-NOT: = phi
-  // CHECK: }
-  for (int i = 0; a && i < b; ++i) foo();
-  for (int i = 0; a || i < b; ++i) bar();
-}





More information about the cfe-commits mailing list