@@ -832,6 +832,10 @@ getAsConstantIndexedAddress(Value *V, const DataLayout &DL) {
832
832
static Instruction *transformToIndexedCompare (GEPOperator *GEPLHS, Value *RHS,
833
833
ICmpInst::Predicate Cond,
834
834
const DataLayout &DL) {
835
+ // FIXME: Support vector of pointers.
836
+ if (GEPLHS->getType ()->isVectorTy ())
837
+ return nullptr ;
838
+
835
839
if (!GEPLHS->hasAllConstantIndices ())
836
840
return nullptr ;
837
841
@@ -882,7 +886,9 @@ Instruction *InstCombiner::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
882
886
RHS = RHS->stripPointerCasts ();
883
887
884
888
Value *PtrBase = GEPLHS->getOperand (0 );
885
- if (PtrBase == RHS && GEPLHS->isInBounds ()) {
889
+ // FIXME: Support vector pointer GEPs.
890
+ if (PtrBase == RHS && GEPLHS->isInBounds () &&
891
+ !GEPLHS->getType ()->isVectorTy ()) {
886
892
// ((gep Ptr, OFFSET) cmp Ptr) ---> (OFFSET cmp 0).
887
893
// This transformation (ignoring the base and scales) is valid because we
888
894
// know pointers can't overflow since the gep is inbounds. See if we can
@@ -894,10 +900,12 @@ Instruction *InstCombiner::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
894
900
Offset = EmitGEPOffset (GEPLHS);
895
901
return new ICmpInst (ICmpInst::getSignedPredicate (Cond), Offset,
896
902
Constant::getNullValue (Offset->getType ()));
897
- } else if (GEPLHS->isInBounds () && ICmpInst::isEquality (Cond) &&
898
- isa<Constant>(RHS) && cast<Constant>(RHS)->isNullValue () &&
899
- !NullPointerIsDefined (I.getFunction (),
900
- RHS->getType ()->getPointerAddressSpace ())) {
903
+ }
904
+
905
+ if (GEPLHS->isInBounds () && ICmpInst::isEquality (Cond) &&
906
+ isa<Constant>(RHS) && cast<Constant>(RHS)->isNullValue () &&
907
+ !NullPointerIsDefined (I.getFunction (),
908
+ RHS->getType ()->getPointerAddressSpace ())) {
901
909
// For most address spaces, an allocation can't be placed at null, but null
902
910
// itself is treated as a 0 size allocation in the in bounds rules. Thus,
903
911
// the only valid inbounds address derived from null, is null itself.
@@ -945,11 +953,13 @@ Instruction *InstCombiner::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
945
953
// If we're comparing GEPs with two base pointers that only differ in type
946
954
// and both GEPs have only constant indices or just one use, then fold
947
955
// the compare with the adjusted indices.
956
+ // FIXME: Support vector of pointers.
948
957
if (GEPLHS->isInBounds () && GEPRHS->isInBounds () &&
949
958
(GEPLHS->hasAllConstantIndices () || GEPLHS->hasOneUse ()) &&
950
959
(GEPRHS->hasAllConstantIndices () || GEPRHS->hasOneUse ()) &&
951
960
PtrBase->stripPointerCasts () ==
952
- GEPRHS->getOperand (0 )->stripPointerCasts ()) {
961
+ GEPRHS->getOperand (0 )->stripPointerCasts () &&
962
+ !GEPLHS->getType ()->isVectorTy ()) {
953
963
Value *LOffset = EmitGEPOffset (GEPLHS);
954
964
Value *ROffset = EmitGEPOffset (GEPRHS);
955
965
@@ -993,15 +1003,20 @@ Instruction *InstCombiner::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
993
1003
unsigned DiffOperand = 0 ; // The operand that differs.
994
1004
for (unsigned i = 1 , e = GEPRHS->getNumOperands (); i != e; ++i)
995
1005
if (GEPLHS->getOperand (i) != GEPRHS->getOperand (i)) {
996
- if (GEPLHS->getOperand (i)->getType ()->getPrimitiveSizeInBits () !=
997
- GEPRHS->getOperand (i)->getType ()->getPrimitiveSizeInBits ()) {
1006
+ Type *LHSType = GEPLHS->getOperand (i)->getType ();
1007
+ Type *RHSType = GEPRHS->getOperand (i)->getType ();
1008
+ // FIXME: Better support for vector of pointers.
1009
+ if (LHSType->getPrimitiveSizeInBits () !=
1010
+ RHSType->getPrimitiveSizeInBits () ||
1011
+ (GEPLHS->getType ()->isVectorTy () &&
1012
+ (!LHSType->isVectorTy () || !RHSType->isVectorTy ()))) {
998
1013
// Irreconcilable differences.
999
1014
NumDifferences = 2 ;
1000
1015
break ;
1001
- } else {
1002
- if (NumDifferences++) break ;
1003
- DiffOperand = i;
1004
1016
}
1017
+
1018
+ if (NumDifferences++) break ;
1019
+ DiffOperand = i;
1005
1020
}
1006
1021
1007
1022
if (NumDifferences == 0 ) // SAME GEP?
0 commit comments