[llvm-commits] [llvm] r66354 - in /llvm/branches/Apple/Dib: lib/Transforms/IPO/GlobalOpt.cpp test/Transforms/GlobalOpt/2009-03-07-PromotePtrToBool.ll

Bill Wendling isanbard at gmail.com
Sat Mar 7 16:56:11 PST 2009


Author: void
Date: Sat Mar  7 18:56:10 2009
New Revision: 66354

URL: http://llvm.org/viewvc/llvm-project?rev=66354&view=rev
Log:
Merge r66351 into Dib:

fix a serious pessimization that Tron on IRC pointed out where we would
"boolify" pointers, generating really awful code because getting the pointer
value requires a load itself.  Before:

_foo:
        movb    $1, _X.b
        ret
_get:
        xorl    %ecx, %ecx
        movb    _X.b, %al
        testb   %al, %al
        movl    $_Y, %eax
        cmove   %ecx, %eax
        ret

With the xform disabled:

_foo:
        movl    $_Y, _X
        ret
_get:
        movl    _X, %eax
        ret

Added:
    llvm/branches/Apple/Dib/test/Transforms/GlobalOpt/2009-03-07-PromotePtrToBool.ll
      - copied unchanged from r66351, llvm/trunk/test/Transforms/GlobalOpt/2009-03-07-PromotePtrToBool.ll
Modified:
    llvm/branches/Apple/Dib/lib/Transforms/IPO/GlobalOpt.cpp

Modified: llvm/branches/Apple/Dib/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Transforms/IPO/GlobalOpt.cpp?rev=66354&r1=66353&r2=66354&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/branches/Apple/Dib/lib/Transforms/IPO/GlobalOpt.cpp Sat Mar  7 18:56:10 2009
@@ -1529,10 +1529,12 @@
   const Type *GVElType = GV->getType()->getElementType();
   
   // If GVElType is already i1, it is already shrunk.  If the type of the GV is
-  // an FP value or vector, don't do this optimization because a select between
-  // them is very expensive and unlikely to lead to later simplification.
+  // an FP value, pointer or vector, don't do this optimization because a select
+  // between them is very expensive and unlikely to lead to later
+  // simplification.  In these cases, we typically end up with "cond ? v1 : v2"
+  // where v1 and v2 both require constant pool loads, a big loss.
   if (GVElType == Type::Int1Ty || GVElType->isFloatingPoint() ||
-      isa<VectorType>(GVElType))
+      isa<PointerType>(GVElType) || isa<VectorType>(GVElType))
     return false;
   
   // Walk the use list of the global seeing if all the uses are load or store.





More information about the llvm-commits mailing list