aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/InstCombine/InstCombineCompares.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2013-08-19 21:40:31 +0000
committerMatt Arsenault <Matthew.Arsenault@amd.com>2013-08-19 21:40:31 +0000
commit89062b838789d61460886c5c4c3838690a800de7 (patch)
treeb19350c449b2781c7a3c594763cea8e874e0b447 /lib/Transforms/InstCombine/InstCombineCompares.cpp
parent8227d0f1857c03349f0c5f8ee17e809cee66b217 (diff)
downloadexternal_llvm-89062b838789d61460886c5c4c3838690a800de7.zip
external_llvm-89062b838789d61460886c5c4c3838690a800de7.tar.gz
external_llvm-89062b838789d61460886c5c4c3838690a800de7.tar.bz2
Revert non-test parts of r188507
Re-add the inboundsless tests I didn't add originally git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188710 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineCompares.cpp')
-rw-r--r--lib/Transforms/InstCombine/InstCombineCompares.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 4ac4753..93466ea 100644
--- a/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -226,7 +226,8 @@ static void ComputeUnsignedMinMaxValuesFromKnownBits(const APInt &KnownZero,
Instruction *InstCombiner::
FoldCmpLoadFromIndexedGlobal(GetElementPtrInst *GEP, GlobalVariable *GV,
CmpInst &ICI, ConstantInt *AndCst) {
- if (!GEP->isInBounds())
+ // We need TD information to know the pointer size unless this is inbounds.
+ if (!GEP->isInBounds() && TD == 0)
return 0;
Constant *Init = GV->getInitializer();
@@ -390,6 +391,13 @@ 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.
if (SecondTrueElement != Overdefined) {