public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/66299] New: more optimize oppotunity
@ 2015-05-27  7:34 ishiura-compiler at ml dot kwansei.ac.jp
  2015-05-27  7:47 ` [Bug tree-optimization/66299] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: ishiura-compiler at ml dot kwansei.ac.jp @ 2015-05-27  7:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66299

            Bug ID: 66299
           Summary: more optimize oppotunity
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ishiura-compiler at ml dot kwansei.ac.jp
  Target Milestone: ---

We compiled a program (A.c) by GCC-6.0.0 and LLVM/Clang-3.7.0 with -O3 option.
LLVM/Clang worked better on this test case, where the shift operation is
optimized out. 

(A.c)
int main (void)
{
        volatile signed int x = 1;
        unsigned int t = ((unsigned int)1U<<x);

        if (t == 2U) ;
        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                                |
|        subq  $24, %rsp                                 |# BB#0:              
                  # %entry      *
|        .cfi_def_cfa_offset 32                          |        pushq   %rax 
                                *
|        movl  $1, %eax                                  |.Ltmp0:              
                                *
|        movl    $1, 12(%rsp)                            |       
.cfi_def_cfa_offset 16                        *
|        movl    12(%rsp), %ecx                          |        movl    $1,
4(%rsp)                           *
|        sall    %cl, %eax                               |        movl   
4(%rsp), %eax                         *
|        cmpl    $2, %eax                                |        cmpl    $1,
%eax                              *
|        jne     .L5                                     |        jne    
.LBB0_2                               *
|                                                        |# BB#1:              
                  # %if.end     *
|        xorl    %eax, %eax                              |        xorl    %eax,
%eax                            |
|        addq    $24, %rsp                               |        popq    %rdx 
                                *
|        .cfi_remember_state                             |        retq         
                                *
|        .cfi_def_cfa_offset 8                           |.LBB0_2:             
                  # %if.else    *
|        ret                                             |        callq   abort
                                *
|.L5:                                                    |.Ltmp1:              
                                *
|        .cfi_restore_state                              |        .size   main,
.Ltmp1-main                     *
|        call    abort                                   |                     
                                |
|        .cfi_endproc                                    |        .cfi_endproc 
                                |
|.LFE11:                                                 |                     
                                *
|        .size\tmain, .-main                             |                     
                                *
|        .section        .text.unlikely                  |                     
                                *
|.LCOLDE0:                                               |                     
                                *
|        .section        .text.startup                   |                     
                                |
|.LHOTE0:                                                |                     
                                |
+--------------------------------------------------------+------------------------------------------------------+


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.

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/66299] more optimize oppotunity
  2015-05-27  7:34 [Bug tree-optimization/66299] New: more optimize oppotunity ishiura-compiler at ml dot kwansei.ac.jp
@ 2015-05-27  7:47 ` pinskia at gcc dot gnu.org
  2015-05-27  7:59 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2015-05-27  7:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66299

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
1<<x == 2 can be transformed into x == 1 and that seems like it is not being
done.

Related to bug 15350.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/66299] more optimize oppotunity
  2015-05-27  7:34 [Bug tree-optimization/66299] New: more optimize oppotunity ishiura-compiler at ml dot kwansei.ac.jp
  2015-05-27  7:47 ` [Bug tree-optimization/66299] " pinskia at gcc dot gnu.org
@ 2015-05-27  7:59 ` jakub at gcc dot gnu.org
  2015-05-27  8:29 ` mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-05-27  7:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66299

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I'd think using a volatile var in the optimization test is highly undesirable,
that can mean stopping optimizations differently between different compilers.
But, the same thing can be reproduced with:
void
foo (signed int x)
{
  unsigned int t = ((unsigned int) 1U << x);

  if (t != 2U)
    __builtin_abort ();
}

Perhaps we should have a match.pd simplification of (const1 << var) {==,!=}
const2, perhaps something even for {<,<=,>,>=} if they could be simplified to a
simple comparison of var and const3; supposedly guarded with single use of the
shift.  What about >> ?  Other arithmetics single use operations (e.g. 2U * var
== 16)?  For addition of a constant apparently forwprop1 already optimizes
that.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/66299] more optimize oppotunity
  2015-05-27  7:34 [Bug tree-optimization/66299] New: more optimize oppotunity ishiura-compiler at ml dot kwansei.ac.jp
  2015-05-27  7:47 ` [Bug tree-optimization/66299] " pinskia at gcc dot gnu.org
  2015-05-27  7:59 ` jakub at gcc dot gnu.org
@ 2015-05-27  8:29 ` mpolacek at gcc dot gnu.org
  2015-05-28 10:27 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-05-27  8:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66299

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-05-27
                 CC|                            |mpolacek at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.  I'm experimenting with this.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/66299] more optimize oppotunity
  2015-05-27  7:34 [Bug tree-optimization/66299] New: more optimize oppotunity ishiura-compiler at ml dot kwansei.ac.jp
                   ` (2 preceding siblings ...)
  2015-05-27  8:29 ` mpolacek at gcc dot gnu.org
