xref: /llvm-project/llvm/test/Transforms/Attributor/ArgumentPromotion/control-flow.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
5; Don't promote around control flow.
6define internal i32 @callee(i1 %C, ptr %P) {
7; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
8; CHECK-LABEL: define {{[^@]+}}@callee
9; CHECK-SAME: (i1 noundef [[C:%.*]], ptr nofree readonly captures(none) [[P:%.*]]) #[[ATTR0:[0-9]+]] {
10; CHECK-NEXT:  entry:
11; CHECK-NEXT:    br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
12; CHECK:       T:
13; CHECK-NEXT:    ret i32 17
14; CHECK:       F:
15; CHECK-NEXT:    [[X:%.*]] = load i32, ptr [[P]], align 4
16; CHECK-NEXT:    ret i32 [[X]]
17;
18entry:
19  br i1 %C, label %T, label %F
20
21T:
22  ret i32 17
23
24F:
25  %X = load i32, ptr %P
26  ret i32 %X
27}
28
29define i32 @foo(i1 %C, ptr %P) {
30; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
31; TUNIT-LABEL: define {{[^@]+}}@foo
32; TUNIT-SAME: (i1 [[C:%.*]], ptr nofree readonly captures(none) [[P:%.*]]) #[[ATTR0]] {
33; TUNIT-NEXT:  entry:
34; TUNIT-NEXT:    [[X:%.*]] = call i32 @callee(i1 noundef [[C]], ptr nofree readonly captures(none) [[P]]) #[[ATTR1:[0-9]+]]
35; TUNIT-NEXT:    ret i32 [[X]]
36;
37; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(argmem: read)
38; CGSCC-LABEL: define {{[^@]+}}@foo
39; CGSCC-SAME: (i1 noundef [[C:%.*]], ptr nofree readonly captures(none) [[P:%.*]]) #[[ATTR1:[0-9]+]] {
40; CGSCC-NEXT:  entry:
41; CGSCC-NEXT:    [[X:%.*]] = call i32 @callee(i1 noundef [[C]], ptr nofree readonly captures(none) [[P]]) #[[ATTR2:[0-9]+]]
42; CGSCC-NEXT:    ret i32 [[X]]
43;
44entry:
45  %X = call i32 @callee(i1 %C, ptr %P)
46  ret i32 %X
47}
48
49;.
50; TUNIT: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) }
51; TUNIT: attributes #[[ATTR1]] = { nofree nosync nounwind willreturn memory(read) }
52;.
53; CGSCC: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) }
54; CGSCC: attributes #[[ATTR1]] = { mustprogress nofree nosync nounwind willreturn memory(argmem: read) }
55; CGSCC: attributes #[[ATTR2]] = { nofree willreturn memory(read) }
56;.
57