[llvm] [MemoryLocation] Model value parameter of memset.pattern intrinsic (PR #138559)

via llvm-commits llvm-commits at lists.llvm.org
Mon May 5 10:43:22 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Philip Reames (preames)

<details>
<summary>Changes</summary>

This parameter may be a pointer if the pointer is being written to the destination, but is neither read or written.

---
Full diff: https://github.com/llvm/llvm-project/pull/138559.diff


2 Files Affected:

- (modified) llvm/lib/Analysis/MemoryLocation.cpp (+4) 
- (modified) llvm/test/Transforms/GVN/memset-pattern.ll (+2-5) 


``````````diff
diff --git a/llvm/lib/Analysis/MemoryLocation.cpp b/llvm/lib/Analysis/MemoryLocation.cpp
index 6e3232772706a..7c474fe1a28b6 100644
--- a/llvm/lib/Analysis/MemoryLocation.cpp
+++ b/llvm/lib/Analysis/MemoryLocation.cpp
@@ -186,6 +186,10 @@ MemoryLocation MemoryLocation::getForArgument(const CallBase *Call,
     case Intrinsic::experimental_memset_pattern:
       assert((ArgIdx == 0 || ArgIdx == 1) &&
              "Invalid argument index for memory intrinsic");
+      if (ArgIdx == 1) {
+        assert(Arg->getType()->isPointerTy());
+        return MemoryLocation(Arg, LocationSize::precise(0), AATags);
+      }
       if (ConstantInt *LenCI = dyn_cast<ConstantInt>(II->getArgOperand(2)))
         return MemoryLocation(
             Arg,
diff --git a/llvm/test/Transforms/GVN/memset-pattern.ll b/llvm/test/Transforms/GVN/memset-pattern.ll
index 20ac87e916757..6fe50867df8dc 100644
--- a/llvm/test/Transforms/GVN/memset-pattern.ll
+++ b/llvm/test/Transforms/GVN/memset-pattern.ll
@@ -49,11 +49,8 @@ define i32 @load_forward_over_memset_pattern(ptr %P, ptr noalias %Q) {
 
 define i32 @load_forward_over_memset_pattern2(ptr %P, ptr noalias %Q) nounwind ssp {
 ; CHECK-LABEL: @load_forward_over_memset_pattern2(
-; CHECK-NEXT:    [[V1:%.*]] = load i32, ptr [[Q:%.*]], align 4
-; CHECK-NEXT:    tail call void @llvm.experimental.memset.pattern.p0.p0.i64(ptr [[P:%.*]], ptr [[Q]], i64 8, i1 false)
-; CHECK-NEXT:    [[V2:%.*]] = load i32, ptr [[Q]], align 4
-; CHECK-NEXT:    [[SUB:%.*]] = sub i32 [[V1]], [[V2]]
-; CHECK-NEXT:    ret i32 [[SUB]]
+; CHECK-NEXT:    tail call void @llvm.experimental.memset.pattern.p0.p0.i64(ptr [[P:%.*]], ptr [[Q:%.*]], i64 8, i1 false)
+; CHECK-NEXT:    ret i32 0
 ;
   %v1 = load i32, ptr %Q
   tail call void @llvm.experimental.memset.pattern(ptr %P, ptr %Q, i64 8, i1 false)

``````````

</details>


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


More information about the llvm-commits mailing list