[llvm] [InstCombine] Relax the same-underlying-object constraint for the GEP canonicalization (PR #76583)
    Nikita Popov via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Sun Dec 31 03:43:45 PST 2023
    
    
  
================
@@ -2471,14 +2471,37 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) {
 
       if (TyAllocSize == 1) {
         // Canonicalize (gep i8* X, (ptrtoint Y)-(ptrtoint X)) to (bitcast Y),
-        // but only if both point to the same underlying object (otherwise
-        // provenance is not necessarily retained).
+        // but only if the result pointer is only used as if it were an integer,
+        // or both point to the same underlying object (otherwise provenance is
+        // not necessarily retained).
         Value *X = GEP.getPointerOperand();
         Value *Y;
         if (match(GEP.getOperand(1),
-                  m_Sub(m_PtrToInt(m_Value(Y)), m_PtrToInt(m_Specific(X)))) &&
-            getUnderlyingObject(X) == getUnderlyingObject(Y))
-          return CastInst::CreatePointerBitCastOrAddrSpaceCast(Y, GEPType);
+                  m_Sub(m_PtrToInt(m_Value(Y)), m_PtrToInt(m_Specific(X))))) {
----------------
nikic wrote:
Check that `X->getType() == Y->getType()` and then simplify the code below by dropping the CreatePointerBitCastOrAddrSpaceCast handling. I don't think this generalization is useful anymore, now that it only handles different address spaces.
https://github.com/llvm/llvm-project/pull/76583
    
    
More information about the llvm-commits
mailing list