Fix GlobalOpt to avoid committing a store if the address getelementptr

is missing the inbounds flag. This is slightly conservative, but it
avoids problems with two constants pointing to the same address but
getting distinct entries in the Memory DenseMap.

llvm-svn: 81163
This commit is contained in:
Dan Gohman 2009-09-07 22:40:13 +00:00
parent 19244eaa4a
commit beee35a277
1 changed files with 2 additions and 1 deletions

View File

@ -2032,7 +2032,8 @@ static bool isSimpleEnoughPointerToCommit(Constant *C, LLVMContext &Context) {
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
// Handle a constantexpr gep.
if (CE->getOpcode() == Instruction::GetElementPtr &&
isa<GlobalVariable>(CE->getOperand(0))) {
isa<GlobalVariable>(CE->getOperand(0)) &&
cast<GEPOperator>(CE)->isInBounds()) {
GlobalVariable *GV = cast<GlobalVariable>(CE->getOperand(0));
// Do not allow weak/linkonce/dllimport/dllexport linkage or
// external globals.