[LLVMbugs] [Bug 23673] New: more optimize oppotunity

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed May 27 00:40:13 PDT 2015


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

            Bug ID: 23673
           Summary: more optimize oppotunity
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ishiura-compiler at ml.kwansei.ac.jp
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

We compiled a program (A.c) by LLVM/Clang-3.7.0 and GCC-6.0.0 with -O3 option.
GCC performed better optimization on this code, where the code for the
expression for t (which always evaluates to 1) is eliminated.

(A.c)
int x = -1;

int main (void)
{
    int t = ((((0!=(1*(x+1)))<<0U)/-2344)|1);

    if (t == 1) ;
    else __builtin_abort();

    return 0;
}


+------------------------------------------------------------+--------------------------------------------------------+
|                 gcc.s (gcc A.c -O3 -S)                     |             
clang.s (clang A.c -O3 -S)                |
+------------------------------------------------------------+--------------------------------------------------------+
|main:                                                       |                 
                                      *
|.LFB11:                                                     |main:            
                      # @main         *
|        .cfi_startproc                                      |       
.cfi_startproc                                  |
|                                                            |# BB#0:          
                      # %entry        *
|                                                            |        pushq  
%rax                                    *
|                                                            |.Ltmp0:          
                                      *
|                                                            |       
.cfi_def_cfa_offset 16                          *
|                                                            |        cmpl   
$-1, x247(%rip)                         *
|                                                            |        setne  
%al                                     *
|                                                            |        movzbl 
%al, %eax                               *
|                                                            |        negl   
%eax                                    *
|                                                            |        movl   
%eax, %ecx                              *
|                                                            |        shrl   
$31, %ecx                               *
|                                                            |        sarl   
$11, %eax                               *
|                                                            |        addl   
%ecx, %eax                              *
|                                                            |        orl    
$1, %eax                                *
|                                                            |        cmpl   
$1, %eax                                *
|                                                            |        jne    
.LBB0_2                                 *
|                                                            |# BB#1:          
                      # %if.end       *
|        xorl    %eax, %eax                                  |        xorl   
%eax, %eax                              |
|        ret                                                 |        popq   
%rdx                                    *
|                                                            |        retq     
                                      *
|                                                            |.LBB0_2:         
                      # %if.else      *
|                                                            |        callq  
abort                                   *
|                                                            |.Ltmp1:          
                                      *
|                                                            |        .size  
main, .Ltmp1-main                       *
|        .cfi_endproc                                        |       
.cfi_endproc                                    |
|.LFE11:                                                     |                 
                                      *
|        .size   main, .-main                                |        .type  
x247, at object            # @x247         *
|        .section        .text.unlikely                      |                 
                                      |
|.LCOLDE0:                                                   |                 
                                      |
|        .section        .text.startup                       |                 
                                      |
|.LHOTE0:                                                    |                 
                                      |
|        .globl  x247                                        |                 
                                      |
|        .data                                               |        .data    
                                      |
|        .align 4                                            |        .globl 
x247                                    *
|        .type   x247, @object                               |        .align  4
                                      *
|        .size   x247, 4                                     |                 
                                      |
|x247:                                                       |x247:            
                                      |
|        .long   -1                                          |        .long  
4294967295              # 0xffffffff    *
|                                                            |        .size  
x247, 4                                 *
+------------------------------------------------------------+--------------------------------------------------------+


clang version 3.7.0 (trunk 237801)
Target: x86_64-unknown-linux-gnu
Thread model: posix

gcc (GCC) 6.0.0 20150416 (experimental)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

-- 
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/20150527/2642da17/attachment.html>


More information about the llvm-bugs mailing list