[cfe-commits] r72125 - /cfe/trunk/lib/CodeGen/CGExpr.cpp

Anders Carlsson andersca at mac.com
Tue May 19 12:36:20 PDT 2009


Author: andersca
Date: Tue May 19 14:36:19 2009
New Revision: 72125

URL: http://llvm.org/viewvc/llvm-project?rev=72125&view=rev
Log:
Only do the bitcast in EmitStoreOfScalar if the type is a boolean.

Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue May 19 14:36:19 2009
@@ -200,8 +200,7 @@
                                                QualType Ty) {
   llvm::Value *V = Builder.CreateLoad(Addr, Volatile, "tmp");
 
-  // Bool can have different representation in memory than in
-  // registers.
+  // Bool can have different representation in memory than in registers.
   if (Ty->isBooleanType())
     if (V->getType() != llvm::Type::Int1Ty)
       V = Builder.CreateTrunc(V, llvm::Type::Int1Ty, "tobool");
@@ -211,20 +210,18 @@
 
 void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr,
                                         bool Volatile, QualType Ty) {
-  // Handle stores of types which have different representations in memory and
-  // as LLVM values.
-
-  // FIXME: We shouldn't be this loose, we should only do this conversion when
-  // we have a type we know has a different memory representation (e.g., bool).
-
-  const llvm::Type *SrcTy = Value->getType();
-  const llvm::PointerType *DstPtr = cast<llvm::PointerType>(Addr->getType());
-  if (DstPtr->getElementType() != SrcTy) {
-    const llvm::Type *MemTy = 
-      llvm::PointerType::get(SrcTy, DstPtr->getAddressSpace());
-    Addr = Builder.CreateBitCast(Addr, MemTy, "storetmp");
+  
+  if (Ty->isBooleanType()) {
+    // Bool can have different representation in memory than in registers.
+    const llvm::Type *SrcTy = Value->getType();
+    const llvm::PointerType *DstPtr = cast<llvm::PointerType>(Addr->getType());
+    if (DstPtr->getElementType() != SrcTy) {
+      const llvm::Type *MemTy = 
+        llvm::PointerType::get(SrcTy, DstPtr->getAddressSpace());
+      Addr = Builder.CreateBitCast(Addr, MemTy, "storetmp");
+    }
   }
-
+  
   Builder.CreateStore(Value, Addr, Volatile);  
 }
 





More information about the cfe-commits mailing list