<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - Redundant phi elimination"
href="https://bugs.llvm.org/show_bug.cgi?id=44287">44287</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Redundant phi elimination
</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>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>david.bolvansky@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>int comp(int max, int pos, unsigned char *cur)
{
unsigned char *p = cur + pos;
int len = 0;
while (++len != max)
if (p[len] != cur[len])
break;
return cur[len];
}
Clang 9
define dso_local i32 @comp(i32, i32, i8* nocapture readonly) local_unnamed_addr
#0 {
%4 = sext i32 %1 to i64
%5 = getelementptr inbounds i8, i8* %2, i64 %4
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %11, %3
%8 = phi i64 [ %9, %11 ], [ 0, %3 ]
%9 = add nuw nsw i64 %8, 1
%10 = icmp eq i64 %9, %6
br i1 %10, label %17, label %11
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %5, i64 %9
%13 = load i8, i8* %12, align 1, !tbaa !2
%14 = getelementptr inbounds i8, i8* %2, i64 %9
%15 = load i8, i8* %14, align 1, !tbaa !2
%16 = icmp eq i8 %13, %15
br i1 %16, label %7, label %17
17: ; preds = %11, %7
%18 = and i64 %9, 4294967295
%19 = getelementptr inbounds i8, i8* %2, i64 %18
%20 = load i8, i8* %19, align 1, !tbaa !2
%21 = zext i8 %20 to i32
ret i32 %21
}
Clang 10
define dso_local i32 @comp(i32 %0, i32 %1, i8* nocapture readonly %2)
local_unnamed_addr #0 {
%4 = sext i32 %1 to i64
%5 = getelementptr inbounds i8, i8* %2, i64 %4
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %11, %3
%8 = phi i64 [ %9, %11 ], [ 0, %3 ]
%9 = add nuw nsw i64 %8, 1
%10 = icmp eq i64 %9, %6
br i1 %10, label %19, label %11
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %5, i64 %9
%13 = load i8, i8* %12, align 1, !tbaa !2
%14 = getelementptr inbounds i8, i8* %2, i64 %9
%15 = load i8, i8* %14, align 1, !tbaa !2
%16 = icmp eq i8 %13, %15
br i1 %16, label %7, label %17
17: ; preds = %11
%18 = and i64 %9, 4294967295
br label %19
19: ; preds = %7, %17
%20 = phi i64 [ %18, %17 ], [ %6, %7 ]
%21 = getelementptr inbounds i8, i8* %2, i64 %20
%22 = load i8, i8* %21, align 1, !tbaa !2
%23 = zext i8 %22 to i32
ret i32 %23
}
See new phi "%20 = phi i64 [ %18, %17 ], [ %6, %7 ]".
Codegen is worse a bit:
Clang 9
comp: # @comp
movsxd rax, esi
mov r8d, edi
add rax, rdx
mov edi, 1
.LBB0_1: # =>This Inner Loop Header: Depth=1
mov rsi, rdi
cmp r8, rdi
je .LBB0_3
movzx ecx, byte ptr [rax + rsi]
lea rdi, [rsi + 1]
cmp cl, byte ptr [rdx + rsi]
je .LBB0_1
.LBB0_3:
mov eax, esi
movzx eax, byte ptr [rdx + rax]
ret
Clang 10
comp: # @comp
movsxd rax, esi
mov r8d, edi
lea r9, [rdx + 1]
lea rdi, [rdx + rax]
add rdi, 1
lea rax, [r8 - 1]
xor esi, esi
.LBB0_1: # =>This Inner Loop Header: Depth=1
cmp rax, rsi
je .LBB0_4
movzx ecx, byte ptr [rdi + rsi]
cmp cl, byte ptr [r9 + rsi]
lea rsi, [rsi + 1]
je .LBB0_1
mov r8d, esi
.LBB0_4:
movzx eax, byte ptr [rdx + r8]
ret
<a href="https://godbolt.org/z/2zMDVf">https://godbolt.org/z/2zMDVf</a></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>