<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 - weird codegen: xor eax, eax; test al, al; jne"
href="https://bugs.llvm.org/show_bug.cgi?id=49594">49594</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>weird codegen: xor eax, eax; test al, al; jne
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>11.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</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>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>redbeard0531@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre><a href="https://godbolt.org/z/nsGj55">https://godbolt.org/z/nsGj55</a>
I noticed this while trying to minrepro another codegen issue, so the input
code is a bit odd. I can't think of any reason to ever generate this
instruction sequence, since the value of al is well known after zeroing it. It
also seems odd that it is doing anything with eax/al at all here, given that it
is clobbering it a few instructions later.
#include <cassert>
#include <cstdint>
template<int V> int f(int = V);
int test1(const char* p) {
switch(auto byte = uint8_t(*p)) {
case 0: return f<0>();
case 1: return f<1>();
case 2: return f<2>();
case 3 ... 10: return f<3>(byte);
case 11 ... 100: return f<4>(byte);
case 111 ... 120: return f<5>(byte);
case 121 ... 130: return f<6>(byte);
case 131 ... 140: return f<7>(byte);
case 141 ... 150: return f<8>(byte);
case 151 ... 160: return f<9>(byte);
case 161 ... 170: return f<10>(byte);
case 171 ... 180: return f<5>(byte);
case 181 ... 190: return f<5>(byte);
case 191 ... 200: return f<5>(byte);
default: assert(false);
}
}
test1(char const*): # @test1(char const*)
push rax
movzx edi, byte ptr [rdi]
xor eax, eax # <-- zeros eax, including al
test al, al # <-- why ?!?!?!?
jne .LBB0_6 # <-- never taken
lea eax, [rdi - 128]
movzx eax, al
jmp qword ptr [8*rax + .LJTI0_0]
...
(snipping rest since the interesting bit is above)</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>