public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/67769] New: VRP pass does wrong optimization
@ 2015-09-29 16:24 bmei at broadcom dot com
  2015-09-29 17:51 ` [Bug tree-optimization/67769] [6 Regression] " mpolacek at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: bmei at broadcom dot com @ 2015-09-29 16:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 67769
           Summary: VRP pass does wrong optimization
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bmei at broadcom dot com
  Target Milestone: ---

#include <stdlib.h>

static int
clamp (int x, int lo, int hi)
{
    return (x < lo) ? lo : ((x > hi) ? hi : x);
}


__attribute__((noinline))
short
foo (int N)
{
    short value =
        clamp (N, 0, 16);


    return value;
}

int main ()
{
  if (foo (-5) != 0)
    abort();
  return 0;
}


Compile this simple code and run. 

bash:bmei:xl-cam-21:34271> ~/scratch/install-x86/bin/gcc tst.c -O2
bash:bmei:xl-cam-21:34272> ./a.out
Aborted
bash:bmei:xl-cam-21:34273> ~/scratch/install-x86/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/home/bmei/scratch/install-x86/bin/gcc
COLLECT_LTO_WRAPPER=/projects/firepath_tools1_scratch/bmei/install-x86/libexec/gcc/x86_64-unknown-linux-gnu/6.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../trunk/configure
--prefix=/projects/firepath_tools1_scratch/bmei/install-x86 --disable-nls
--with-mpfr=/projects/firepath_tools/work/bmei/packages/mpfr/2.4.1/x86-64
--with-gmp=/projects/firepath_tools/work/bmei/packages/gmp/4.3.0/x86-64
--with-mpc=/projects/firepath_tools/work/bmei/packages/mpc/0.8.1/x86-64
--disable-libsanitizer --disable-target-libsanitizer CFLAGS='-O0 -g3'
CXXFLAGS='-O0 -g3' --enable-languages=c --no-recursion --disable-bootstrap :
(reconfigured) ../trunk/configure
--prefix=/projects/firepath_tools1_scratch/bmei/install-x86 --disable-nls
--with-mpfr=/projects/firepath_tools/work/bmei/packages/mpfr/2.4.1/x86-64
--with-gmp=/projects/firepath_tools/work/bmei/packages/gmp/4.3.0/x86-64
--with-mpc=/projects/firepath_tools/work/bmei/packages/mpc/0.8.1/x86-64
--disable-libsanitizer --disable-target-libsanitizer CFLAGS='-O0 -g3'
CXXFLAGS='-O0 -g3' --disable-bootstrap --enable-languages=c,lto --no-create
--no-recursion
Thread model: posix
gcc version 6.0.0 20150929 (experimental) [trunk revision 143368] (GCC)


I looked into the tree dump, it seems that VRP2 pass. The second MAX_EXPR is
folded.

Folding statement: iftmp.0_3 = MIN_EXPR <N_2(D), 16>;
Not folded
Folding statement: iftmp.0_6 = MAX_EXPR <iftmp.0_3, 0>;
Folded into: iftmp.0_6 = iftmp.0_3;

Folding statement: value_4 = (short int) iftmp.0_6;
Not folded
Folding statement: return value_4;
Not folded
foo (int N)
[ noinline ]
{
  short int value;
  int iftmp.0_3;
  int iftmp.0_6;

  <bb 2>:
  iftmp.0_3 = MIN_EXPR <N_2(D), 16>;
  iftmp.0_6 = iftmp.0_3;
  value_4 = (short int) iftmp.0_6;
  return value_4;

}


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

* [Bug tree-optimization/67769] [6 Regression] VRP pass does wrong optimization
  2015-09-29 16:24 [Bug c/67769] New: VRP pass does wrong optimization bmei at broadcom dot com
@ 2015-09-29 17:51 ` mpolacek at gcc dot gnu.org
  2015-09-29 17:53 ` glisse at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-09-29 17:51 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-09-29
   Target Milestone|---                         |6.0
            Summary|VRP pass does wrong         |[6 Regression] VRP pass
                   |optimization                |does wrong optimization
     Ever confirmed|0                           |1
           Severity|major                       |normal

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Started with r226809.


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

* [Bug tree-optimization/67769] [6 Regression] VRP pass does wrong optimization
  2015-09-29 16:24 [Bug c/67769] New: VRP pass does wrong optimization bmei at broadcom dot com
  2015-09-29 17:51 ` [Bug tree-optimization/67769] [6 Regression] " mpolacek at gcc dot gnu.org
