public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/61839] New: More optimize opportunity
@ 2014-07-18  7:52 ishiura-compiler at ml dot kwansei.ac.jp
  2014-07-23 13:00 ` [Bug tree-optimization/61839] More optimize opportunity for VRP rguenth at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: ishiura-compiler at ml dot kwansei.ac.jp @ 2014-07-18  7:52 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 61839
           Summary: More optimize opportunity
           Product: gcc
           Version: 4.8.4
            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

We have two equvalent programs (A) and (B), which only differ by one line
(marked by "// <---HERE"), where (B) simply folds a+972195718 to 972195717,
for local variable a=-1.

Resulting code by "x86_64-unknown-linux-gnu-gcc-4.8.4 -Os -S" is
different; the code for (A) is less optimized than that of (B).

(A)
int main (void)
{
    int a = -1;
    volatile unsigned b = 1U;
    int c = 1;

    c = (a + 972195718) >> (1LU <= b);  // <---HERE

    if (c == 486097858);
    else __builtin_abort();
    return 0;
}

(B)
int main (void)
{
    int a = -1;
    volatile unsigned b = 1U;
    int c = 1;

    c = 972195717 >> (1LU <= b);        // <---HERE

    if (c == 486097858);
    else __builtin_abort();
    return 0;
}

+-----------------------------+-----------------------------+
|(A)                          |(B)                          |
+-----------------------------+-----------------------------+
|main:                        |main:                        |
|.LFB0:                       |.LFB0:                       |
|    .cfi_startproc           |    .cfi_startproc           |
|    subq    $24, %rsp        |    subq    $24, %rsp        |
|    .cfi_def_cfa_offset 32   |    .cfi_def_cfa_offset 32   |
|    movl    $1, 12(%rsp)     |    movl    $1, 12(%rsp)     |
|    movl    12(%rsp), %eax   |    movl    12(%rsp), %eax   |
|    testl   %eax, %eax       |    testl   %eax, %eax       |
|    movl    $972195717, %eax |                             |
|    setne   %cl              |                             |
|    sarl    %cl, %eax        |                             |
|    cmpl    $486097858, %eax |                             |
|    jne     .L5              |    jne     .L2              |
|    xorl    %eax, %eax       |    call    abort            |
|    addq    $24, %rsp        |.L2:                         |
|    .cfi_remember_state      |    xorl    %eax, %eax       |
|    .cfi_def_cfa_offset 8    |    addq    $24, %rsp        |
|    ret                      |    .cfi_def_cfa_offset 8    |
|.L5:                         |    ret                      |
|    .cfi_restore_state       |    .cfi_endproc             |
|    call    abort            |                             |
|    .cfi_endproc             |                             |
+-----------------------------+-----------------------------+

$ x86_64-unknown-linux-gnu-gcc-4.8.4 -v
Using built-in specs.         
COLLECT_GCC=x86_64-unknown-linux-gnu-gcc-4.8.4
COLLECT_LTO_WRAPPER=/usr/local/x86_64-tools/gcc-4.8.4/libexec/gcc/x86_64-unknown-linux-gnu/4.8.4/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /home/hassy/gcc/configure
--prefix=/usr/local/x86_64-tools/gcc-4.8.4/ --with-gmp=/usr/local/gmp-5.1.1/
--with-mpfr=/usr/local/mpfr-3.1.2/ --with-mpc=/usr/local/mpc-1.0.1/
--disable-multilib --disable-nls --enable-languages=c
Thread model: posix
gcc version 4.8.4 20140622 (prerelease) (GCC)


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

* [Bug tree-optimization/61839] More optimize opportunity for VRP
  2014-07-18  7:52 [Bug tree-optimization/61839] New: More optimize opportunity ishiura-compiler at ml dot kwansei.ac.jp
@ 2014-07-23 13:00 ` rguenth at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-07-23 13:00 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-07-23
            Summary|More optimize opportunity   |More optimize opportunity
                   |                            |for VRP
     Ever confirmed|0                           |1
      Known to fail|                            |4.10.0

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  This is straight-line (A) code vs. if-code (B) that makes the
difference, introduced by fold already:

--- a/t.c.003t.original 2014-07-23 14:48:48.984335370 +0200
+++ b/t.c.003t.original 2014-07-23 14:46:19.224345681 +0200
@@ -11,7 +11,7 @@
     int a = -1;
     volatile unsigned int b = 1;
     int c = 1;
-  c = b != 0 ? 486097858 : 972195717;
+  c = a + 972195718 >> (b != 0);
   if (c == 486097858)
     {
       (void) 0;

in the bad case we have

  <bb 2>:
  b ={v} 1;
  b.0_3 ={v} b;
  _4 = b.0_3 != 0;
  _5 = (int) _4;
  c_6 = 972195717 >> _5;
  if (c_6 == 486097858)
...

until the very end, not transforming c_6.  Note that VRP could do the
missing transform as it knows that _5 is [0, 1] (it has to jump through
the shift - the value-range for the shift itself is too broad).

If written this kind of transform should be applied more generally, not
just for shifts.  It basically wants to ask whether a conditional test
can be carried out against another SSA name (and another constant) if
an intermediate compute can be omitted in that case.


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

end of thread, other threads:[~2014-07-23 13:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-18  7:52 [Bug tree-optimization/61839] New: More optimize opportunity ishiura-compiler at ml dot kwansei.ac.jp
2014-07-23 13:00 ` [Bug tree-optimization/61839] More optimize opportunity for VRP rguenth 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).