[llvm-bugs] [Bug 49594] New: weird codegen: xor eax, eax; test al, al; jne
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Mar 15 06:45:44 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=49594
Bug ID: 49594
Summary: weird codegen: xor eax, eax; test al, al; jne
Product: clang
Version: 11.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: redbeard0531 at gmail.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
neeilans at live.com, richard-llvm at metafoo.co.uk
https://godbolt.org/z/nsGj55
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)
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210315/8da25a98/attachment.html>
More information about the llvm-bugs
mailing list