[llvm] [InstCombine] Canonicalize `gep T* X, V / sizeof(T)` to `gep i8* X, V` (PR #76458)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 28 09:04:39 PST 2023


================
@@ -2470,20 +2470,18 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) {
       uint64_t TyAllocSize = DL.getTypeAllocSize(GEPEltType).getFixedValue();
 
       bool Matched = false;
-      uint64_t C;
       Value *V = nullptr;
       if (TyAllocSize == 1) {
         V = GEP.getOperand(1);
         Matched = true;
-      } else if (match(GEP.getOperand(1),
-                       m_AShr(m_Value(V), m_ConstantInt(C)))) {
-        if (TyAllocSize == 1ULL << C)
-          Matched = true;
-      } else if (match(GEP.getOperand(1),
-                       m_SDiv(m_Value(V), m_ConstantInt(C)))) {
-        if (TyAllocSize == C)
-          Matched = true;
-      }
+      } else if (has_single_bit(TyAllocSize) &&
+                 match(GEP.getOperand(1),
+                       m_Exact(m_AShr(m_Value(V), m_SpecificInt(countr_zero(
+                                                      TyAllocSize))))))
+        Matched = true;
+      else if (match(GEP.getOperand(1),
+                     m_Exact(m_SDiv(m_Value(V), m_SpecificInt(TyAllocSize)))))
+        Matched = true;
----------------
dtcxzyw wrote:

Done.

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


More information about the llvm-commits mailing list