[llvm-bugs] [Bug 23827] bad generated code for conditionals connected by (&)

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Sep 7 13:39:32 PDT 2015


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

Sanjay Patel <spatel+llvm at rotateright.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |INVALID

--- Comment #19 from Sanjay Patel <spatel+llvm at rotateright.com> ---
As of:
http://reviews.llvm.org/rL246699

...we can use "__builtin_unpredictable()" to get the desired single branch
codegen from either of the ampamp() or amp() test cases:

void ampamp(int x, int y) {
  if (__builtin_unpredictable(x < 3 && y > 10) ) 
    printf("%d%d", x, y);
}

void amp(int x, int y) {
  if (__builtin_unpredictable((x < 3) & (y > 10)) ) 
    printf("%d%d", x, y);
}

$ ./clang -O2 -fomit-frame-pointer -S -o - 23827.c 
...
## BB#0:                                ## %entry
    movl    %esi, %r8d
    movl    %edi, %edx
    cmpl    $3, %edx
    setl    %al
    cmpl    $10, %r8d
    setg    %cl
    andb    %al, %cl
    movzbl    %cl, %eax
    cmpl    $1, %eax
    jne    LBB0_1
## BB#2:                                ## %if.then
    leaq    L_.str(%rip), %rdi
    xorl    %eax, %eax
    movl    %edx, %esi
    movl    %r8d, %edx
    jmp    _printf                 ## TAILCALL
LBB0_1:                                 ## %if.end
    retq

-------------------------------------------------------------------------

I'm resolving this as 'invalid' because the request to change codegen in the
original test is not something we can do. Please reopen if you still disagree.
If there are problems with the less branchy codegen after using
'unpredictable', please file a new bug.

I filed bug 24743 to track the problem mentioned in comment 1 / comment 7.

-- 
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/20150907/7acf585b/attachment.html>


More information about the llvm-bugs mailing list