[llvm] [EarlyCSE] Compare GEP instructions based on offset (PR #65875)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 14 01:51:47 PDT 2023


================
@@ -405,6 +412,17 @@ static bool isEqualImpl(SimpleValue LHS, SimpleValue RHS) {
            LII->getArgOperand(1) == RII->getArgOperand(0);
   }
 
+  if (auto *LGEP = dyn_cast<GetElementPtrInst>(LHSI)) {
+    auto *RGEP = cast<GetElementPtrInst>(RHSI);
+    if (LGEP->getOperand(0) != RGEP->getOperand(0))
+      return false;
+    auto &DL = LGEP->getModule()->getDataLayout();
+    APInt LOffset(DL.getIndexTypeSizeInBits(LGEP->getType()), 0);
+    APInt ROffset(DL.getIndexTypeSizeInBits(LGEP->getType()), 0);
----------------
nikic wrote:

nit: Avoid duplicate getIndexTypeSizeInBits() call (can't have different bitwidths if the pointer operand is the same)

https://github.com/llvm/llvm-project/pull/65875


More information about the llvm-commits mailing list