[llvm] [MemCpyOpt] Fix the invalid code modification for GEP (PR #68479)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 8 02:56:25 PDT 2023


================
@@ -0,0 +1,39 @@
+; RUN: opt -S -passes=memcpyopt < %s -verify-memoryssa | FileCheck %s
+
+; ModuleID = 'memcpy_invalid_modify.ll'
+source_filename = "memcpy_invalid_modify.ll"
+
+%struct.MaskedType = type { i32, i32 }
+
+ at .str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
+
+declare void @llvm.lifetime.start.p0(i64, i8* nocapture) #0
+declare void @llvm.lifetime.end.p0(i64, i8* nocapture) #0
+declare void @MaskedFunction(%struct.MaskedType*, i32 addrspace(1)*)
+
+define i32 @test_gep_modified(ptr noundef %0, ptr noundef %1) {
+; CHECK-NOT: LLVM ERROR: Function @test_gep_modified changed by MemCpyOptPass without invalidating analyses
+; CHECK:   call void @MaskedFunction
+; CHECK:   %7 = getelementptr inbounds %struct.MaskedType
+
+entry:
+  %2 = alloca %struct.MaskedType, align 4
+  %3 = alloca i32, align 4
+  br label %4
+
+4:                                                ; preds = %4, %entry
+  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #0
+  %5 = addrspacecast i32* %3 to i32 addrspace(1)*
+  call void @MaskedFunction(%struct.MaskedType* noundef %1, i32 addrspace(1)* noundef %5)
----------------
nikic wrote:

I still see a lot of non-opaque pointers like `i8*` in here. All of these should be replaced with `ptr`.

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


More information about the llvm-commits mailing list