From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24543 invoked by alias); 16 Mar 2013 18:03:22 -0000 Received: (qmail 24386 invoked by uid 48); 16 Mar 2013 18:02:51 -0000 From: "fkrogh#gcc at mathalacarte dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/56637] Bad result on max(1,shiftr(j,1)) Date: Sat, 16 Mar 2013 18:03:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: fkrogh#gcc at mathalacarte dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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 X-SW-Source: 2013-03/txt/msg01188.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56637 --- Comment #1 from Fred Krogh 2013-03-16 18:02:49 UTC --- I realize this is not much help for a bug report. I can't get a small test case to fail, and if I change the optimization level it works. Also, I can't be sure whether the problem is in the compiler or the library, but I suspect the former. Here is a small snippet of code k = max(1, shiftr(j,1)) ! The increment during the sort do ! Sort constraints to make active (Shell sort) do i = k + 1, j In my small test case j is 13. And k gets the value 1. If I precede the first statement with a garbage statement "i2=17" then after the first statement above, k has the correct value of 6, even though the added statement should not have changed the result. Here are my flags -ggdb -march=native -mpc80 -funroll-loops -pipe \ -ftree-vectorize -floop-strip-mine \ -floop-block -fimplicit-none -finit-real=NAN -fopenmp\ -fcheck=bounds -Wall -Wextra If I follow -ggdb with either -O1 or -O2 it gets the correct result. This is running on a Gentoo Linux system, with Intel I7 CPU's. Finally, here is a dump of the assembler code from the start of the first statement. Dump of assembler code from 0x40e5f1 to 0x40e6f1: => 0x000000000040e5f1 : mov 0x1204(%rbx),%edx 0x000000000040e5f7 : mov $0x1,%eax 0x000000000040e5fc : shr %edx 0x000000000040e5fe : cmp %eax,%edx 0x000000000040e600 : jle 0x40e604 0x000000000040e602 : mov %edx,%eax 0x000000000040e604 : mov %eax,0x1330(%rbx) 0x000000000040e60a : mov 0x1330(%rbx),%eax 0x000000000040e610 : add $0x1,%eax 0x000000000040e613 : mov 0x1204(%rbx),%esi 0x000000000040e619 : mov %eax,0x133c(%rbx) 0x000000000040e61f : mov 0x133c(%rbx),%eax 0x000000000040e625 : cmp %esi,%eax 0x000000000040e627 : jg 0x40ea50 0x000000000040e62d : jmp 0x40e630 0x000000000040e62f : nop 0x000000000040e630 : mov 0x133c(%rbx),%eax 0x000000000040e636 : cltq 0x000000000040e638 : test %rax,%rax 0x000000000040e63b : setle %dl 0x000000000040e63e : movzbl %dl,%edx 0x000000000040e641 : mov %edx,%edx 0x000000000040e643 : and $0x1,%edx 0x000000000040e646 : test %edx,%edx 0x000000000040e648 : je 0x40e666 0x000000000040e64a : mov $0x1,%ecx 0x000000000040e64f : mov %rax,%rdx 0x000000000040e652 : mov $0x4820d8,%esi 0x000000000040e657 : mov $0x4827f0,%edi 0x000000000040e65c : mov $0x0,%eax 0x000000000040e661 : callq 0x401d70 <_gfortran_runtime_error_at@plt> 0x000000000040e666 : cmp $0x12,%rax 0x000000000040e66a : setg %dl 0x000000000040e66d : movzbl %dl,%edx 0x000000000040e670 : mov %edx,%edx 0x000000000040e672 : and $0x1,%edx 0x000000000040e675 : test %edx,%edx 0x000000000040e677 : je 0x40e695 0x000000000040e679 : mov $0x12,%ecx 0x000000000040e67e : mov %rax,%rdx 0x000000000040e681 : mov $0x482148,%esi 0x000000000040e686 : mov $0x4827f0,%edi 0x000000000040e68b : mov $0x0,%eax 0x000000000040e690 : callq 0x401d70 <_gfortran_runtime_error_at@plt> 0x000000000040e695 : sub $0x1,%rax 0x000000000040e699 : add $0x4b8,%rax 0x000000000040e69f : mov 0x4(%rbx,%rax,4),%eax 0x000000000040e6a3 : mov %eax,0x1200(%rbx) 0x000000000040e6a9 : mov 0x1200(%rbx),%eax 0x000000000040e6af : add $0x1,%eax 0x000000000040e6b2 : movslq %eax,%rdx 0x000000000040e6b5 : test %rdx,%rdx 0x000000000040e6b8 : setle %al 0x000000000040e6bb : movzbl %al,%eax 0x000000000040e6be : mov %eax,%eax 0x000000000040e6c0 : and $0x1,%eax 0x000000000040e6c3 : test %eax,%eax 0x000000000040e6c5 : je 0x40e6e0 0x000000000040e6c7 : mov $0x1,%ecx 0x000000000040e6cc : mov $0x481190,%esi 0x000000000040e6d1 : mov $0x482818,%edi 0x000000000040e6d6 : mov $0x0,%eax 0x000000000040e6db : callq 0x401d70 <_gfortran_runtime_error_at@plt> 0x000000000040e6e0 : cmp $0x21,%rdx 0x000000000040e6e4 : setg %al 0x000000000040e6e7 : movzbl %al,%eax 0x000000000040e6ea : mov %eax,%eax 0x000000000040e6ec : and $0x1,%eax 0x000000000040e6ef : test %eax,%eax End of assembler dump.