Bug 97967 - Missed optimization opportunity for VRP
Summary: Missed optimization opportunity for VRP
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 10.2.0
: P3 normal
Target Milestone: 11.0
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks: VRP
  Show dependency treegraph
 
Reported: 2020-11-24 12:32 UTC by Ishiura Lab Compiler Team
Modified: 2021-07-28 20:54 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ishiura Lab Compiler Team 2020-11-24 12:32:13 UTC
We have another VRP related test case for GCC-10.2.0. 

We expect A1.c and A2.c should compile to the same codes, but they did
not.

+---------------------------------+---------------------------------+
|                A1.c             |              A2.c               |
+---------------------------------+---------------------------------+
|int main (void)                  |int main (void)                  |
|{                                |{                                |
|  volatile int a = 1;            |  volatile int a = 1;            |
|                                 |                                 |
|  int b = a%2;                   |  a;                             |
|  int t = 200<(short)(-50*b);    |  int t = 0;                     |
|                                 |                                 |
|  if (t != 0) __builtin_abort(); |  if (t != 0) __builtin_abort(); |
|                                 |                                 |
|  return 0;                      |  return 0;                      |
|}                                |}                                |
+---------------------------------+---------------------------------+

+-------------------------------+------------------------------+
| A1.s (gcc-10.2.0 A1.c -O3 -S) | A2.s (gcc-10.2.0 A2.c -O3 -S)|
+-------------------------------+------------------------------+
|main:                          |main:                         |
|.LFB0:                         |.LFB0:                        |
|   .cfi_startproc              |   .cfi_startproc             |
|   subq    $24, %rsp           |   movl    $1, -4(%rsp)       |
|   .cfi_def_cfa_offset 32      |   movl    -4(%rsp), %eax     |
|   movl    $1, 12(%rsp)        |                              |
|   movl    12(%rsp), %eax      |                              |
|   movl    %eax, %edx          |                              |
|   shrl    $31, %edx           |                              |
|   addl    %edx, %eax          |                              |
|   andl    $1, %eax            |                              |
|   subl    %edx, %eax          |                              |
|   imull   $-50, %eax, %eax    |                              |
|   cmpw    $200, %ax           |                              |
|   jg      .L3                 |                              |
|   xorl    %eax, %eax          |   xorl    %eax, %eax         |
|   addq    $24, %rsp           |                              |
|   .cfi_def_cfa_offset 8       |                              |
|   ret                         |   ret                        |
|   .cfi_endproc                |   .cfi_endproc               |
|   .section   .text.unlikely   |                              |
|   .cfi_startproc              |                              |
|   .type   main.cold, @function|                              |
|main.cold:                     |                              |
|.LFSB0:                        |                              |
|.L3:                           |                              |
|    .cfi_def_cfa_offset 32     |                              |
|    call    abort              |                              |
|    .cfi_endproc               |                              |
|.LFE0:                         |.LFE0:                        |
|    .section  text.startup     |                              |
|    .size   main, .-main       |   .size   main, .-main       |
|    .section  .text.unlikely   |                              |
|    .size   main.cold, .-mai...|                              |
|.LCOLDE0:                      |                              |
|    .section  .text.startup    |                              |
|.LHOTE0:                       |                              |
|    .ident  "GCC: (GNU) 10.2.0"|   .ident  "GCC: (GNU) 10.2.0"|
|    .section  .note.GNU-stac...|   .section  .note.GNU-stac...|
+--------------------------------------------------------------+

$ gcc -v
using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper
target: x86_64-pc-linux-gnu
configure woth: ../configure --enable-languages=c,c++ --prefix=/usr/local
--disable-bootstrap --disable-multilib
thred model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (GCC)
Comment 1 Andrew Pinski 2021-07-28 20:54:29 UTC
Fixed in GCC 11 already.