diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2009-05-08 06:47:37 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2009-05-08 06:47:37 +0000 |
commit | 48f95ad971c01878b33b04e497aa45a8b3c8d4d8 (patch) | |
tree | 85b236cfec67afd83cbb799ae0641b7deea972a7 /lib/Transforms/Scalar | |
parent | 45e0010e14d419ebeca9266b9b705867fd251b83 (diff) | |
download | external_llvm-48f95ad971c01878b33b04e497aa45a8b3c8d4d8.zip external_llvm-48f95ad971c01878b33b04e497aa45a8b3c8d4d8.tar.gz external_llvm-48f95ad971c01878b33b04e497aa45a8b3c8d4d8.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71210 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index c285c32..b80fc49 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -11196,34 +11196,36 @@ static Instruction *InstCombineLoadCast(InstCombiner &IC, LoadInst &LI, 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); } } } |