File: simple-memory.ll

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (62 lines) | stat: -rw-r--r-- 1,821 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
; RUN: opt -passes=called-value-propagation -S < %s | FileCheck %s

target triple = "aarch64-unknown-linux-gnueabi"

@global_function = internal unnamed_addr global ptr null, align 8
@global_array = common unnamed_addr global ptr null, align 8

; This test checks that we propagate the functions through an internal global
; variable, and attach !callees metadata to the call. Such metadata can enable
; optimizations of this code sequence.
;
; For example, since both of the targeted functions have the "nounwind" and
; "readnone" function attributes, LICM can be made to move the call and the
; function pointer load outside the loop. This would then enable the loop
; vectorizer to vectorize the sum reduction.
;
; CHECK: call void %tmp0(), !callees ![[MD:[0-9]+]]
; CHECK: ![[MD]] = !{ptr @invariant_1, ptr @invariant_2}
;
define i64 @test_memory_entry(i64 %n, i1 %flag) {
entry:
  br i1 %flag, label %then, label %else

then:
  store ptr @invariant_1, ptr @global_function
  br label %merge

else:
  store ptr @invariant_2, ptr @global_function
  br label %merge

merge:
  %tmp1 = call i64 @test_memory(i64 %n)
  ret i64 %tmp1
}

define internal i64 @test_memory(i64 %n) {
entry:
  %array = load ptr, ptr @global_array
  br label %for.body

for.body:
  %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]
  %r = phi i64 [ 0, %entry ], [ %tmp3, %for.body ]
  %tmp0 = load ptr, ptr @global_function
  call void %tmp0()
  %tmp1 = getelementptr inbounds i64, ptr %array, i64 %i
  %tmp2 = load i64, ptr %tmp1
  %tmp3 = add i64 %tmp2, %r
  %i.next = add nuw nsw i64 %i, 1
  %cond = icmp slt i64 %i.next, %n
  br i1 %cond, label %for.body, label %for.end

for.end:
  %tmp4 = phi i64 [ %tmp3, %for.body ]
  ret i64 %tmp4
}

declare void @invariant_1() #0
declare void @invariant_2() #0

attributes #0 = { nounwind readnone }