[llvm-bugs] [Bug 25429] New: Optimizing loop with sizeof("literal")

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Nov 6 01:58:08 PST 2015


https://llvm.org/bugs/show_bug.cgi?id=25429

            Bug ID: 25429
           Summary: Optimizing loop with sizeof("literal")
           Product: clang
           Version: 3.6
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hugo.guiroux at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 15233
  --> https://llvm.org/bugs/attachment.cgi?id=15233&action=edit
minimal working example

Compiling with clang++ the minimal working example, I get the following result:

clang++ -O3 -Wall -o sizeof_vs_strlen sizeof_vs_strlen.cpp
./sizeof_vs_strlen
Strlen 36 ret=4
Sizeof 62092396 ret=5

With g++:

g++ -O3 -Wall -o sizeof_vs_strlen sizeof_vs_strlen.cpp 
./sizeof_vs_strlen
Strlen 30 ret=4
Sizeof 30 ret=5

The assembly generated by clang++ for the loop with sizeof:
rdtsc  
mov    %edx,%r14d
shl    $0x20,%r14
mov    $0x3b9aca01,%ecx
xchg   %ax,%ax
add    $0xffffffed,%ecx // 0x400ad0
jne    0x400ad0 <main+192>
mov    %eax,%eax
or     %rax,%r14
rdtsc  

And the one by g++:
rdtsc  
mov    %edx,%esi
mov    %eax,%ecx
rdtsc
I don't understand why clang++ do the {add, jne} loop, it seems to be a bug

For information:
g++ (GCC) 5.1.0
clang version 3.6.2 (tags/RELEASE_362/final) (also tested with 3.7.0, same
bug).

The bug was originally describe on stackoverflow
(http://stackoverflow.com/questions/33562365/clang-sizeofliteral-optimization).

-- 
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/20151106/d66d13d5/attachment.html>


More information about the llvm-bugs mailing list