diff options
author | Chris Lattner <sabre@nondot.org> | 2010-01-04 18:57:15 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-01-04 18:57:15 +0000 |
commit | d70a2c04170f81534c8a879700bae5938dceeb0f (patch) | |
tree | 58ad48ef96dc55d4dcfa667f438abb2b6b872810 /lib | |
parent | 483868d9c455deb2def9e09d18ba18fd8d4ecebf (diff) | |
download | external_llvm-d70a2c04170f81534c8a879700bae5938dceeb0f.zip external_llvm-d70a2c04170f81534c8a879700bae5938dceeb0f.tar.gz external_llvm-d70a2c04170f81534c8a879700bae5938dceeb0f.tar.bz2 |
Truncate GEP indexes larger than the pointer size down to pointer size
when doing this transform if the GEP is not inbounds. No testcase because
it is very difficult to trigger this: instcombine already canonicalizes
GEP indices to pointer size, so it relies specific permutations of the
instcombine worklist.
Thanks to Duncan for pointing this possible problem out.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92495 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCompares.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index 005f1a0..90ab4f4 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -197,6 +197,9 @@ static void ComputeUnsignedMinMaxValuesFromKnownBits(const APInt &KnownZero, Instruction *InstCombiner:: FoldCmpLoadFromIndexedGlobal(GetElementPtrInst *GEP, GlobalVariable *GV, CmpInst &ICI, ConstantInt *AndCst) { + // We need TD information to know the pointer size unless this is inbounds. + if (!GEP->isInBounds() && TD == 0) return 0; + ConstantArray *Init = dyn_cast<ConstantArray>(GV->getInitializer()); if (Init == 0 || Init->getNumOperands() > 1024) return 0; @@ -354,6 +357,12 @@ FoldCmpLoadFromIndexedGlobal(GetElementPtrInst *GEP, GlobalVariable *GV, // order the state machines in complexity of the generated code. Value *Idx = GEP->getOperand(2); + // If the index is larger than the pointer size of the target, truncate the + // index down like the GEP would do implicitly. We don't have to do this for + // an inbounds GEP because the index can't be out of range. + if (!GEP->isInBounds() && + Idx->getType()->getPrimitiveSizeInBits() > TD->getPointerSizeInBits()) + Idx = Builder->CreateTrunc(Idx, TD->getIntPtrType(Idx->getContext())); // If the comparison is only true for one or two elements, emit direct // comparisons. |