[InstCombine] icmp eq/ne (gep inbounds P, Idx..), null -> icmp eq/ne P, null for vectors

Extend the transform introduced in https://reviews.llvm.org/D66608 to work for vector geps as well.

Differential Revision: https://reviews.llvm.org/D66671

llvm-svn: 369949
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index b80e9ad..c449117 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -895,7 +895,6 @@
     return new ICmpInst(ICmpInst::getSignedPredicate(Cond), Offset,
                         Constant::getNullValue(Offset->getType()));
   } else if (GEPLHS->isInBounds() && ICmpInst::isEquality(Cond) &&
-             GEPLHS->getType()->isPointerTy() && // TODO: extend to vector geps
              isa<Constant>(RHS) && cast<Constant>(RHS)->isNullValue() &&
              !NullPointerIsDefined(I.getFunction(),
                                    RHS->getType()->getPointerAddressSpace())) {
@@ -914,7 +913,13 @@
     // In general, we're allowed to make values less poison (i.e. remove
     //   sources of full UB), so in this case, we just select between the two
     //   non-poison cases (1 and 4 above).
+    //
+    // For vectors, we apply the same reasoning on a per-lane basis.
     auto *Base = GEPLHS->getPointerOperand();
+    if (GEPLHS->getType()->isVectorTy() && Base->getType()->isPointerTy()) {
+      int NumElts = GEPLHS->getType()->getVectorNumElements();
+      Base = Builder.CreateVectorSplat(NumElts, Base);
+    }
     return new ICmpInst(Cond, Base,
                         ConstantExpr::getBitCast(cast<Constant>(RHS),
                                                  Base->getType()));