public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/65918] New: Optimized code (> -O0) on 2-dim array iteration incorrect
@ 2015-04-28 14:23 habanero_pizza at yahoo dot com
  2015-04-28 14:24 ` [Bug tree-optimization/65918] " habanero_pizza at yahoo dot com
  2015-04-28 14:35 ` trippels at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: habanero_pizza at yahoo dot com @ 2015-04-28 14:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 65918
           Summary: Optimized code (> -O0) on 2-dim array iteration
                    incorrect
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: habanero_pizza at yahoo dot com
  Target Milestone: ---
              Host: i686-pc-linux-gnu
            Target: i686-pc-linux-gnu
             Build: i686-pc-linux-gnu

Created attachment 35413
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35413&action=edit
Test case source:  execution fails if OKAY is not defined...

When the following function is compiled with gcc 4.8.3, 4.9.2, or 5.1.0, it
only executes properly when no optimization is specified (-O0):

int f(int value, int type)
{
    static const int limits[2][3] = {
        { 400, 480, 512 },
        { 460, 492, 500 }
    };

    int retval = 0;

    while ((value > limits[type][retval]) && (retval < 3)) {
        retval++;
    }

    return retval;
}

The problem is in the case where retval should be 3; for example, if value is
550 and type is 0, the retval should be 3, but the function will return 2.  For
cases where the function is supposed to return 0, 1, or 2, it does work
correctly.

However, if gcc 4.6.4 or gcc 4.7.2 is used, it works correctly with and without
optimization.

If the loop is changed to use an array of a single dimension, the problem is
also eliminated (4.8, 4.9, 5.1):

    const int *limit = limits[type];

    while ((value > limit[retval]) && (retval < 3)) {
        retval++;
    }

I have also confirmed that the problem appears for x86_64 and ARM
architectures.

See attached file (test-opt-2-dim-array-iter.c) for further information.

Compilation details:

Using built-in specs.
COLLECT_GCC=i386-eabi-gcc
COLLECT_LTO_WRAPPER=/usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/5.1.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../../gcc-5.1.0/configure --prefix=/usr/local/i386-eabi-5.1.0
--program-prefix=i386-eabi- --enable-languages=c,c++
--with-gmp=/usr/local/i386-eabi-5.1.0 --with-mpfr=/usr/local/i386-eabi-5.1.0
--with-mpc=/usr/local/i386-eabi-5.1.0 --with-isl=/usr/local/i386-eabi-5.1.0
--with-zlib=/usr/local --enable-lto --enable-gold
Thread model: posix
gcc version 5.1.0 (GCC) 
COLLECT_GCC_OPTIONS='-O1' '-v' '-save-temps' '-o' 'test-opt-2-dim-array-iter'
'-mtune=generic' '-march=pentiumpro'
 /usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/5.1.0/cc1 -E -quiet
-v test-opt-2-dim-array-iter.c -mtune=generic -march=pentiumpro -O1
-fpch-preprocess -o test-opt-2-dim-array-iter.i
ignoring nonexistent directory
"/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/include
 /usr/local/include
 /usr/local/i386-eabi-5.1.0/include
 /usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-O1' '-v' '-save-temps' '-o' 'test-opt-2-dim-array-iter'
'-mtune=generic' '-march=pentiumpro'
 /usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/5.1.0/cc1
-fpreprocessed test-opt-2-dim-array-iter.i -quiet -dumpbase
test-opt-2-dim-array-iter.c -mtune=generic -march=pentiumpro -auxbase
test-opt-2-dim-array-iter -O1 -version -o test-opt-2-dim-array-iter.s
GNU C11 (GCC) version 5.1.0 (i686-pc-linux-gnu)
        compiled by GNU C version 5.1.0, GMP version 5.1.3, MPFR version 3.1.2,
MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C11 (GCC) version 5.1.0 (i686-pc-linux-gnu)
        compiled by GNU C version 5.1.0, GMP version 5.1.3, MPFR version 3.1.2,
MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: d06407f4e6fff3c174315d9bcdf98d85
COLLECT_GCC_OPTIONS='-O1' '-v' '-save-temps' '-o' 'test-opt-2-dim-array-iter'
'-mtune=generic' '-march=pentiumpro'

/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/../../../../i686-pc-linux-gnu/bin/as
-v --32 -o test-opt-2-dim-array-iter.o test-opt-2-dim-array-iter.s
GNU assembler version 2.25 (i686-pc-linux-gnu) using BFD version (GNU Binutils)
2.25
COMPILER_PATH=/usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/5.1.0/:/usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/5.1.0/:/usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/:/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/:/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/:/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/../../../../i686-pc-linux-gnu/bin/
LIBRARY_PATH=/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/:/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-O1' '-v' '-save-temps' '-o' 'test-opt-2-dim-array-iter'
'-mtune=generic' '-march=pentiumpro'
 /usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/5.1.0/collect2
-plugin
/usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/5.1.0/liblto_plugin.so
-plugin-opt=/usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/5.1.0/lto-wrapper
-plugin-opt=-fresolution=test-opt-2-dim-array-iter.res
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s
-plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc
-plugin-opt=-pass-through=-lgcc_s --eh-frame-hdr -m elf_i386 -dynamic-linker
/lib/ld-linux.so.2 -o test-opt-2-dim-array-iter /usr/lib/crt1.o /usr/lib/crti.o
/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/crtbegin.o
-L/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0
-L/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/../../..
test-opt-2-dim-array-iter.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc
--as-needed -lgcc_s --no-as-needed
/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/crtend.o
/usr/lib/crtn.o

Preprocessed code:

  [Will add as an additional attachment.]


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

* [Bug tree-optimization/65918] Optimized code (> -O0) on 2-dim array iteration incorrect
  2015-04-28 14:23 [Bug tree-optimization/65918] New: Optimized code (> -O0) on 2-dim array iteration incorrect habanero_pizza at yahoo dot com
@ 2015-04-28 14:24 ` habanero_pizza at yahoo dot com
  2015-04-28 14:35 ` trippels at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: habanero_pizza at yahoo dot com @ 2015-04-28 14:24 UTC (permalink / raw)
  To: gcc-bugs

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

J. W. Mitchell <habanero_pizza at yahoo dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |habanero_pizza at yahoo dot com

--- Comment #1 from J. W. Mitchell <habanero_pizza at yahoo dot com> ---
Created attachment 35414
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35414&action=edit
Preprocessed test case.


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

* [Bug tree-optimization/65918] Optimized code (> -O0) on 2-dim array iteration incorrect
  2015-04-28 14:23 [Bug tree-optimization/65918] New: Optimized code (> -O0) on 2-dim array iteration incorrect habanero_pizza at yahoo dot com
  2015-04-28 14:24 ` [Bug tree-optimization/65918] " habanero_pizza at yahoo dot com
@ 2015-04-28 14:35 ` trippels at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: trippels at gcc dot gnu.org @ 2015-04-28 14:35 UTC (permalink / raw)
  To: gcc-bugs

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

Markus Trippelsdorf <trippels at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |trippels at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #2 from Markus Trippelsdorf <trippels at gcc dot gnu.org> ---
while ((value > limits[type][retval]) && (retval < 3))

well, the index gets out of bound. Check (retval < 3) first.


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

end of thread, other threads:[~2015-04-28 14:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-28 14:23 [Bug tree-optimization/65918] New: Optimized code (> -O0) on 2-dim array iteration incorrect habanero_pizza at yahoo dot com
2015-04-28 14:24 ` [Bug tree-optimization/65918] " habanero_pizza at yahoo dot com
2015-04-28 14:35 ` trippels 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).