@ 2015-05-28 10:27 ` mpolacek at gcc dot gnu.org
  2015-05-28 10:27 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-05-28 10:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66299

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
   Target Milestone|---                         |6.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/66299] more optimize oppotunity
  2015-05-27  7:34 [Bug tree-optimization/66299] New: more optimize oppotunity ishiura-compiler at ml dot kwansei.ac.jp
                   ` (3 preceding siblings ...)
  2015-05-28 10:27 ` mpolacek at gcc dot gnu.org
@ 2015-05-28 10:27 ` mpolacek at gcc dot gnu.org
  2015-06-09 14:24 ` [Bug tree-optimization/66299] more optimize opportunity mpolacek at gcc dot gnu.org
  2015-06-09 14:27 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-05-28 10:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66299

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I have some patch now, we'll see.

There are some more things to optimize, e.g. "if ((1 << x) == 3)" can't ever be
true, yet we fail to optimize it to "if (0)".


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/66299] more optimize opportunity
  2015-05-27  7:34 [Bug tree-optimization/66299] New: more optimize oppotunity ishiura-compiler at ml dot kwansei.ac.jp
                   ` (4 preceding siblings ...)
  2015-05-28 10:27 ` mpolacek at gcc dot gnu.org
@ 2015-06-09 14:24 ` mpolacek at gcc dot gnu.org
  2015-06-09 14:27 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-06-09 14:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66299

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Tue Jun  9 14:24:04 2015
New Revision: 224283

URL: https://gcc.gnu.org/viewcvs?rev=224283&root=gcc&view=rev
Log:
        PR tree-optimization/66299
        * match.pd ((CST1 << A) == CST2 -> A == ctz (CST2) - ctz (CST1)
        ((CST1 << A) != CST2 -> A != ctz (CST2) - ctz (CST1)): New
        patterns.

        * gcc.dg/pr66299-1.c: New test.
        * gcc.dg/pr66299-2.c: New test.
        * gcc.dg/pr66299-3.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr66299-1.c
    trunk/gcc/testsuite/gcc.dg/pr66299-2.c
    trunk/gcc/testsuite/gcc.dg/pr66299-3.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/match.pd
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/66299] more optimize opportunity
  2015-05-27  7:34 [Bug tree-optimization/66299] New: more optimize oppotunity ishiura-compiler at ml dot kwansei.ac.jp
                   ` (5 preceding siblings ...)
  2015-06-09 14:24 ` [Bug tree-optimization/66299] more optimize opportunity mpolacek at gcc dot gnu.org
@ 2015-06-09 14:27 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-06-09 14:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66299

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
This one should be done.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-06-09 14:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-27  7:34 [Bug tree-optimization/66299] New: more optimize oppotunity ishiura-compiler at ml dot kwansei.ac.jp
2015-05-27  7:47 ` [Bug tree-optimization/66299] " pinskia at gcc dot gnu.org
2015-05-27  7:59 ` jakub at gcc dot gnu.org
2015-05-27  8:29 ` mpolacek at gcc dot gnu.org
2015-05-28 10:27 ` mpolacek at gcc dot gnu.org
2015-05-28 10:27 ` mpolacek at gcc dot gnu.org
2015-06-09 14:24 ` [Bug tree-optimization/66299] more optimize opportunity mpolacek at gcc dot gnu.org
2015-06-09 14:27 ` mpolacek at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).