[llvm-bugs] [Bug 35399] New: lzcnt causes erroneous code generation (x86_64)
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Nov 23 07:45:56 PST 2017
https://bugs.llvm.org/show_bug.cgi?id=35399
Bug ID: 35399
Summary: lzcnt causes erroneous code generation (x86_64)
Product: clang
Version: 5.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: michel.bernert at gmail.com
CC: llvm-bugs at lists.llvm.org
Created attachment 19461
--> https://bugs.llvm.org/attachment.cgi?id=19461&action=edit
Code compiled with : clang++ lzcnt.cpp -Wall -pedantic -O2 -mlzcnt -S
The use of lzcnt has an unexpected behavior, when using the -mlzcnt flag with
optimizations.
Compiling :
uint64_t test64_2(uint64_t x, bool& b1, bool& b2)
{
uint64_t a = (x == 0 ? 64 : __builtin_clzll(x));
b1 = (a != 64);
b2 = !b1;
return a;
}
Generates :
test64_2(unsigned long, bool&, bool&): # @test64_2(unsigned long, bool&, bool&)
lzcntq %rdi, %rax
setae (%rsi)
setae (%rdx)
retq
Which sets the two bools to the same value, even though 'b2 = !b1;' and I can't
see any undefined behavior.
This concerns all 16, 32 and 64 bits versions of lzcnt. Omitting -mlzcnt
produces the expected behavior for __builtin_clz versions, using bsr.
--
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/20171123/a75b01c4/attachment-0001.html>
More information about the llvm-bugs
mailing list