From: Chris Lattner Date: Mon, 26 Sep 2005 05:28:52 +0000 (+0000) Subject: Eliminate GetGEPGlobalInitializer in favor of the more powerful X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=ebe61201d182123b699241e31d5123206836515c;p=oota-llvm.git Eliminate GetGEPGlobalInitializer in favor of the more powerful ConstantFoldLoadThroughGEPConstantExpr function in the utils lib. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23446 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index d9d74ca8ea9..491ca73fa3b 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -756,32 +756,6 @@ void SCCPSolver::visitGetElementPtrInst(GetElementPtrInst &I) { markConstant(IV, &I, ConstantExpr::getGetElementPtr(Ptr, Operands)); } -/// GetGEPGlobalInitializer - Given a constant and a getelementptr constantexpr, -/// return the constant value being addressed by the constant expression, or -/// null if something is funny. -/// -static Constant *GetGEPGlobalInitializer(Constant *C, ConstantExpr *CE) { - if (CE->getOperand(1) != Constant::getNullValue(CE->getOperand(1)->getType())) - return 0; // Do not allow stepping over the value! - - // Loop over all of the operands, tracking down which value we are - // addressing... - for (unsigned i = 2, e = CE->getNumOperands(); i != e; ++i) - if (ConstantUInt *CU = dyn_cast(CE->getOperand(i))) { - ConstantStruct *CS = dyn_cast(C); - if (CS == 0) return 0; - if (CU->getValue() >= CS->getNumOperands()) return 0; - C = CS->getOperand((unsigned)CU->getValue()); - } else if (ConstantSInt *CS = dyn_cast(CE->getOperand(i))) { - ConstantArray *CA = dyn_cast(C); - if (CA == 0) return 0; - if ((uint64_t)CS->getValue() >= CA->getNumOperands()) return 0; - C = CA->getOperand((unsigned)CS->getValue()); - } else - return 0; - return C; -} - void SCCPSolver::visitStoreInst(Instruction &SI) { if (TrackedGlobals.empty() || !isa(SI.getOperand(1))) return; @@ -838,7 +812,7 @@ void SCCPSolver::visitLoadInst(LoadInst &I) { if (GlobalVariable *GV = dyn_cast(CE->getOperand(0))) if (GV->isConstant() && !GV->isExternal()) if (Constant *V = - GetGEPGlobalInitializer(GV->getInitializer(), CE)) { + ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE)) { markConstant(IV, &I, V); return; }