From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 70531 invoked by alias); 28 Apr 2015 14:23:09 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 70501 invoked by uid 48); 28 Apr 2015 14:23:05 -0000 From: "habanero_pizza at yahoo dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/65918] New: Optimized code (> -O0) on 2-dim array iteration incorrect Date: Tue, 28 Apr 2015 14:23:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 5.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: habanero_pizza at yahoo dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone cf_gcchost cf_gcctarget cf_gccbuild attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-04/txt/msg02406.txt.bz2 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.]