File: deletion-of-loops-that-became-side-effect-free.ll

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (194 lines) | stat: -rw-r--r-- 7,203 bytes parent folder | download | duplicates (3)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes='default<O3>' -S < %s  | FileCheck %s --check-prefixes=ALL,O3
; RUN: opt -passes='default<O2>' -S < %s  | FileCheck %s --check-prefixes=ALL,O2
; RUN: opt -passes='default<O1>' -S < %s  | FileCheck %s --check-prefixes=ALL,O1

; All these tests should optimize to a single comparison
; of the original argument with null. There should be no loops.

%struct.node = type { %struct.node*, i32 }

define dso_local zeroext i1 @is_not_empty_variant1(%struct.node* %p) {
; ALL-LABEL: @is_not_empty_variant1(
; ALL-NEXT:  entry:
; ALL-NEXT:    [[TOBOOL_NOT3_I:%.*]] = icmp ne %struct.node* [[P:%.*]], null
; ALL-NEXT:    ret i1 [[TOBOOL_NOT3_I]]
;
entry:
  %p.addr = alloca %struct.node*, align 8
  store %struct.node* %p, %struct.node** %p.addr, align 8
  %0 = load %struct.node*, %struct.node** %p.addr, align 8
  %call = call i32 @count_nodes_variant1(%struct.node* %0)
  %cmp = icmp sgt i32 %call, 0
  ret i1 %cmp
}

define internal i32 @count_nodes_variant1(%struct.node* %p) {
entry:
  %p.addr = alloca %struct.node*, align 8
  %size = alloca i32, align 4
  store %struct.node* %p, %struct.node** %p.addr, align 8
  %0 = bitcast i32* %size to i8*
  store i32 0, i32* %size, align 4
  br label %while.cond

while.cond:
  %1 = load %struct.node*, %struct.node** %p.addr, align 8
  %tobool = icmp ne %struct.node* %1, null
  br i1 %tobool, label %while.body, label %while.end

while.body:
  %2 = load %struct.node*, %struct.node** %p.addr, align 8
  %next = getelementptr inbounds %struct.node, %struct.node* %2, i32 0, i32 0
  %3 = load %struct.node*, %struct.node** %next, align 8
  store %struct.node* %3, %struct.node** %p.addr, align 8
  %4 = load i32, i32* %size, align 4
  %inc = add nsw i32 %4, 1
  store i32 %inc, i32* %size, align 4
  br label %while.cond, !llvm.loop !0

while.end:
  %5 = load i32, i32* %size, align 4
  %6 = bitcast i32* %size to i8*
  ret i32 %5
}

define dso_local zeroext i1 @is_not_empty_variant2(%struct.node* %p) {
; ALL-LABEL: @is_not_empty_variant2(
; ALL-NEXT:  entry:
; ALL-NEXT:    [[TOBOOL_NOT4_I:%.*]] = icmp ne %struct.node* [[P:%.*]], null
; ALL-NEXT:    ret i1 [[TOBOOL_NOT4_I]]
;
entry:
  %p.addr = alloca %struct.node*, align 8
  store %struct.node* %p, %struct.node** %p.addr, align 8
  %0 = load %struct.node*, %struct.node** %p.addr, align 8
  %call = call i64 @count_nodes_variant2(%struct.node* %0)
  %cmp = icmp ugt i64 %call, 0
  ret i1 %cmp
}

define internal i64 @count_nodes_variant2(%struct.node* %p) {
entry:
  %p.addr = alloca %struct.node*, align 8
  %size = alloca i64, align 8
  store %struct.node* %p, %struct.node** %p.addr, align 8
  %0 = bitcast i64* %size to i8*
  store i64 0, i64* %size, align 8
  br label %while.cond

while.cond:
  %1 = load %struct.node*, %struct.node** %p.addr, align 8
  %tobool = icmp ne %struct.node* %1, null
  br i1 %tobool, label %while.body, label %while.end

while.body:
  %2 = load %struct.node*, %struct.node** %p.addr, align 8
  %next = getelementptr inbounds %struct.node, %struct.node* %2, i32 0, i32 0
  %3 = load %struct.node*, %struct.node** %next, align 8
  store %struct.node* %3, %struct.node** %p.addr, align 8
  %4 = load i64, i64* %size, align 8
  %inc = add i64 %4, 1
  store i64 %inc, i64* %size, align 8
  %5 = load i64, i64* %size, align 8
  %cmp = icmp ne i64 %5, 0
  call void @_ZL6assumeb(i1 zeroext %cmp)
  br label %while.cond, !llvm.loop !2

while.end:
  %6 = load i64, i64* %size, align 8
  %7 = bitcast i64* %size to i8*
  ret i64 %6
}

define dso_local zeroext i1 @is_not_empty_variant3(%struct.node* %p) {
; O3-LABEL: @is_not_empty_variant3(
; O3-NEXT:  entry:
; O3-NEXT:    [[TOBOOL_NOT4_I:%.*]] = icmp ne %struct.node* [[P:%.*]], null
; O3-NEXT:    ret i1 [[TOBOOL_NOT4_I]]
;
; O2-LABEL: @is_not_empty_variant3(
; O2-NEXT:  entry:
; O2-NEXT:    [[TOBOOL_NOT4_I:%.*]] = icmp ne %struct.node* [[P:%.*]], null
; O2-NEXT:    ret i1 [[TOBOOL_NOT4_I]]
;
; O1-LABEL: @is_not_empty_variant3(
; O1-NEXT:  entry:
; O1-NEXT:    [[TOBOOL_NOT4_I:%.*]] = icmp eq %struct.node* [[P:%.*]], null
; O1-NEXT:    br i1 [[TOBOOL_NOT4_I]], label [[COUNT_NODES_VARIANT3_EXIT:%.*]], label [[WHILE_BODY_I:%.*]]
; O1:       while.body.i:
; O1-NEXT:    [[SIZE_06_I:%.*]] = phi i64 [ [[INC_I:%.*]], [[WHILE_BODY_I]] ], [ 0, [[ENTRY:%.*]] ]
; O1-NEXT:    [[P_ADDR_05_I:%.*]] = phi %struct.node* [ [[TMP0:%.*]], [[WHILE_BODY_I]] ], [ [[P]], [[ENTRY]] ]
; O1-NEXT:    [[CMP_I:%.*]] = icmp ne i64 [[SIZE_06_I]], -1
; O1-NEXT:    call void @llvm.assume(i1 [[CMP_I]]) #[[ATTR3:[0-9]+]]
; O1-NEXT:    [[NEXT_I:%.*]] = getelementptr inbounds [[STRUCT_NODE:%.*]], %struct.node* [[P_ADDR_05_I]], i64 0, i32 0
; O1-NEXT:    [[TMP0]] = load %struct.node*, %struct.node** [[NEXT_I]], align 8
; O1-NEXT:    [[INC_I]] = add i64 [[SIZE_06_I]], 1
; O1-NEXT:    [[TOBOOL_NOT_I:%.*]] = icmp eq %struct.node* [[TMP0]], null
; O1-NEXT:    br i1 [[TOBOOL_NOT_I]], label [[COUNT_NODES_VARIANT3_EXIT_LOOPEXIT:%.*]], label [[WHILE_BODY_I]], !llvm.loop [[LOOP0:![0-9]+]]
; O1:       count_nodes_variant3.exit.loopexit:
; O1-NEXT:    [[PHI_CMP:%.*]] = icmp ne i64 [[INC_I]], 0
; O1-NEXT:    br label [[COUNT_NODES_VARIANT3_EXIT]]
; O1:       count_nodes_variant3.exit:
; O1-NEXT:    [[SIZE_0_LCSSA_I:%.*]] = phi i1 [ false, [[ENTRY]] ], [ [[PHI_CMP]], [[COUNT_NODES_VARIANT3_EXIT_LOOPEXIT]] ]
; O1-NEXT:    ret i1 [[SIZE_0_LCSSA_I]]
;
entry:
  %p.addr = alloca %struct.node*, align 8
  store %struct.node* %p, %struct.node** %p.addr, align 8
  %0 = load %struct.node*, %struct.node** %p.addr, align 8
  %call = call i64 @count_nodes_variant3(%struct.node* %0)
  %cmp = icmp ugt i64 %call, 0
  ret i1 %cmp
}

define internal i64 @count_nodes_variant3(%struct.node* %p) {
entry:
  %p.addr = alloca %struct.node*, align 8
  %size = alloca i64, align 8
  store %struct.node* %p, %struct.node** %p.addr, align 8
  %0 = bitcast i64* %size to i8*
  store i64 0, i64* %size, align 8
  br label %while.cond

while.cond:
  %1 = load %struct.node*, %struct.node** %p.addr, align 8
  %tobool = icmp ne %struct.node* %1, null
  br i1 %tobool, label %while.body, label %while.end

while.body:
  %2 = load i64, i64* %size, align 8
  %cmp = icmp ne i64 %2, -1
  call void @_ZL6assumeb(i1 zeroext %cmp)
  %3 = load %struct.node*, %struct.node** %p.addr, align 8
  %next = getelementptr inbounds %struct.node, %struct.node* %3, i32 0, i32 0
  %4 = load %struct.node*, %struct.node** %next, align 8
  store %struct.node* %4, %struct.node** %p.addr, align 8
  %5 = load i64, i64* %size, align 8
  %inc = add i64 %5, 1
  store i64 %inc, i64* %size, align 8
  br label %while.cond, !llvm.loop !3

while.end:
  %6 = load i64, i64* %size, align 8
  %7 = bitcast i64* %size to i8*
  ret i64 %6
}

define internal void @_ZL6assumeb(i1 zeroext %expression) {
entry:
  %expression.addr = alloca i8, align 1
  %frombool = zext i1 %expression to i8
  store i8 %frombool, i8* %expression.addr, align 1
  %0 = load i8, i8* %expression.addr, align 1
  %tobool = trunc i8 %0 to i1
  call void @llvm.assume(i1 %tobool)
  ret void
}

declare void @llvm.assume(i1 noundef)

!0 = distinct !{!0, !1}
!1 = !{!"llvm.loop.mustprogress"}
!2 = distinct !{!2, !1}
!3 = distinct !{!3, !1}