<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - [ppc] LLVM generates an extra loop"
href="https://llvm.org/bugs/show_bug.cgi?id=30342">30342</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[ppc] LLVM generates an extra loop
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Backend: PowerPC
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>carrot@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Compile the following code with options
--target=powerpc64le-grtev4-linux-gnu -m64 -O2 -mvsx -mcpu=power8
typedef unsigned short T;
int foo(T* array_a, T* array_b, int size_a, int size_b, T* buf) {
int i_a = 0, i_b = 0, idx = 0;
while (i_a < size_a && i_b < size_b) {
if (array_a[i_a] == array_b[i_b]) {
buf[idx++] = array_a[i_a];
i_a++;
i_b++;
} else if (array_a[i_a] > array_b[i_b]) {
i_b++;
} else {
i_a++;
}
}
return idx;
}
Trunk llvm generates:
9 # BB#0: # %entry
10 li 12, 0
11 cmpwi 5, 0
12 std 28, -32(1) # 8-byte Folded Spill
13 std 29, -24(1) # 8-byte Folded Spill
14 std 30, -16(1) # 8-byte Folded Spill
15 cmpwi 1, 6, 0
16 crand 20, 1, 5
17 bc 4, 20, .LBB0_10
18 # BB#1: # %while.body.lr.ph.lr.ph.preheader
19 extsw 8, 6
20 extsw 9, 5
21 addi 4, 4, -2
22 li 11, 0
23 li 10, 0
24 li 30, 0
25 .LBB0_2: # %while.body.lr.ph.lr.ph
26 # =>This Loop Header: Depth=1
27 # Child Loop BB0_3 Depth 2
28 # Child Loop BB0_4 Depth 3
29 extsw 12, 30
30 .LBB0_3: # %while.body.lr.ph
31 # Parent Loop BB0_2 Depth=1
32 # => This Loop Header: Depth=2
33 # Child Loop BB0_4 Depth 3
34 extsw 11, 11
35 sldi 0, 12, 1
36 addi 30, 11, 1
37 lhzx 0, 3, 0
38 sldi 29, 11, 1
39 cmpd 30, 8
40 isel 30, 30, 8, 1
41 sub 28, 30, 11
42 add 30, 4, 29
43 mtctr 28
44 .p2align 5
45 .LBB0_4: # %while.body
46 # Parent Loop BB0_2 Depth=1
47 # Parent Loop BB0_3 Depth=2
48 # => This Inner Loop Header:
Depth=3
49 lhzu 29, 2(30)
50 cmplw 0, 29
51 beq 0, .LBB0_8
52 # BB#5: # %if.else
53 # in Loop: Header=BB0_4 Depth=3
54 ble 0, .LBB0_7
55 # BB#6: # %if.then21
56 # in Loop: Header=BB0_4 Depth=3
57 addi 11, 11, 1
58 bdnz .LBB0_4
59 b .LBB0_9
60 .p2align 4
61 .LBB0_7: # %if.else23
62 # in Loop: Header=BB0_3 Depth=2
63 addi 12, 12, 1
64 cmpw 1, 11, 6
65 cmpd 12, 9
66 crand 20, 0, 4
67 bc 12, 20, .LBB0_3
68 b .LBB0_9
69 .p2align 4
70 .LBB0_8: # %if.then
71 # in Loop: Header=BB0_2 Depth=1
72 addi 30, 12, 1
73 addi 11, 11, 1
74 addi 12, 10, 1
75 sldi 10, 10, 1
76 sthx 0, 7, 10
77 mr 10, 12
78 cmpw 30, 5
79 cmpw 1, 11, 6
80 crand 20, 0, 4
81 bc 12, 20, .LBB0_2
82 b .LBB0_10
83 .LBB0_9:
84 mr 12, 10
85 .LBB0_10: # %while.end
86 extsw 3, 12
87 ld 30, -16(1) # 8-byte Folded Reload
88 ld 29, -24(1) # 8-byte Folded Reload
89 ld 28, -32(1) # 8-byte Folded Reload
90 blr
Although there is only loop in the source code, llvm generates an extra loop
start from .LBB0_4. And the loop preparation work in .LBB0_3 is very slow
because of isel and mtctr.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>