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

Kai Yan via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 8 02:43:43 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)
+  %6 = load i32, ptr %3, align 4
+  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #0
+  %7 = getelementptr inbounds %"struct.MaskedType", ptr %2, i32 0, i32 1
+  store i32 %6, ptr %7, align 4
+  %8 = load i32, ptr %1, align 4
+  %cond = icmp eq i32 %8, 0
+  br i1 %cond, label %4, label %9
+9:                                                ; preds = %4
+  ret i32 0
+}
+
+attributes #0 = { nounwind }
----------------
kaiyan96 wrote:

Fixed

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


More information about the llvm-commits mailing list