File: global-var-constants.ll

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (78 lines) | stat: -rw-r--r-- 1,979 bytes parent folder | download | duplicates (2)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
; RUN:  opt -S --passes=ipsccp,deadargelim --force-specialization                       < %s | FileCheck %s --check-prefix=NO-GLOBALS
; RUN:  opt -S --passes=ipsccp,deadargelim --force-specialization --funcspec-on-address < %s | FileCheck %s --check-prefix=GLOBALS
@G = global [10 x i32] zeroinitializer, align 4

define internal i32 @f(ptr %p) noinline {
entry:
  %0 = load i32, ptr %p, align 4
  store i32 0, ptr %p, align 4
  ret i32 %0
}

define internal i32 @g(i32 %x, i32 %y, ptr %p) noinline {
entry:
  %cmp = icmp sgt i32 %x, %y
  br i1 %cmp, label %if.then, label %if.else

if.then:
  br label %if.end

if.else:
  br label %if.end

if.end:
  %x.addr.0 = phi i32 [ %x, %if.then ], [ 11, %if.else ]
  %p.addr.0 = phi ptr [ @G, %if.then ], [ %p, %if.else ]
  %call = call i32 @f(ptr %p.addr.0)
  %add = add nsw i32 %call, %x.addr.0
  ret i32 %add
}

define i32 @h0(ptr %p) {
entry:
  %call = call i32 @g(i32 2, i32 1, ptr %p)
  ret i32 %call
}

define i32 @h1() {
entry:
  %call = call i32 @f(ptr @G)
  ret i32 %call
}

define i32 @h2() {
entry:
  %call = call i32 @f(ptr getelementptr inbounds (i32, ptr @G, i64 1))
  ret i32 %call
}

; Check if specialisation on the address of a non-const global variable
; is not allowed, then it is not performed.

; NO-GLOBALS-LABEL: define internal i32 @g()
; NO-GLOBALS: call i32 @f(ptr @G)

; NO-GLOBALS-LABEL: define i32 @h0(ptr %p)
; NO-GLOBALS:call i32 @g()

; NO-GLOBALS-LABEL: define i32 @h1()
; NO-GLOBALS: call i32 @f(ptr @G)

; NO-GLOBALS-LABEL: define i32 @h2()
; NO-GLOBALS: call i32 @f(ptr getelementptr inbounds (i32, ptr @G, i64 1))

; Check if specialisation on the address of a non-const global variable
; is allowed, then it is performed where possible.

; GLOBALS-LABEL: define internal i32 @g()
; GLOBALS: call i32 @f.2()

; GLOBALS-LABEL: define i32 @h0(ptr %p)
; GLOBALS: call i32 @g()

; GLOBALS-LABEL: define i32 @h1()
; GLOBALS: call i32 @f.2()

; GLOBALS-LABEL: define i32 @h2()
; GLOBALS: call i32 @f.1()