[PATCH] D140697: [MemCpyOpt] Merge succeeding undefs while attempting a `memset`

Jamie Hill-Daniel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 27 09:00:36 PST 2022


clubby789 created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
clubby789 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

`MemCpyOpt` current folds preceeding `undef` stores when creating `MemSetRange`, i.e.
`[undef, undef, undef, 0]`. However, succeeding undefs end the range, meaning that cases
like `[0, undef, 0, undef, 0, undef, 0, undef, 0, undef]` don't get folded. This patch
addresses this case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140697

Files:
  llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp


Index: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -456,8 +456,15 @@
 
       // Check to see if this stored value is of the same byte-splattable value.
       Value *StoredByte = isBytewiseValue(StoredVal, DL);
+      // If the previously stored value is undef, we can replace it with the
+      // newly stored value (which may be undef)
+      // Inversely, if the newly stored value is undef, we can replace it with
+      // the previously stored one
       if (isa<UndefValue>(ByteVal) && StoredByte)
         ByteVal = StoredByte;
+      else if (StoredByte && isa<UndefValue>(StoredByte))
+        StoredByte = ByteVal;
+
       if (ByteVal != StoredByte)
         break;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140697.485382.patch
Type: text/x-patch
Size: 858 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221227/395a1c6b/attachment.bin>


More information about the llvm-commits mailing list