File: reordering.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 (163 lines) | stat: -rw-r--r-- 4,533 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
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
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
; RUN: opt -S -passes=normalize -verify-each -norm-rename-all=false < %s | FileCheck %s

define void @foo() {
; CHECK-LABEL: define void @foo() {
; CHECK-NEXT:  bb17254:
; CHECK-NEXT:    ret void
;
  ret void
}

define void @empty_basic_block() {
; CHECK-LABEL: define void @empty_basic_block() {
; CHECK-NEXT:  exit:
; CHECK-NEXT:    ret void
;
exit:
  ret void
}

declare void @effecting()

; Place dead instruction(s) before the terminator
define void @call_effecting() {
; CHECK-LABEL: define void @call_effecting() {
; CHECK-NEXT:  bb15160:
; CHECK-NEXT:    call void @effecting()
; CHECK-NEXT:    [[TMP0:%.*]] = add i32 0, 1
; CHECK-NEXT:    ret void
;
  %1 = add i32 0, 1
  call void @effecting()
  ret void
}

define void @dont_move_above_phi() {
; CHECK-LABEL: define void @dont_move_above_phi() {
; CHECK-NEXT:  bb76951:
; CHECK-NEXT:    br label [[EXIT:%.*]]
; CHECK:       exit:
; CHECK-NEXT:    [[TMP0:%.*]] = phi i32 [ 0, [[BB76951:%.*]] ]
; CHECK-NEXT:    call void @effecting()
; CHECK-NEXT:    ret void
;
  br label %exit
exit:
  %1 = phi i32 [0, %0]
  call void @effecting()
  ret void
}

define void @dont_move_above_alloca() {
; CHECK-LABEL: define void @dont_move_above_alloca() {
; CHECK-NEXT:  bb15160:
; CHECK-NEXT:    [[TMP0:%.*]] = alloca i32, align 4
; CHECK-NEXT:    call void @effecting()
; CHECK-NEXT:    ret void
;
  %1 = alloca i32
  call void @effecting()
  ret void
}

declare void @effecting1()

define void @dont_reorder_effecting() {
; CHECK-LABEL: define void @dont_reorder_effecting() {
; CHECK-NEXT:  bb10075:
; CHECK-NEXT:    call void @effecting()
; CHECK-NEXT:    call void @effecting1()
; CHECK-NEXT:    ret void
;
  call void @effecting()
  call void @effecting1()
  ret void
}

declare void @effecting2(i32)

define void @dont_reorder_effecting1() {
; CHECK-LABEL: define void @dont_reorder_effecting1() {
; CHECK-NEXT:  bb10075:
; CHECK-NEXT:    [[ONE:%.*]] = add i32 1, 1
; CHECK-NEXT:    call void @effecting2(i32 [[ONE]])
; CHECK-NEXT:    [[TWO:%.*]] = add i32 2, 2
; CHECK-NEXT:    call void @effecting2(i32 [[TWO]])
; CHECK-NEXT:    ret void
;
  %one = add i32 1, 1
  %two = add i32 2, 2
  call void @effecting2(i32 %one)
  call void @effecting2(i32 %two)
  ret void
}

define void @dont_reorder_across_blocks() {
; CHECK-LABEL: define void @dont_reorder_across_blocks() {
; CHECK-NEXT:  bb76951:
; CHECK-NEXT:    [[ONE:%.*]] = add i32 1, 1
; CHECK-NEXT:    br label [[EXIT:%.*]]
; CHECK:       exit:
; CHECK-NEXT:    call void @effecting2(i32 [[ONE]])
; CHECK-NEXT:    ret void
;
  %one = add i32 1, 1
  br label %exit
exit:
  call void @effecting2(i32 %one)
  ret void
}

define void @independentldst(ptr %a, ptr %b) {
; CHECK-LABEL: define void @independentldst(
; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]]) {
; CHECK-NEXT:  bb10495:
; CHECK-NEXT:    %"vl12961([[B]])" = load i32, ptr [[B]], align 4
; CHECK-NEXT:    store i32 %"vl12961([[B]])", ptr [[A]], align 4
; CHECK-NEXT:    %"vl89528([[A]])" = load i32, ptr [[A]], align 4
; CHECK-NEXT:    store i32 %"vl89528([[A]])", ptr [[B]], align 4
; CHECK-NEXT:    ret void
;
  %2 = load i32, ptr %a
  %3 = load i32, ptr %b
  store i32 %3, ptr %a
  store i32 %2, ptr %b
  ret void
}

define void @multiple_use_ld(ptr %a, ptr %b) {
; CHECK-LABEL: define void @multiple_use_ld(
; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]]) {
; CHECK-NEXT:  bb14927:
; CHECK-NEXT:    %"vl16793([[A]])" = load i32, ptr [[A]], align 4
; CHECK-NEXT:    store i32 %"vl16793([[A]])", ptr [[A]], align 4
; CHECK-NEXT:    %"vl89528([[B]])" = load i32, ptr [[B]], align 4
; CHECK-NEXT:    store i32 %"vl89528([[B]])", ptr [[B]], align 4
; CHECK-NEXT:    store i32 %"vl16793([[A]])", ptr [[A]], align 4
; CHECK-NEXT:    ret void
;
  %2 = load i32, ptr %a
  store i32 %2, ptr %a
  %3 = load i32, ptr %b
  store i32 %3, ptr %b
  store i32 %2, ptr %a
  ret void
}

; This is an incorrect transformation. Moving the store above the load could
; change the loaded value. To do this, the pointers would need to be `noalias`.
define void @undef_st(ptr %a, ptr %b) {
; CHECK-LABEL: define void @undef_st(
; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]]) {
; CHECK-NEXT:  bb10495:
; CHECK-NEXT:    store i32 undef, ptr [[B]], align 4
; CHECK-NEXT:    %"vl16028([[A]])" = load i32, ptr [[A]], align 4
; CHECK-NEXT:    store i32 %"vl16028([[A]])", ptr [[A]], align 4
; CHECK-NEXT:    ret void
;
  %2 = load i32, ptr %a
  store i32 undef, ptr %b
  store i32 %2, ptr %a
  ret void
}