Revert "[opaque pointer type] Pass explicit pointer type through GEP constant folding"
[oota-llvm.git] / lib / IR / Constants.cpp
index b598c2807ceb4f49371a88d1ba7a4cc6f5ec9b5a..20a5206c2300716c94f40d84b5a5bddcf3dbac7a 100644 (file)
@@ -2015,16 +2015,14 @@ Constant *ConstantExpr::getSelect(Constant *C, Constant *V1, Constant *V2,
 Constant *ConstantExpr::getGetElementPtr(Type *Ty, Constant *C,
                                          ArrayRef<Value *> Idxs, bool InBounds,
                                          Type *OnlyIfReducedTy) {
+  if (Constant *FC = ConstantFoldGetElementPtr(C, InBounds, Idxs))
+    return FC;          // Fold a few common cases.
+
   if (!Ty)
     Ty = cast<PointerType>(C->getType()->getScalarType())->getElementType();
   else
-    assert(
-        Ty ==
-        cast<PointerType>(C->getType()->getScalarType())->getContainedType(0u));
-
-  if (Constant *FC = ConstantFoldGetElementPtr(Ty, C, InBounds, Idxs))
-    return FC;          // Fold a few common cases.
-
+    assert(Ty ==
+           cast<PointerType>(C->getType()->getScalarType())->getElementType());
   // Get the result type of the getelementptr!
   Type *DestTy = GetElementPtrInst::getIndexedType(Ty, Idxs);
   assert(DestTy && "GEP indices invalid!");