[PATCH] D155688: [PATCH] [llvm] [InstCombine] Canonicalise ADD+GEP

Nikita Popov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 2 06:39:38 PDT 2023


nikic added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:2338-2340
+    if (BinaryOperator *Idx =
+            dyn_cast_or_null<BinaryOperator>(GEP.getOperand(1)))
+      if ((Idx->getOpcode() == Instruction::Add) && Idx->hasOneUse()) {
----------------



================
Comment at: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:2346
+        //   %newgep = getelementptr i32, i32* %newptr, i64 %idx2
+        Value *Ptr = GEP.getOperand(0);
+        auto *NewPtr = GetElementPtrInst::Create(
----------------



================
Comment at: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:2349
+            GEP.getResultElementType(), Ptr, Idx->getOperand(0), "", &GEP);
+        auto *NewGEP = GetElementPtrInst::Create(GEP.getResultElementType(),
+                                                 NewPtr, Idx->getOperand(1));
----------------
No need for the NewGEP variable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155688



More information about the cfe-commits mailing list