diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 236a1fdcced..146d1f50a64 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -441,6 +441,12 @@ public: /// zeros. If so, the result pointer and the first operand have the same /// value, just potentially different types. bool hasAllZeroIndices() const; + + /// hasAllConstantIndices - Return true if all of the indices of this GEP are + /// constant integers. If so, the result pointer and the first operand have + /// a constant offset between them. + bool hasAllConstantIndices() const; + // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const GetElementPtrInst *) { return true; } diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 2bd350080e3..4c792a56afb 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -1043,6 +1043,17 @@ bool GetElementPtrInst::hasAllZeroIndices() const { return true; } +/// hasAllConstantIndices - Return true if all of the indices of this GEP are +/// constant integers. If so, the result pointer and the first operand have +/// a constant offset between them. +bool GetElementPtrInst::hasAllConstantIndices() const { + for (unsigned i = 1, e = getNumOperands(); i != e; ++i) { + if (!isa(getOperand(i))) + return false; + } + return true; +} + //===----------------------------------------------------------------------===// // ExtractElementInst Implementation