summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-10-24 05:27:19 +0000
committerChris Lattner <sabre@nondot.org>2009-10-24 05:27:19 +0000
commit3db7bd27c25c567cfa606a38cedc47c981d7fc2a (patch)
tree84994cb33b4ccc8b8fabb2da0b7a812160817f05 /llvm/lib/Analysis/ConstantFolding.cpp
parent9e2d5b3b8eccc1d88f849b3bddb5bc48c63c754f (diff)
downloadbcm5719-llvm-3db7bd27c25c567cfa606a38cedc47c981d7fc2a.tar.gz
bcm5719-llvm-3db7bd27c25c567cfa606a38cedc47c981d7fc2a.zip
various cleanups suggested by Duncan
llvm-svn: 84993
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 3fe1d754546..074ff790e1f 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -103,6 +103,8 @@ static bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset,
assert(ByteOffset <= TD.getTypeAllocSize(C->getType()) &&
"Out of range access");
+ // If this element is zero or undefined, we can just return since *CurPtr is
+ // zero initialized.
if (isa<ConstantAggregateZero>(C) || isa<UndefValue>(C))
return true;
@@ -115,7 +117,7 @@ static bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset,
unsigned IntBytes = unsigned(CI->getBitWidth()/8);
for (unsigned i = 0; i != BytesLeft && ByteOffset != IntBytes; ++i) {
- CurPtr[i] = (unsigned char)(Val >> ByteOffset * 8);
+ CurPtr[i] = (unsigned char)(Val >> (ByteOffset * 8));
++ByteOffset;
}
return true;
@@ -130,6 +132,7 @@ static bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset,
C = ConstantExpr::getBitCast(C, Type::getInt32Ty(C->getContext()));
return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, TD);
}
+ return false;
}
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) {
@@ -247,8 +250,7 @@ static Constant *FoldReinterpretLoadFromConstPtr(Constant *C,
return 0;
GlobalVariable *GV = dyn_cast<GlobalVariable>(GVal);
- if (!GV || !GV->isConstant() || !GV->hasInitializer() ||
- !GV->hasDefinitiveInitializer() ||
+ if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer() ||
!GV->getInitializer()->getType()->isSized())
return 0;
OpenPOWER on IntegriCloud