[llvm] [GlobalISel] Allow Legalizer to lower volatile memcpy family. (PR #145997)

Pete Chou via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 26 21:17:47 PDT 2025


================
@@ -10099,8 +10100,8 @@ LegalizerHelper::lowerMemCpyFamily(MachineInstr &MI, unsigned MaxLen) {
   }
 
   bool IsVolatile = MemOp->isVolatile();
-  // Don't try to optimize volatile.
-  if (IsVolatile)
+  // Don't try to optimize volatile when not allowed.
+  if (SkipVolatile && IsVolatile)
----------------
petechou wrote:

ISTM, when the code was first introduced in 13af1ed, it's part of combiner code and used as an optimization for AArch64 to inline memcpy sequence instead of creating libcall. In a later refactoring change 36527cb, the code was moved to legalizer to allow AMDGPU to legalize memcpy family of intrinsics by lowering them. However, the code is still used by [combiner](https://github.com/llvm/llvm-project/blob/61739d76f0093562cecef508766fb73a4a07462b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp#L1702-L1709), and the logic to skip volatile was kept for combiner users. So, that's why I think it's used by some targets as an optimization.

The change tries to make the least change to support both legalizer and combiner users. Another alternative could be deleting the check as you suggested, and do the check in combiner before calling legalizer lowering function instead. That might add some duplicate code like checking zero length and volatile though. What do you think?


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


More information about the llvm-commits mailing list