This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/83544] New: Missed optimization opportunity for constant folding


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

            Bug ID: 83544
           Summary: Missed optimization opportunity for constant folding
           Product: gcc
           Version: 8.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 two programs (A1.c, A2.c) by GCC-8.0.0 with -O3 option.
We expect the resulting assembly codes would be the same, or at least
A1.c would result in simpler code.  However, the result was the opposite.


+---------------------------------+---------------------------------+
|                A1.c             |              A2.c               |
+---------------------------------+---------------------------------+
|int main (void)                  |int main (void)                  |
|{                                |{                                |
|  volatile int x = 1;            |  volatile int x = 1;            |
|                                 |  int a = 1;                     |
|                                 |                                 |
|  int t = 1 / ( 0 < ( 1/x ) );   |  int t = a / ( 0 < ( 1/x ) );   |
|  if (t != 1) __builtin_abort(); |  if (t != 1) __builtin_abort(); |
|  return 0;                      |  return 0;                      |
|}                                |}                                |
+---------------------------------+---------------------------------+

+----------------------------+----------------------------+
|A1.s (gcc-8.0.0 A1.c -O3 -S)|A2.s (gcc-8.0.0 A2.c -O3 -S)|
+----------------------------+----------------------------+
|main:                       |main:                       |
|.LFB0:                      |.LFB0:                      |
|  .cfi_startproc            |  .cfi_startproc            |
|  movl  $1, %eax            |                            |
|  movl  $1, -4(%rsp)        |  movl  $1, -4(%rsp)        |
|  movl  -4(%rsp), %ecx      |  movl  -4(%rsp), %eax      |
|  cltd                      |                            |
|  idivl %ecx                |                            |
|  cmpl  $1, %eax            |                            |
|  je    .L2                 |                            |
|  ud2                       |                            |
|  .p2align 4,,10            |                            |
|  .p2align 3                |                            |
|.L2:                        |                            |
|  xorl  %eax, %eax          |  xorl  %eax, %eax          |
|  ret                       |  ret                       |
|  .cfi_endproc              |  .cfi_endproc              |
|.LFE0:                      |.LFE0:                      |
|  .size  main, .-main       |   .size  main, .-main      |
+----------------------------+----------------------------+

gcc-8.0 (GCC) 8.0.0 20171215 (experimental)
Copyright (C) 2017 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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]