public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/58019] New: Problem with -O3 optimization
@ 2013-07-29 16:06 william.jordan at vbrick dot com
2013-07-29 16:21 ` [Bug c/58019] " glisse at gcc dot gnu.org
2013-07-29 17:03 ` william.jordan at vbrick dot com
0 siblings, 2 replies; 3+ messages in thread
From: william.jordan at vbrick dot com @ 2013-07-29 16:06 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58019
Bug ID: 58019
Summary: Problem with -O3 optimization
Product: gcc
Version: 4.7.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: william.jordan at vbrick dot com
I wrote a simple program to solve the 8 queens chess problem (i.e. put 8 queens
on a chessboard so that no queen can take any other queen). When I compile the
program normally or with -O1 -O2 optimization it finds solutions and prints
them out. When I compile with -O3 optimization it finds no solutions.
Below is the compiler version and source code. This was also reproduced using
gcc 4.1.2.
gcc -v output:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.7.3-1ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs
--enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.7 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin
--with-system-zlib --enable-objc-gc --with-cloog --enable-cloog-backend=ppl
--disable-cloog-version-check --disable-ppl-version-check --enable-multiarch
--disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-1ubuntu1)
Source code to reproduce problem:
#include <stdio.h>
int TestPiece(int ipos, int jpos, int board[8][8])
{
int i, j;
for (i = 0; i < 8; i++) {
for (j = 0; j < 8; j++) {
if (board[i][j] && (i != ipos || j!= jpos)) {
if (i == ipos) {
return(1);
} else if (j == jpos) {
return(2);
} else if ((ipos - i == jpos - j) || (i - ipos == jpos - j)) {
return(3);
}
}
}
}
return(0);
}
int TestBoard(int board[8][8])
{
int i, j;
for (i = 0; i < 8; i++) {
for (j = 0; j < 8; j++) {
if (board[i][j]) {
if (TestPiece(i, j, board)) {
return(1);
}
}
}
}
}
int PrintBoard(int board[8][8])
{
int i, j;
printf("Solution found\n\n");
for (i = 0; i < 8; i++) {
for (j = 0; j < 8; j++) {
if (board[i][j]) {
printf("Q");
} else {
printf("-");
}
}
printf("\n");
}
printf("\n");
}
int main(int argc, char *argv[])
{
int board[8][8];
int i, j, k, numchecks = 1;
for (i = 0; i < 8; i++) {
numchecks *= 8;
for (j = 0; j < 8; j++) {
if (j == 0) {
board[i][j] = 1;
} else {
board[i][j] = 0;
}
}
}
for (i = 0; i < numchecks; i++) {
if (!TestBoard(board)) {
PrintBoard(board);
}
for (j = 7; j >= 0; j--) {
if (board[j][7]) {
board[j][7] = 0;
board[j][0] = 1;
} else {
for (k = 0; k < 7; k++) {
if (board[j][k]) {
board[j][k] = 0;
board[j][k + 1] = 1;
break;
}
}
break;
}
}
}
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/58019] Problem with -O3 optimization
2013-07-29 16:06 [Bug c/58019] New: Problem with -O3 optimization william.jordan at vbrick dot com
@ 2013-07-29 16:21 ` glisse at gcc dot gnu.org
2013-07-29 17:03 ` william.jordan at vbrick dot com
1 sibling, 0 replies; 3+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-07-29 16:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58019
Marc Glisse <glisse at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |WAITING
Last reconfirmed| |2013-07-29
Ever confirmed|0 |1
--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
Your testcase produces obvious warnings with -Wall -Wextra. Please provide a
fixed testcase (or close the bug if following the warnings solves your issue).
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/58019] Problem with -O3 optimization
2013-07-29 16:06 [Bug c/58019] New: Problem with -O3 optimization william.jordan at vbrick dot com
2013-07-29 16:21 ` [Bug c/58019] " glisse at gcc dot gnu.org
@ 2013-07-29 17:03 ` william.jordan at vbrick dot com
1 sibling, 0 replies; 3+ messages in thread
From: william.jordan at vbrick dot com @ 2013-07-29 17:03 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58019
Bill <william.jordan at vbrick dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Bill <william.jordan at vbrick dot com> ---
Close the bug. I fixed the warnings produced by -Wall and it worked correctly.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-07-29 17:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-29 16:06 [Bug c/58019] New: Problem with -O3 optimization william.jordan at vbrick dot com
2013-07-29 16:21 ` [Bug c/58019] " glisse at gcc dot gnu.org
2013-07-29 17:03 ` william.jordan at vbrick dot com
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).