Skip to content

[NewGVN] Precommit test #141362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions llvm/test/Transforms/NewGVN/coercion-different-ptr.ll
Original file line number Diff line number Diff line change
@@ -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 @foo(
; 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) }
Loading