[llvm-bugs] [Bug 35557] New: suboptimal code for range check

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 7 03:33:21 PST 2017


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

            Bug ID: 35557
           Summary: suboptimal code for range check
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: dvyukov at google.com
                CC: llvm-bugs at lists.llvm.org

clang version 6.0.0 (trunk 320027)

int foobar(int x) {
        return x > 16 && x < 32;
}

-O3 produces:

  4004d0:       31 c0                   xor    %eax,%eax
  4004d2:       83 ff 11                cmp    $0x11,%edi
  4004d5:       7c 08                   jl     4004df <foobar+0xf>
  4004d7:       31 c0                   xor    %eax,%eax
  4004d9:       83 ff 20                cmp    $0x20,%edi
  4004dc:       0f 9c c0                setl   %al
  4004df:       c3                      retq   

a more optimal code would be:

  400480:       83 ef 11                sub    $0x11,%edi
  400483:       31 c0                   xor    %eax,%eax
  400485:       83 ff 0e                cmp    $0xe,%edi
  400488:       0f 96 c0                setbe  %al
  40048b:       c3                      retq   

Besides the sub trick, it's unclear why llvm generates a duplicate "xor   
%eax,%eax". That may be a second bug.

-- 
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/20171207/31323493/attachment-0001.html>


More information about the llvm-bugs mailing list