@ 2015-09-29 17:53 ` glisse at gcc dot gnu.org
  2015-09-29 17:59 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: glisse at gcc dot gnu.org @ 2015-09-29 17:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Marc Glisse <glisse at gcc dot gnu.org> ---
Probably phiopt not clearing the flow sensitive info.


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

* [Bug tree-optimization/67769] [6 Regression] VRP pass does wrong optimization
  2015-09-29 16:24 [Bug c/67769] New: VRP pass does wrong optimization bmei at broadcom dot com
  2015-09-29 17:51 ` [Bug tree-optimization/67769] [6 Regression] " mpolacek at gcc dot gnu.org
  2015-09-29 17:53 ` glisse at gcc dot gnu.org
@ 2015-09-29 17:59 ` mpolacek at gcc dot gnu.org
  2015-10-01 14:26 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-09-29 17:59 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Yea, something like that.  I'm taking this; it's sort of dependent on my patch
https://gcc.gnu.org/ml/gcc-patches/2015-09/msg02210.html (we'll probably need
to call reset_flow_sensitive_info_in_bb somewhere to fix this).


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

* [Bug tree-optimization/67769] [6 Regression] VRP pass does wrong optimization
  2015-09-29 16:24 [Bug c/67769] New: VRP pass does wrong optimization bmei at broadcom dot com
                   ` (2 preceding siblings ...)
  2015-09-29 17:59 ` mpolacek at gcc dot gnu.org
@ 2015-10-01 14:26 ` mpolacek at gcc dot gnu.org
  2015-10-01 19:09 ` mpolacek at gcc dot gnu.org
  2015-10-01 19:10 ` mpolacek at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-10-01 14:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Thu Oct  1 14:25:42 2015
New Revision: 228341

URL: https://gcc.gnu.org/viewcvs?rev=228341&root=gcc&view=rev
Log:
        PR tree-optimization/67769
        * tree-ssa-phiopt.c (conditional_replacement): Call
        reset_flow_sensitive_info_in_bb.
        (minmax_replacement): Likewise.
        (abs_replacement): Likewise.

        * gcc.dg/torture/pr67769.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr67769.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-phiopt.c


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

* [Bug tree-optimization/67769] [6 Regression] VRP pass does wrong optimization
  2015-09-29 16:24 [Bug c/67769] New: VRP pass does wrong optimization bmei at broadcom dot com
                   ` (3 preceding siblings ...)
  2015-10-01 14:26 ` mpolacek at gcc dot gnu.org
@ 2015-10-01 19:09 ` mpolacek at gcc dot gnu.org
  2015-10-01 19:10 ` mpolacek at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-10-01 19:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Thu Oct  1 19:09:01 2015
New Revision: 228353

URL: https://gcc.gnu.org/viewcvs?rev=228353&root=gcc&view=rev
Log:
        PR tree-optimization/67769
        * tree-ssa-phiopt.c (conditional_replacement): Call
        reset_flow_sensitive_info_in_bb.
        (minmax_replacement): Likewise.
        (abs_replacement): Likewise.

        * gcc.dg/torture/pr67769.c: New test.

Added:
    branches/gcc-5-branch/gcc/testsuite/gcc.dg/torture/pr67769.c
Modified:
    branches/gcc-5-branch/gcc/ChangeLog
    branches/gcc-5-branch/gcc/testsuite/ChangeLog
    branches/gcc-5-branch/gcc/tree-ssa-phiopt.c


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

* [Bug tree-optimization/67769] [6 Regression] VRP pass does wrong optimization
  2015-09-29 16:24 [Bug c/67769] New: VRP pass does wrong optimization bmei at broadcom dot com
                   ` (4 preceding siblings ...)
  2015-10-01 19:09 ` mpolacek at gcc dot gnu.org
@ 2015-10-01 19:10 ` mpolacek at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-10-01 19:10 UTC (permalink / raw)
  To: gcc-bugs

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

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> ---
Fixed.


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

end of thread, other threads:[~2015-10-01 19:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-29 16:24 [Bug c/67769] New: VRP pass does wrong optimization bmei at broadcom dot com
2015-09-29 17:51 ` [Bug tree-optimization/67769] [6 Regression] " mpolacek at gcc dot gnu.org
2015-09-29 17:53 ` glisse at gcc dot gnu.org
2015-09-29 17:59 ` mpolacek at gcc dot gnu.org
2015-10-01 14:26 ` mpolacek at gcc dot gnu.org
2015-10-01 19:09 ` mpolacek at gcc dot gnu.org
2015-10-01 19:10 ` 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).