1 # RUN: llc -mtriple=x86_64-- -run-pass=peephole-opt -o - %s | FileCheck %s
4 define i32 @foo(i32 %a) {
8 bb1: ; preds = %bb7, %bb0
9 %vreg0 = phi i32 [ 0, %bb0 ], [ %vreg3, %bb7 ]
10 %cond0 = icmp eq i32 %a, 0
11 br i1 %cond0, label %bb4, label %bb3
16 bb4: ; preds = %bb1, %bb3
17 %vreg5 = phi i32 [ 2, %bb3 ], [ 1, %bb1 ]
18 %cond1 = icmp eq i32 %vreg5, 0
19 br i1 %cond1, label %bb7, label %bb6
24 bb7: ; preds = %bb4, %bb6
25 %vreg1 = phi i32 [ 2, %bb6 ], [ 1, %bb4 ]
26 %vreg2 = add i32 %vreg5, %vreg0
27 %vreg3 = add i32 %vreg1, %vreg2
28 %cond2 = icmp slt i32 %vreg3, 10
29 br i1 %cond2, label %bb1, label %bb8
35 define i32 @bar(i32 %a, ptr %p) {
39 bb1: ; preds = %bb7, %bb0
40 %vreg0 = phi i32 [ 0, %bb0 ], [ %vreg3, %bb7 ]
41 %cond0 = icmp eq i32 %a, 0
42 br i1 %cond0, label %bb4, label %bb3
47 bb4: ; preds = %bb1, %bb3
48 %vreg5 = phi i32 [ 2, %bb3 ], [ 1, %bb1 ]
49 %cond1 = icmp eq i32 %vreg5, 0
50 br i1 %cond1, label %bb7, label %bb6
55 bb7: ; preds = %bb4, %bb6
56 %vreg1 = phi i32 [ 2, %bb6 ], [ 1, %bb4 ]
57 %vreg2 = add i32 %vreg5, %vreg0
58 store i32 %vreg0, ptr %p
59 %vreg3 = add i32 %vreg1, %vreg2
60 %cond2 = icmp slt i32 %vreg3, 10
61 br i1 %cond2, label %bb1, label %bb8
69 # There is a recurrence formulated around %0, %10, and %3. Check that operands
70 # are commuted for ADD instructions in bb.5.bb7 so that the values involved in
71 # the recurrence are tied. This will remove redundant copy instruction.
73 tracksRegLiveness: true
75 - { id: 0, class: gr32, preferred-register: '' }
76 - { id: 1, class: gr32, preferred-register: '' }
77 - { id: 2, class: gr32, preferred-register: '' }
78 - { id: 3, class: gr32, preferred-register: '' }
79 - { id: 4, class: gr32, preferred-register: '' }
80 - { id: 5, class: gr32, preferred-register: '' }
81 - { id: 6, class: gr32, preferred-register: '' }
82 - { id: 7, class: gr32, preferred-register: '' }
83 - { id: 8, class: gr32, preferred-register: '' }
84 - { id: 9, class: gr32, preferred-register: '' }
85 - { id: 10, class: gr32, preferred-register: '' }
86 - { id: 11, class: gr32, preferred-register: '' }
87 - { id: 12, class: gr32, preferred-register: '' }
89 - { reg: '$edi', virtual-reg: '%4' }
92 successors: %bb.1(0x80000000)
96 %5 = MOV32r0 implicit-def dead $eflags
99 successors: %bb.3(0x30000000), %bb.2(0x50000000)
101 ; CHECK: %0:gr32 = PHI %5, %bb.0, %3, %bb.5
102 %0 = PHI %5, %bb.0, %3, %bb.5
104 TEST32rr %4, %4, implicit-def $eflags
105 JCC_1 %bb.3, 4, implicit $eflags
109 successors: %bb.3(0x80000000)
114 successors: %bb.5(0x30000000), %bb.4(0x50000000)
116 %1 = PHI %6, %bb.1, %7, %bb.2
117 TEST32rr %1, %1, implicit-def $eflags
118 JCC_1 %bb.5, 4, implicit $eflags
122 successors: %bb.5(0x80000000)
127 successors: %bb.1(0x7c000000), %bb.6(0x04000000)
129 %2 = PHI %6, %bb.3, %9, %bb.4
130 %10 = ADD32rr %1, %0, implicit-def dead $eflags
131 ; CHECK: %10:gr32 = ADD32rr
134 %3 = ADD32rr %2, killed %10, implicit-def dead $eflags
135 ; CHECK: %3:gr32 = ADD32rr
138 %11 = SUB32ri8 %3, 10, implicit-def $eflags
139 JCC_1 %bb.1, 12, implicit $eflags
143 %12 = MOV32r0 implicit-def dead $eflags
149 # Here a recurrence is formulated around %0, %11, and %3, but operands should
150 # not be commuted because %0 has a use outside of recurrence. This is to
151 # prevent the case of commuting operands ties the values with overlapping live
154 tracksRegLiveness: true
156 - { id: 0, class: gr32, preferred-register: '' }
157 - { id: 1, class: gr32, preferred-register: '' }
158 - { id: 2, class: gr32, preferred-register: '' }
159 - { id: 3, class: gr32, preferred-register: '' }
160 - { id: 4, class: gr32, preferred-register: '' }
161 - { id: 5, class: gr64, preferred-register: '' }
162 - { id: 6, class: gr32, preferred-register: '' }
163 - { id: 7, class: gr32, preferred-register: '' }
164 - { id: 8, class: gr32, preferred-register: '' }
165 - { id: 9, class: gr32, preferred-register: '' }
166 - { id: 10, class: gr32, preferred-register: '' }
167 - { id: 11, class: gr32, preferred-register: '' }
168 - { id: 12, class: gr32, preferred-register: '' }
169 - { id: 13, class: gr32, preferred-register: '' }
171 - { reg: '$edi', virtual-reg: '%4' }
172 - { reg: '$rsi', virtual-reg: '%5' }
175 successors: %bb.1(0x80000000)
180 %6 = MOV32r0 implicit-def dead $eflags
183 successors: %bb.3(0x30000000), %bb.2(0x50000000)
185 %0 = PHI %6, %bb.0, %3, %bb.5
186 ; CHECK: %0:gr32 = PHI %6, %bb.0, %3, %bb.5
188 TEST32rr %4, %4, implicit-def $eflags
189 JCC_1 %bb.3, 4, implicit $eflags
193 successors: %bb.3(0x80000000)
198 successors: %bb.5(0x30000000), %bb.4(0x50000000)
200 %1 = PHI %7, %bb.1, %8, %bb.2
201 TEST32rr %1, %1, implicit-def $eflags
202 JCC_1 %bb.5, 4, implicit $eflags
206 successors: %bb.5(0x80000000)
211 successors: %bb.1(0x7c000000), %bb.6(0x04000000)
213 %2 = PHI %7, %bb.3, %10, %bb.4
214 %11 = ADD32rr %1, %0, implicit-def dead $eflags
215 ; CHECK: %11:gr32 = ADD32rr
218 MOV32mr %5, 1, $noreg, 0, $noreg, %0 :: (store (s32) into %ir.p)
219 %3 = ADD32rr %2, killed %11, implicit-def dead $eflags
220 ; CHECK: %3:gr32 = ADD32rr
223 %12 = SUB32ri8 %3, 10, implicit-def $eflags
224 JCC_1 %bb.1, 12, implicit $eflags
228 %13 = MOV32r0 implicit-def dead $eflags