[PATCH] D124078: [MemCpyOpt] Avoid infinite loop in processMemSetMemCpyDependence (PR54983)

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 22 02:26:05 PDT 2023


fhahn added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp:1298
           Builder.CreatePointerCast(Dest, Builder.getInt8PtrTy(DestAS)),
           SrcSize),
       MemSet->getOperand(1), MemsetLen, Alignment);
----------------
I think the underlying issue here is that the builder folds this GEP to `Dest` is `SrcSize` is poison. This in turn leads to the new MemSet to `must-alias` the original memcpy, causing the cycle IIUC. Could we break the cycle here by bailing out if the pointer folds to `Dest` as more general solution and leave the cleanup of the cases where the size simplifies to 0 to instcombine?


================
Comment at: llvm/test/Transforms/MemCpyOpt/memcpy-zero-size.ll:34
+  call void @llvm.memset.p0.i64(ptr inttoptr (i64 -1 to ptr), i8 0, i64 %len, i1 false)
+  call void @llvm.memcpy.p0.p0.i64(ptr inttoptr (i64 -1 to ptr), ptr null, i64 poison, i1 false)
+  ret void
----------------
might be good to use pointer arguments passed to the function here, instead of `null`/`inttoptr` so the `poison` is the only issue here 


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

https://reviews.llvm.org/D124078



More information about the llvm-commits mailing list