[llvm-commits] [llvm] r71210 - /llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Nick Lewycky nicholas at mxc.ca
Thu May 7 23:47:37 PDT 2009


Author: nicholas
Date: Fri May  8 01:47:37 2009
New Revision: 71210

URL: http://llvm.org/viewvc/llvm-project?rev=71210&view=rev
Log:
This transform requires valid TargetData info. Wrap it in 'if (TD)' in
preparation for the day we use null TargetData when no target is specified.

Modified:
    llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=71210&r1=71209&r2=71210&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Fri May  8 01:47:37 2009
@@ -11196,34 +11196,36 @@
   User *CI = cast<User>(LI.getOperand(0));
   Value *CastOp = CI->getOperand(0);
 
-  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(CI)) {
-    // Instead of loading constant c string, use corresponding integer value
-    // directly if string length is small enough.
-    std::string Str;
-    if (GetConstantStringInfo(CE->getOperand(0), Str) && !Str.empty()) {
-      unsigned len = Str.length();
-      const Type *Ty = cast<PointerType>(CE->getType())->getElementType();
-      unsigned numBits = Ty->getPrimitiveSizeInBits();
-      // Replace LI with immediate integer store.
-      if ((numBits >> 3) == len + 1) {
-        APInt StrVal(numBits, 0);
-        APInt SingleChar(numBits, 0);
-        if (TD->isLittleEndian()) {
-          for (signed i = len-1; i >= 0; i--) {
-            SingleChar = (uint64_t) Str[i] & UCHAR_MAX;
-            StrVal = (StrVal << 8) | SingleChar;
-          }
-        } else {
-          for (unsigned i = 0; i < len; i++) {
-            SingleChar = (uint64_t) Str[i] & UCHAR_MAX;
+  if (TD) {
+    if (ConstantExpr *CE = dyn_cast<ConstantExpr>(CI)) {
+      // Instead of loading constant c string, use corresponding integer value
+      // directly if string length is small enough.
+      std::string Str;
+      if (GetConstantStringInfo(CE->getOperand(0), Str) && !Str.empty()) {
+        unsigned len = Str.length();
+        const Type *Ty = cast<PointerType>(CE->getType())->getElementType();
+        unsigned numBits = Ty->getPrimitiveSizeInBits();
+        // Replace LI with immediate integer store.
+        if ((numBits >> 3) == len + 1) {
+          APInt StrVal(numBits, 0);
+          APInt SingleChar(numBits, 0);
+          if (TD->isLittleEndian()) {
+            for (signed i = len-1; i >= 0; i--) {
+              SingleChar = (uint64_t) Str[i] & UCHAR_MAX;
+              StrVal = (StrVal << 8) | SingleChar;
+            }
+          } else {
+            for (unsigned i = 0; i < len; i++) {
+              SingleChar = (uint64_t) Str[i] & UCHAR_MAX;
+              StrVal = (StrVal << 8) | SingleChar;
+            }
+            // Append NULL at the end.
+            SingleChar = 0;
             StrVal = (StrVal << 8) | SingleChar;
           }
-          // Append NULL at the end.
-          SingleChar = 0;
-          StrVal = (StrVal << 8) | SingleChar;
+          Value *NL = ConstantInt::get(StrVal);
+          return IC.ReplaceInstUsesWith(LI, NL);
         }
-        Value *NL = ConstantInt::get(StrVal);
-        return IC.ReplaceInstUsesWith(LI, NL);
       }
     }
   }





More information about the llvm-commits mailing list