From fe63f5d5d84cf5b4fe3a00425378d8c10f826a6f Mon Sep 17 00:00:00 2001 From: ManuelJBrito Date: Sat, 24 May 2025 19:24:20 +0100 Subject: [PATCH 1/3] test --- .../NewGVN/coercion-different-ptr.ll | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 llvm/test/Transforms/NewGVN/coercion-different-ptr.ll diff --git a/llvm/test/Transforms/NewGVN/coercion-different-ptr.ll b/llvm/test/Transforms/NewGVN/coercion-different-ptr.ll new file mode 100644 index 0000000000000..c6eb4a2cd179b --- /dev/null +++ b/llvm/test/Transforms/NewGVN/coercion-different-ptr.ll @@ -0,0 +1,53 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 +; RUN: opt < %s -passes=newgvn -S | FileCheck %s + + +; FIXME: MemorySSA says that load1 depends on the lifetime start. +; That's OK since MemorySSA is may-alias; however, NewGVN should +; check whether the lifetime start *actually* defines the loaded pointer +; before simplifying to uninitialized memory. +define void @foo(ptr %arg) { +; CHECK-LABEL: define void @main( +; CHECK-SAME: ptr [[ARG:%.*]]) { +; CHECK-NEXT: [[BB:.*:]] +; CHECK-NEXT: [[ALLOCA:%.*]] = alloca i8, align 16 +; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 1, ptr [[ALLOCA]]) +; CHECK-NEXT: [[LOAD:%.*]] = load ptr, ptr [[ARG]], align 8 +; CHECK-NEXT: [[CALL:%.*]] = call ptr undef(ptr [[ALLOCA]]) +; CHECK-NEXT: ret void +; +bb: + %alloca = alloca i8, align 16 + call void @llvm.lifetime.start.p0(i64 1, ptr %alloca) + %load = load ptr, ptr %arg, align 8 + %load1 = load ptr, ptr %load, align 8 + %call = call ptr %load1(ptr %alloca) + ret void +} + +declare void @llvm.lifetime.start.p0(i64 immarg, ptr captures(none)) #0 + +declare ptr @malloc(i64) + +; This case is handled correctly. +; Since malloc returns a pointer, NewGVN checks whether +; it is the same pointer, an equivalent one, or a must-alias. +define void @wombat(ptr %arg) { +; CHECK-LABEL: define void @wombat( +; CHECK-SAME: ptr [[ARG:%.*]]) { +; CHECK-NEXT: [[BB:.*:]] +; CHECK-NEXT: [[CALL:%.*]] = call ptr @malloc(i64 1) +; CHECK-NEXT: [[LOAD:%.*]] = load ptr, ptr [[ARG]], align 8 +; CHECK-NEXT: [[LOAD1:%.*]] = load ptr, ptr [[LOAD]], align 8 +; CHECK-NEXT: [[CALL2:%.*]] = call ptr [[LOAD1]](ptr [[CALL]]) +; CHECK-NEXT: ret void +; +bb: + %call = call ptr @malloc(i64 1) + %load = load ptr, ptr %arg, align 8 + %load1 = load ptr, ptr %load, align 8 + %call2 = call ptr %load1(ptr %call) + ret void +} + +attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) } From f7f10eb095cd519941c507c711d8538e055238ad Mon Sep 17 00:00:00 2001 From: ManuelJBrito <59119670+ManuelJBrito@users.noreply.github.com> Date: Sun, 25 May 2025 10:31:32 +0100 Subject: [PATCH 2/3] Update coercion-different-ptr.ll --- llvm/test/Transforms/NewGVN/coercion-different-ptr.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/test/Transforms/NewGVN/coercion-different-ptr.ll b/llvm/test/Transforms/NewGVN/coercion-different-ptr.ll index c6eb4a2cd179b..cdcd41e00742b 100644 --- a/llvm/test/Transforms/NewGVN/coercion-different-ptr.ll +++ b/llvm/test/Transforms/NewGVN/coercion-different-ptr.ll @@ -1,5 +1,5 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 -; RUN: opt < %s -passes=newgvn -S | FileCheck %s +; RUN: opt -S -passes=newgvn < %s | FileCheck %s ; FIXME: MemorySSA says that load1 depends on the lifetime start. From 25f27a8df78d9cfcca8e558955547a756815da51 Mon Sep 17 00:00:00 2001 From: ManuelJBrito <59119670+ManuelJBrito@users.noreply.github.com> Date: Mon, 26 May 2025 10:40:22 +0100 Subject: [PATCH 3/3] fix test --- llvm/test/Transforms/NewGVN/coercion-different-ptr.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/test/Transforms/NewGVN/coercion-different-ptr.ll b/llvm/test/Transforms/NewGVN/coercion-different-ptr.ll index cdcd41e00742b..61a6a633788e1 100644 --- a/llvm/test/Transforms/NewGVN/coercion-different-ptr.ll +++ b/llvm/test/Transforms/NewGVN/coercion-different-ptr.ll @@ -7,7 +7,7 @@ ; check whether the lifetime start *actually* defines the loaded pointer ; before simplifying to uninitialized memory. define void @foo(ptr %arg) { -; CHECK-LABEL: define void @main( +; CHECK-LABEL: define void @foo( ; CHECK-SAME: ptr [[ARG:%.*]]) { ; CHECK-NEXT: [[BB:.*:]] ; CHECK-NEXT: [[ALLOCA:%.*]] = alloca i8, align 16