xref: /llvm-project/llvm/test/Transforms/Attributor/ArgumentPromotion/sret.ll (revision 29441e4f5fa5f5c7709f7cf180815ba97f611297)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals
2; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal  -attributor-annotate-decl-cs  -S < %s | FileCheck %s --check-prefixes=CHECK,TUNIT
3; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal  -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,CGSCC
4
5target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
6target triple = "x86_64-pc-windows-msvc"
7
8define internal void @add(ptr %this, ptr sret(i32) %r) {
9;
10; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
11; TUNIT-LABEL: define {{[^@]+}}@add
12; TUNIT-SAME: (ptr noalias nofree nonnull readnone align 8 captures(none) dereferenceable(8) [[THIS:%.*]], ptr noalias nofree noundef nonnull writeonly sret(i32) align 4 captures(none) dereferenceable(4) [[R:%.*]]) #[[ATTR0:[0-9]+]] {
13; TUNIT-NEXT:    store i32 undef, ptr [[R]], align 4
14; TUNIT-NEXT:    ret void
15;
16; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite)
17; CGSCC-LABEL: define {{[^@]+}}@add
18; CGSCC-SAME: (ptr noalias nofree noundef nonnull readonly align 8 captures(none) dereferenceable(8) [[THIS:%.*]], ptr noalias nofree noundef nonnull writeonly sret(i32) align 4 captures(none) dereferenceable(4) [[R:%.*]]) #[[ATTR0:[0-9]+]] {
19; CGSCC-NEXT:    [[BP:%.*]] = getelementptr { i32, i32 }, ptr [[THIS]], i32 0, i32 1
20; CGSCC-NEXT:    [[A:%.*]] = load i32, ptr [[THIS]], align 8
21; CGSCC-NEXT:    [[B:%.*]] = load i32, ptr [[BP]], align 4
22; CGSCC-NEXT:    [[AB:%.*]] = add i32 [[A]], [[B]]
23; CGSCC-NEXT:    store i32 [[AB]], ptr [[R]], align 4
24; CGSCC-NEXT:    ret void
25;
26  %ap = getelementptr {i32, i32}, ptr %this, i32 0, i32 0
27  %bp = getelementptr {i32, i32}, ptr %this, i32 0, i32 1
28  %a = load i32, ptr %ap
29  %b = load i32, ptr %bp
30  %ab = add i32 %a, %b
31  store i32 %ab, ptr %r
32  ret void
33}
34
35define void @f() {
36; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
37; TUNIT-LABEL: define {{[^@]+}}@f
38; TUNIT-SAME: () #[[ATTR1:[0-9]+]] {
39; TUNIT-NEXT:    [[R:%.*]] = alloca i32, align 4
40; TUNIT-NEXT:    call void @add(ptr noalias nofree nonnull readnone align 8 captures(none) dereferenceable(8) undef, ptr noalias nofree noundef nonnull writeonly sret(i32) align 4 captures(none) dereferenceable(4) [[R]]) #[[ATTR2:[0-9]+]]
41; TUNIT-NEXT:    ret void
42;
43; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
44; CGSCC-LABEL: define {{[^@]+}}@f
45; CGSCC-SAME: () #[[ATTR1:[0-9]+]] {
46; CGSCC-NEXT:    [[R:%.*]] = alloca i32, align 4
47; CGSCC-NEXT:    [[PAIR:%.*]] = alloca { i32, i32 }, align 8
48; CGSCC-NEXT:    call void @add(ptr noalias nofree noundef nonnull readonly align 8 captures(none) dereferenceable(8) [[PAIR]], ptr noalias nofree noundef nonnull writeonly sret(i32) align 4 captures(none) dereferenceable(4) [[R]]) #[[ATTR2:[0-9]+]]
49; CGSCC-NEXT:    ret void
50;
51  %r = alloca i32
52  %pair = alloca {i32, i32}
53
54  call void @add(ptr %pair, ptr sret(i32) %r)
55  ret void
56}
57;.
58; TUNIT: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) }
59; TUNIT: attributes #[[ATTR1]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
60; TUNIT: attributes #[[ATTR2]] = { nofree nosync nounwind willreturn memory(write) }
61;.
62; CGSCC: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) }
63; CGSCC: attributes #[[ATTR1]] = { mustprogress nofree nosync nounwind willreturn memory(none) }
64; CGSCC: attributes #[[ATTR2]] = { nofree nounwind willreturn }
65;.
66;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
67; CHECK: {{.*}}
68