[llvm] [InstCombine] Support offsets in `memset` to load forwarding (PR #151924)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 4 08:28:20 PDT 2025


================
@@ -645,7 +650,11 @@ static Value *getAvailableLoadStore(Instruction *Inst, const Value *Ptr,
 
     // Make sure the read bytes are contained in the memset.
     uint64_t LoadSize = LoadTypeSize.getFixedValue();
-    if ((Len->getValue() * 8).ult(LoadSize))
+    if ((Len->getValue() * 8).ult(LoadSize + Offset * 8))
+      return nullptr;
+
+    // If there is an offset, make sure the load size is a multiple of 8.
+    if (Offset && LoadSize % 8 != 0)
----------------
nikic wrote:

I don't really get why this condition is needed / how it relates to the non-zero offset.

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


More information about the llvm-commits mailing list