1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=memcpyopt < %s -verify-memoryssa | FileCheck %s
3 declare void @may_throw(ptr nocapture %x)
5 define void @test1(ptr nocapture noalias dereferenceable(4) %x) {
8 ; CHECK-NEXT: [[T:%.*]] = alloca i32, align 4
9 ; CHECK-NEXT: call void @may_throw(ptr nonnull [[T]])
10 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, ptr [[T]], align 4
11 ; CHECK-NEXT: store i32 [[LOAD]], ptr [[X:%.*]], align 4
12 ; CHECK-NEXT: ret void
15 %t = alloca i32, align 4
16 call void @may_throw(ptr nonnull %t)
17 %load = load i32, ptr %t, align 4
18 store i32 %load, ptr %x, align 4
22 declare void @always_throws()
24 define void @test2(ptr nocapture noalias dereferenceable(4) %x) {
25 ; CHECK-LABEL: @test2(
27 ; CHECK-NEXT: [[T:%.*]] = alloca i32, align 4
28 ; CHECK-NEXT: call void @may_throw(ptr nonnull [[T]]) #[[ATTR0:[0-9]+]]
29 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, ptr [[T]], align 4
30 ; CHECK-NEXT: call void @always_throws()
31 ; CHECK-NEXT: store i32 [[LOAD]], ptr [[X:%.*]], align 4
32 ; CHECK-NEXT: ret void
35 %t = alloca i32, align 4
36 call void @may_throw(ptr nonnull %t) nounwind
37 %load = load i32, ptr %t, align 4
38 call void @always_throws()
39 store i32 %load, ptr %x, align 4
43 ; byval argument is not visible on unwind.
44 define void @test_byval(ptr nocapture noalias dereferenceable(4) byval(i32) %x) {
45 ; CHECK-LABEL: @test_byval(
47 ; CHECK-NEXT: [[T:%.*]] = alloca i32, align 4
48 ; CHECK-NEXT: call void @may_throw(ptr nonnull [[X:%.*]])
49 ; CHECK-NEXT: ret void
52 %t = alloca i32, align 4
53 call void @may_throw(ptr nonnull %t)
54 %load = load i32, ptr %t, align 4
55 store i32 %load, ptr %x, align 4
59 define void @test_dead_on_unwind(ptr nocapture noalias writable dead_on_unwind dereferenceable(4) %x) {
60 ; CHECK-LABEL: @test_dead_on_unwind(
62 ; CHECK-NEXT: [[T:%.*]] = alloca i32, align 4
63 ; CHECK-NEXT: call void @may_throw(ptr nonnull [[X:%.*]])
64 ; CHECK-NEXT: ret void
67 %t = alloca i32, align 4
68 call void @may_throw(ptr nonnull %t)
69 %load = load i32, ptr %t, align 4
70 store i32 %load, ptr %x, align 4
74 ; Same as previous test, but dereferenceability information is provided by sret.
75 define void @test_dead_on_unwind_sret(ptr nocapture noalias writable dead_on_unwind sret(i32) %x) {
76 ; CHECK-LABEL: @test_dead_on_unwind_sret(
78 ; CHECK-NEXT: [[T:%.*]] = alloca i32, align 4
79 ; CHECK-NEXT: call void @may_throw(ptr nonnull [[X:%.*]])
80 ; CHECK-NEXT: ret void
83 %t = alloca i32, align 4
84 call void @may_throw(ptr nonnull %t)
85 %load = load i32, ptr %t, align 4
86 store i32 %load, ptr %x, align 4
90 define void @test_dead_on_unwind_missing_writable(ptr nocapture noalias dead_on_unwind dereferenceable(4) %x) {
91 ; CHECK-LABEL: @test_dead_on_unwind_missing_writable(
93 ; CHECK-NEXT: [[T:%.*]] = alloca i32, align 4
94 ; CHECK-NEXT: call void @may_throw(ptr nonnull [[T]])
95 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, ptr [[T]], align 4
96 ; CHECK-NEXT: store i32 [[LOAD]], ptr [[X:%.*]], align 4
97 ; CHECK-NEXT: ret void
100 %t = alloca i32, align 4
101 call void @may_throw(ptr nonnull %t)
102 %load = load i32, ptr %t, align 4
103 store i32 %load, ptr %x, align 4