1 ; RUN: opt -called-value-propagation -S < %s | FileCheck %s
3 target triple = "aarch64-unknown-linux-gnueabi"
5 @global_function = internal unnamed_addr global void ()* null, align 8
6 @global_array = common unnamed_addr global i64* null, align 8
8 ; This test checks that we propagate the functions through an internal global
9 ; variable, and attach !callees metadata to the call. Such metadata can enable
10 ; optimizations of this code sequence.
12 ; For example, since both of the targeted functions have the "nounwind" and
13 ; "readnone" function attributes, LICM can be made to move the call and the
14 ; function pointer load outside the loop. This would then enable the loop
15 ; vectorizer to vectorize the sum reduction.
17 ; CHECK: call void %tmp0(), !callees ![[MD:[0-9]+]]
18 ; CHECK: ![[MD]] = !{void ()* @invariant_1, void ()* @invariant_2}
20 define i64 @test_memory_entry(i64 %n, i1 %flag) {
22 br i1 %flag, label %then, label %else
25 store void ()* @invariant_1, void ()** @global_function
29 store void ()* @invariant_2, void ()** @global_function
33 %tmp1 = call i64 @test_memory(i64 %n)
37 define internal i64 @test_memory(i64 %n) {
39 %array = load i64*, i64** @global_array
43 %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]
44 %r = phi i64 [ 0, %entry ], [ %tmp3, %for.body ]
45 %tmp0 = load void ()*, void ()** @global_function
47 %tmp1 = getelementptr inbounds i64, i64* %array, i64 %i
48 %tmp2 = load i64, i64* %tmp1
49 %tmp3 = add i64 %tmp2, %r
50 %i.next = add nuw nsw i64 %i, 1
51 %cond = icmp slt i64 %i.next, %n
52 br i1 %cond, label %for.body, label %for.end
55 %tmp4 = phi i64 [ %tmp3, %for.body ]
59 declare void @invariant_1() #0
60 declare void @invariant_2() #0
62 attributes #0 = { nounwind readnone }