[llvm] d873630 - Revert "[InstCombine] Generalize ptrtoint(gep) fold (NFC)"

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 12 07:54:32 PDT 2024


Author: Nikita Popov
Date: 2024-07-12T16:54:24+02:00
New Revision: d873630fda191c327c2762c42186fa142c45934a

URL: https://github.com/llvm/llvm-project/commit/d873630fda191c327c2762c42186fa142c45934a
DIFF: https://github.com/llvm/llvm-project/commit/d873630fda191c327c2762c42186fa142c45934a.diff

LOG: Revert "[InstCombine] Generalize ptrtoint(gep) fold (NFC)"

This reverts commit c45f939e34dafaf0f57fd1d93df7df5cc89f1dec.

This refactoring turned out to not be useful for the case I had
originally in mind, so revert it for now.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 5f51c92f95e28..8f83047020936 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -2025,25 +2025,6 @@ Instruction *InstCombinerImpl::visitIntToPtr(IntToPtrInst &CI) {
   return nullptr;
 }
 
-// Whether we should convert ptrtoint(gep P, X) to ptrtoint(P) + X
-static bool shouldPushPtrToIntThroughGEP(GEPOperator *GEP, Type *IntTy,
-                                         const DataLayout &DL) {
-  if (!GEP->hasOneUse())
-    return false;
-
-  // Skip cases whether there is a mismatch between the pointer integer type
-  // and the index type, or the GEP performs an implicit splat operation.
-  if (DL.getIndexType(GEP->getType()) != IntTy ||
-      GEP->getType() != GEP->getPointerOperand()->getType())
-    return false;
-
-  // (ptrtoint (gep (inttoptr Base), Offset)) -> Base + Offset
-  if (match(GEP->getPointerOperand(), m_OneUse(m_IntToPtr(m_Value()))))
-    return true;
-
-  return false;
-}
-
 Instruction *InstCombinerImpl::visitPtrToInt(PtrToIntInst &CI) {
   // If the destination integer type is not the intptr_t type for this target,
   // do a ptrtoint to intptr_t then do a trunc or zext.  This allows the cast
@@ -2083,8 +2064,10 @@ Instruction *InstCombinerImpl::visitPtrToInt(PtrToIntInst &CI) {
     }
 
     // (ptrtoint (gep (inttoptr Base), ...)) -> Base + Offset
-    if (shouldPushPtrToIntThroughGEP(GEP, Ty, DL)) {
-      Value *Base = Builder.CreatePtrToInt(GEP->getPointerOperand(), Ty);
+    Value *Base;
+    if (GEP->hasOneUse() &&
+        match(GEP->getPointerOperand(), m_OneUse(m_IntToPtr(m_Value(Base)))) &&
+        Base->getType() == Ty) {
       Value *Offset = EmitGEPOffset(GEP);
       auto *NewOp = BinaryOperator::CreateAdd(Base, Offset);
       if (GEP->hasNoUnsignedWrap() ||


        


More information about the llvm-commits mailing list