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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76252 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp
index c10c6f3..dcb5903 100644
--- a/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/lib/Analysis/BasicAliasAnalysis.cpp
@@ -23,6 +23,7 @@
 #include "llvm/Instructions.h"
 #include "llvm/IntrinsicInst.h"
 #include "llvm/LLVMContext.h"
+#include "llvm/Operator.h"
 #include "llvm/Pass.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/ADT/SmallVector.h"
@@ -38,10 +39,11 @@
 //===----------------------------------------------------------------------===//
 
 static const User *isGEP(const Value *V) {
-  if (isa<GetElementPtrInst>(V) ||
-      (isa<ConstantExpr>(V) &&
-       cast<ConstantExpr>(V)->getOpcode() == Instruction::GetElementPtr))
-    return cast<User>(V);
+  if (const GEPOperator *GEP = dyn_cast<GEPOperator>(V))
+    // For the purposes of BasicAliasAnalysis, if the GEP has overflow it
+    // could do crazy things.
+    if (GEP->hasNoPointerOverflow())
+      return GEP;
   return 0;
 }