[PATCH] D110043: [IR] Add helper to convert offset to GEP indices

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 19 22:56:10 PDT 2021


aeubanks added inline comments.


================
Comment at: llvm/include/llvm/IR/DataLayout.h:583
+  /// Get GEP indices to access Offset inside ElemTy. ElemTy is updated to be
+  /// the result element type and Offset to be the risidual offset.
+  SmallVector<APInt> getIndicesForOffset(Type *&ElemTy, APInt &Offset) const;
----------------
residual


================
Comment at: llvm/include/llvm/IR/DataLayout.h:584
+  /// the result element type and Offset to be the risidual offset.
+  SmallVector<APInt> getIndicesForOffset(Type *&ElemTy, APInt &Offset) const;
+
----------------
`getGEPIndicesForOffset`


================
Comment at: llvm/lib/Analysis/ConstantFolding.cpp:1008
+  // type.
+  // TODO: Should we avoid extra zero indices if it can't be reached anyway?
+  while (ElemTy != ResElemTy) {
----------------
what do you mean by this?


================
Comment at: llvm/lib/Analysis/ConstantFolding.cpp:1020
+  for (const APInt &Index : Indices)
+    NewIdxs.push_back(ConstantInt::get(Type::getIntNTy(Ptr->getContext(),
+                                                       Index.getBitWidth()),
----------------
clang-format?


================
Comment at: llvm/lib/IR/DataLayout.cpp:913
+    Offset += ElemSize;
+  }
+  Indices.push_back(Index);
----------------
`assert(Offset.isPositive())`?
or can this be negative?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110043/new/

https://reviews.llvm.org/D110043



More information about the llvm-commits mailing list