[cfe-commits] r72226 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/blocks-seq.c

Mike Stump mrs at apple.com
Thu May 21 14:05:16 PDT 2009


Author: mrs
Date: Thu May 21 16:05:15 2009
New Revision: 72226

URL: http://llvm.org/viewvc/llvm-project?rev=72226&view=rev
Log:
Fixup blocks codegen for { __block i; i = rhs(); }, we want the rhs
evaluated first.  This can also improve codegen just a bit as we might
have another register to play with for the evaluation of the rhs.

Added:
    cfe/trunk/test/CodeGen/blocks-seq.c
Modified:
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=72226&r1=72225&r2=72226&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Thu May 21 16:05:15 2009
@@ -1189,8 +1189,10 @@
 }
 
 Value *ScalarExprEmitter::VisitBinAssign(const BinaryOperator *E) {
-  LValue LHS = EmitLValue(E->getLHS());
+  // __block variables need to have the rhs evaluated first, plus
+  // this should improve codegen just a little.
   Value *RHS = Visit(E->getRHS());
+  LValue LHS = EmitLValue(E->getLHS());
   
   // Store the value into the LHS.  Bit-fields are handled specially
   // because the result is altered by the store, i.e., [C99 6.5.16p1]

Added: cfe/trunk/test/CodeGen/blocks-seq.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/blocks-seq.c?rev=72226&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/blocks-seq.c (added)
+++ cfe/trunk/test/CodeGen/blocks-seq.c Thu May 21 16:05:15 2009
@@ -0,0 +1,13 @@
+// RUN: clang-cc -fblocks -triple x86_64-apple-darwin10 -emit-llvm -o %t %s &&
+// RUN: grep '%call = call i32 (...)\* @rhs()' %t | count 1 &&
+// If this fails, see about sliding %4 and %5...
+// RUN: grep '%forwarding1 = getelementptr %0\* %i, i32 0, i32 1' %t | count 1 &&
+// RUN: grep '%4 = bitcast i8\*\* %forwarding1 to %0\*\*' %t | count 1 &&
+// RUN: grep '%5 = load %0\*\* %4' %t | count 1
+
+int rhs();
+
+void foo() {
+  __block int i;
+  i = rhs();
+}





More information about the cfe-commits mailing list