Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Commit

Permalink
Merge from mainline.
Browse files Browse the repository at this point in the history
git-svn-id: http://llvm.org/svn/llvm-project/llvm/branches/release_20@37213 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
tlattner committed May 18, 2007
1 parent 99ac095 commit 21ce360
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
5 changes: 4 additions & 1 deletion lib/Transforms/IPO/GlobalOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,10 @@ static bool OptimizeAwayTrappingUsesOfLoads(GlobalVariable *GV, Constant *LV) {
Loads.push_back(LI);
Changed |= OptimizeAwayTrappingUsesOfValue(LI, LV);
} else {
assert(isa<StoreInst>(*GUI) && "Only expect load and stores!");
// If we get here we could have stores, loads, or phi nodes whose values
// are loaded.
assert((isa<StoreInst>(*GUI) || isa<PHINode>(*GUI)) &&
"Only expect load and stores!");
}

if (Changed) {
Expand Down
23 changes: 16 additions & 7 deletions lib/Transforms/Scalar/InstructionCombining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6449,16 +6449,25 @@ Instruction *InstCombiner::commonPointerCastTransforms(CastInst &CI) {
while (Offset) {
if (const StructType *STy = dyn_cast<StructType>(GEPIdxTy)) {
const StructLayout *SL = TD->getStructLayout(STy);
unsigned Elt = SL->getElementContainingOffset(Offset);
NewIndices.push_back(ConstantInt::get(Type::Int32Ty, Elt));
if (Offset < (int64_t)SL->getSizeInBytes()) {
unsigned Elt = SL->getElementContainingOffset(Offset);
NewIndices.push_back(ConstantInt::get(Type::Int32Ty, Elt));

Offset -= SL->getElementOffset(Elt);
GEPIdxTy = STy->getElementType(Elt);
Offset -= SL->getElementOffset(Elt);
GEPIdxTy = STy->getElementType(Elt);
} else {
// Otherwise, we can't index into this, bail out.
Offset = 0;
OrigBase = 0;
}
} else if (isa<ArrayType>(GEPIdxTy) || isa<VectorType>(GEPIdxTy)) {
const SequentialType *STy = cast<SequentialType>(GEPIdxTy);
uint64_t EltSize = TD->getTypeSize(STy->getElementType());
NewIndices.push_back(ConstantInt::get(IntPtrTy, Offset/EltSize));
Offset %= EltSize;
if (uint64_t EltSize = TD->getTypeSize(STy->getElementType())) {
NewIndices.push_back(ConstantInt::get(IntPtrTy,Offset/EltSize));
Offset %= EltSize;
} else {
NewIndices.push_back(ConstantInt::get(IntPtrTy, 0));
}
GEPIdxTy = STy->getElementType();
} else {
// Otherwise, we can't index into this, bail out.
Expand Down

0 comments on commit 21ce360

Please sign in to comment.