diff options
| author | Dan Gohman <gohman@apple.com> | 2009-07-17 22:25:10 +0000 |
|---|---|---|
| committer | Dan Gohman <gohman@apple.com> | 2009-07-17 22:25:10 +0000 |
| commit | 1d548d851a2b04138bf939ab65c0054bdba6052a (patch) | |
| tree | dac728d9f0cd98c43f1135f9127cd8946d20ab2e /llvm/lib/Transforms | |
| parent | 93668002c48ec1eb45119c88aac4821693b425a2 (diff) | |
| download | bcm5719-llvm-1d548d851a2b04138bf939ab65c0054bdba6052a.tar.gz bcm5719-llvm-1d548d851a2b04138bf939ab65c0054bdba6052a.zip | |
Make BasicAliasAnalysis and Value::getUnderlyingObject use
GEPOperator's hasNoPointer0verflow(), and make a few places in instcombine
that create GEPs that may overflow clear the NoOverflow value. Among
other things, this partially addresses PR2831.
llvm-svn: 76252
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 9ddd0e0d923..dbdf449f60f 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2310,7 +2310,10 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { cast<PointerType>(CI->getOperand(0)->getType())->getAddressSpace(); Value *I2 = InsertBitCastBefore(CI->getOperand(0), Context->getPointerType(Type::Int8Ty, AS), I); - I2 = InsertNewInstBefore(GetElementPtrInst::Create(I2, Other, "ctg2"), I); + GetElementPtrInst *GEP = GetElementPtrInst::Create(I2, Other, "ctg2"); + // A GEP formed from an arbitrary add may overflow. + cast<GEPOperator>(GEP)->setHasNoPointerOverflow(false); + I2 = InsertNewInstBefore(GEP, I); return new PtrToIntInst(I2, CI->getType()); } } @@ -8942,7 +8945,12 @@ Instruction *InstCombiner::visitIntToPtr(IntToPtrInst &CI) { // If Offset is evenly divisible by Size, we can do this xform. if (Size && !APIntOps::srem(Offset, APInt(Offset.getBitWidth(), Size))){ Offset = APIntOps::sdiv(Offset, APInt(Offset.getBitWidth(), Size)); - return GetElementPtrInst::Create(X, Context->getConstantInt(Offset)); + GetElementPtrInst *GEP = + GetElementPtrInst::Create(X, Context->getConstantInt(Offset)); + // A gep synthesized from inttoptr+add+ptrtoint must be assumed to + // potentially overflow, in the absense of further analysis. + cast<GEPOperator>(GEP)->setHasNoPointerOverflow(false); + return GEP; } } // TODO: Could handle other cases, e.g. where add is indexing into field of @@ -8966,8 +8974,12 @@ Instruction *InstCombiner::visitIntToPtr(IntToPtrInst &CI) { Instruction *P = InsertNewInstBefore(new IntToPtrInst(X, CI.getType(), "tmp"), CI); - return GetElementPtrInst::Create(P, - Context->getConstantInt(Offset), "tmp"); + GetElementPtrInst *GEP = + GetElementPtrInst::Create(P, Context->getConstantInt(Offset), "tmp"); + // A gep synthesized from inttoptr+add+ptrtoint must be assumed to + // potentially overflow, in the absense of further analysis. + cast<GEPOperator>(GEP)->setHasNoPointerOverflow(false); + return GEP; } } return 0; |

