xref: /llvm-project/llvm/test/Transforms/ArgumentPromotion/invalidation.ll (revision bcbc6151640f53e9d78392c66de9760c664d8b1d)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
2; Check that when argument promotion changes a function in some parent node of
3; the call graph, any analyses that happened to be cached for that function are
4; actually invalidated. We are using `demanded-bits` here because when printed
5; it will end up caching a value for every instruction, making it easy to
6; detect the instruction-level changes that will fail here. With improper
7; invalidation this will crash in the second printer as it tries to reuse
8; now-invalid demanded bits.
9;
10; RUN: opt < %s -passes='function(print<demanded-bits>),cgscc(argpromotion,function(print<demanded-bits>))' -S | FileCheck %s
11
12@G = constant i32 0
13
14define internal i32 @a(ptr %x) {
15; CHECK-LABEL: define {{[^@]+}}@a
16; CHECK-SAME: (i32 [[X_0_VAL:%.*]]) {
17; CHECK-NEXT:  entry:
18; CHECK-NEXT:    ret i32 [[X_0_VAL]]
19;
20entry:
21  %v = load i32, ptr %x
22  ret i32 %v
23}
24
25define i32 @b() {
26; CHECK-LABEL: define {{[^@]+}}@b() {
27; CHECK-NEXT:  entry:
28; CHECK-NEXT:    [[G_VAL:%.*]] = load i32, ptr @G, align 4
29; CHECK-NEXT:    [[V:%.*]] = call i32 @a(i32 [[G_VAL]])
30; CHECK-NEXT:    ret i32 [[V]]
31;
32entry:
33  %v = call i32 @a(ptr @G)
34  ret i32 %v
35}
36
37define i32 @c() {
38; CHECK-LABEL: define {{[^@]+}}@c() {
39; CHECK-NEXT:  entry:
40; CHECK-NEXT:    [[G_VAL:%.*]] = load i32, ptr @G, align 4
41; CHECK-NEXT:    [[V1:%.*]] = call i32 @a(i32 [[G_VAL]])
42; CHECK-NEXT:    [[V2:%.*]] = call i32 @b()
43; CHECK-NEXT:    [[RESULT:%.*]] = add i32 [[V1]], [[V2]]
44; CHECK-NEXT:    ret i32 [[RESULT]]
45;
46entry:
47  %v1 = call i32 @a(ptr @G)
48  %v2 = call i32 @b()
49  %result = add i32 %v1, %v2
50  ret i32 %result
51}
52