     }
   }
 
+  /// Build a GEP (Get Element Pointer) instruction.
+  ///
+  /// The `GEP` instruction is often the source of confusion.  LLVM [provides a
+  /// document](http://llvm.org/docs/GetElementPtr.html) to answer questions
+  /// around its semantics and correct usage.
+  ///
+  /// - parameter ptr: The base address for the index calculation.
+  /// - parameter type: The type used to calculate pointer offsets.
+  /// - parameter indices: A list of indices that indicate which of the elements
+  ///   of the aggregate object are indexed.
+  /// - parameter name: The name for the newly inserted instruction.
+  ///
+  /// - returns: A value representing the address of a subelement of the given
+  ///   aggregate data structure value.
+  public func buildGEP(_ ptr: IRValue, type: IRType, indices: [IRValue], name: String = "") -> IRValue {
+    var vals = indices.map { $0.asLLVM() as Optional }
+    return vals.withUnsafeMutableBufferPointer { buf in
+      return LLVMBuildGEP2(llvm, type.asLLVM(), ptr.asLLVM(), buf.baseAddress, UInt32(buf.count), name)
+    }
+  }
+  
   /// Build a GEP (Get Element Pointer) instruction suitable for indexing into
   /// a struct.
   ///

  ///
  /// - returns: A value representing the address of a subelement of the given
  ///   struct value.
  public func buildStructGEP(_ ptr: IRValue, index: Int, name: String = "") -> IRValue {
    return LLVMBuildStructGEP(llvm, ptr.asLLVM(), UInt32(index), name)
  }

  /// Build a GEP (Get Element Pointer) instruction suitable for indexing into
  /// a struct. This uses LLVMBuildStructGEP2 from cllvm
  ///
  /// - parameter ptr: The base address for the index calculation.
  /// - parameter type: The type of the struct to index into. If nil is specified, the
  ///   type property of the pointer is used.
  /// - parameter index: The offset from the base for the index calculation.
  /// - parameter name: The name for the newly inserted instruction.
  ///
  /// - returns: A value representing the address of a subelement of the given
  ///   struct value.
  public func buildStructGEP2(_ ptr: IRValue, type: IRType? = nil, index: Int, name: String = "") -> IRValue {
    let structType = type ?? ptr.type
    return LLVMBuildStructGEP2(llvm, structType.asLLVM(), ptr.asLLVM(), UInt32(index), name)
  }
  
  /// Build an ExtractValue instruction to retrieve an indexed value from a

  ///
  /// - returns: A value representing the result of a load from the given
  ///   pointer value.
  @available(*, deprecated, message: "Use buildLoad(type:ptr:ordering:volatile:alignment:name) instead")
  public func buildLoad(_ ptr: IRValue, ordering: AtomicOrdering = .notAtomic, volatile: Bool = false, alignment: Alignment = .zero, name: String = "") -> IRInstruction {
    let loadInst = LLVMBuildLoad(llvm, ptr.asLLVM(), name)!
    LLVMSetOrdering(loadInst, ordering.llvm)
