File: track-ptr-return.ll

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.6-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,304 kB
  • sloc: cpp: 7,438,677; ansic: 1,393,822; asm: 1,012,926; python: 241,650; f90: 86,635; objc: 75,479; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (147 lines) | stat: -rw-r--r-- 4,457 bytes parent folder | download | duplicates (6)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --include-generated-funcs --version 5
; RUN: opt -passes="ipsccp<func-spec>" -force-specialization \
; RUN:     -funcspec-max-iters=3 -S < %s | FileCheck %s

; RUN: opt -passes="ipsccp<func-spec>" -force-specialization          \
; RUN:     -funcspec-for-literal-constant=false -funcspec-max-iters=3 \
; RUN:     -S < %s | FileCheck %s --check-prefix=NOLIT

@global_true = constant i1 true
@global_false = constant i1 false

define i64 @main() {
entry:
  %op1 = call ptr @select_op(ptr @global_true)
  %op2 = call ptr @select_op(ptr @global_false)

  %c1 = call i64 @compute(ptr %op1)
  %c2 = call i64 @compute(ptr %op2)
  %add = add i64 %c1, %c2
  ret i64 %add
}

define ptr @select_op(ptr %flag) {
  %flag.val = load i1, ptr %flag
  %op = select i1 %flag.val, ptr @plus, ptr @minus
  ret ptr %op
}

define internal i64 @compute(ptr %op) {
entry:
  %res = call i64 %op(i64 1)
  ret i64 %res
}

define internal i64 @plus(i64 %x) {
entry:
  %sum = add i64 %x, 1
  ret i64 %sum
}

define internal i64 @minus(i64 %x) {
entry:
  %diff = sub i64 %x, 1
  ret i64 %diff
}
; CHECK-LABEL: define i64 @main() {
; CHECK-NEXT:  [[ENTRY:.*:]]
; CHECK-NEXT:    [[OP1:%.*]] = call ptr @select_op.specialized.1(ptr @global_true)
; CHECK-NEXT:    [[OP2:%.*]] = call ptr @select_op.specialized.2(ptr @global_false)
; CHECK-NEXT:    [[C1:%.*]] = call i64 @compute.specialized.3(ptr @plus)
; CHECK-NEXT:    [[C2:%.*]] = call i64 @compute.specialized.4(ptr @minus)
; CHECK-NEXT:    [[ADD:%.*]] = add i64 [[C1]], [[C2]]
; CHECK-NEXT:    ret i64 [[ADD]]
;
;
; CHECK-LABEL: define ptr @select_op(
; CHECK-SAME: ptr [[FLAG:%.*]]) {
; CHECK-NEXT:    [[FLAG_VAL:%.*]] = load i1, ptr [[FLAG]], align 1
; CHECK-NEXT:    [[OP:%.*]] = select i1 [[FLAG_VAL]], ptr @plus, ptr @minus
; CHECK-NEXT:    ret ptr [[OP]]
;
;
; CHECK-LABEL: define internal i64 @plus(
; CHECK-SAME: i64 [[X:%.*]]) {
; CHECK-NEXT:  [[ENTRY:.*:]]
; CHECK-NEXT:    [[SUM:%.*]] = add i64 [[X]], 1
; CHECK-NEXT:    ret i64 [[SUM]]
;
;
; CHECK-LABEL: define internal i64 @minus(
; CHECK-SAME: i64 [[X:%.*]]) {
; CHECK-NEXT:  [[ENTRY:.*:]]
; CHECK-NEXT:    [[DIFF:%.*]] = sub i64 [[X]], 1
; CHECK-NEXT:    ret i64 [[DIFF]]
;
;
; CHECK-LABEL: define internal ptr @select_op.specialized.1(
; CHECK-SAME: ptr [[FLAG:%.*]]) {
; CHECK-NEXT:    ret ptr poison
;
;
; CHECK-LABEL: define internal ptr @select_op.specialized.2(
; CHECK-SAME: ptr [[FLAG:%.*]]) {
; CHECK-NEXT:    ret ptr poison
;
;
; CHECK-LABEL: define internal i64 @compute.specialized.3(
; CHECK-SAME: ptr [[OP:%.*]]) {
; CHECK-NEXT:  [[ENTRY:.*:]]
; CHECK-NEXT:    [[RES:%.*]] = call i64 @plus(i64 1)
; CHECK-NEXT:    ret i64 [[RES]]
;
;
; CHECK-LABEL: define internal i64 @compute.specialized.4(
; CHECK-SAME: ptr [[OP:%.*]]) {
; CHECK-NEXT:  [[ENTRY:.*:]]
; CHECK-NEXT:    [[RES:%.*]] = call i64 @minus(i64 1)
; CHECK-NEXT:    ret i64 [[RES]]
;
;
; NOLIT-LABEL: define i64 @main() {
; NOLIT-NEXT:  [[ENTRY:.*:]]
; NOLIT-NEXT:    [[OP1:%.*]] = call ptr @select_op.specialized.1(ptr @global_true)
; NOLIT-NEXT:    [[OP2:%.*]] = call ptr @select_op.specialized.2(ptr @global_false)
; NOLIT-NEXT:    [[C1:%.*]] = call i64 @compute(ptr @plus)
; NOLIT-NEXT:    [[C2:%.*]] = call i64 @compute(ptr @minus)
; NOLIT-NEXT:    [[ADD:%.*]] = add i64 [[C1]], [[C2]]
; NOLIT-NEXT:    ret i64 [[ADD]]
;
;
; NOLIT-LABEL: define ptr @select_op(
; NOLIT-SAME: ptr [[FLAG:%.*]]) {
; NOLIT-NEXT:    [[FLAG_VAL:%.*]] = load i1, ptr [[FLAG]], align 1
; NOLIT-NEXT:    [[OP:%.*]] = select i1 [[FLAG_VAL]], ptr @plus, ptr @minus
; NOLIT-NEXT:    ret ptr [[OP]]
;
;
; NOLIT-LABEL: define internal i64 @compute(
; NOLIT-SAME: ptr [[OP:%.*]]) {
; NOLIT-NEXT:  [[ENTRY:.*:]]
; NOLIT-NEXT:    [[RES:%.*]] = call i64 [[OP]](i64 1)
; NOLIT-NEXT:    ret i64 [[RES]]
;
;
; NOLIT-LABEL: define internal i64 @plus(
; NOLIT-SAME: i64 [[X:%.*]]) {
; NOLIT-NEXT:  [[ENTRY:.*:]]
; NOLIT-NEXT:    [[SUM:%.*]] = add i64 [[X]], 1
; NOLIT-NEXT:    ret i64 [[SUM]]
;
;
; NOLIT-LABEL: define internal i64 @minus(
; NOLIT-SAME: i64 [[X:%.*]]) {
; NOLIT-NEXT:  [[ENTRY:.*:]]
; NOLIT-NEXT:    [[DIFF:%.*]] = sub i64 [[X]], 1
; NOLIT-NEXT:    ret i64 [[DIFF]]
;
;
; NOLIT-LABEL: define internal ptr @select_op.specialized.1(
; NOLIT-SAME: ptr [[FLAG:%.*]]) {
; NOLIT-NEXT:    ret ptr poison
;
;
; NOLIT-LABEL: define internal ptr @select_op.specialized.2(
; NOLIT-SAME: ptr [[FLAG:%.*]]) {
; NOLIT-NEXT:    ret ptr poison
;