http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56637
--- Comment #1 from Fred Krogh <fkrogh#gcc at mathalacarte dot com> 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 <find_unequals+5571>: mov 0x1204(%rbx),%edx 0x000000000040e5f7 <find_unequals+5577>: mov $0x1,%eax 0x000000000040e5fc <find_unequals+5582>: shr %edx 0x000000000040e5fe <find_unequals+5584>: cmp %eax,%edx 0x000000000040e600 <find_unequals+5586>: jle 0x40e604 <find_unequals+5590> 0x000000000040e602 <find_unequals+5588>: mov %edx,%eax 0x000000000040e604 <find_unequals+5590>: mov %eax,0x1330(%rbx) 0x000000000040e60a <find_unequals+5596>: mov 0x1330(%rbx),%eax 0x000000000040e610 <find_unequals+5602>: add $0x1,%eax 0x000000000040e613 <find_unequals+5605>: mov 0x1204(%rbx),%esi 0x000000000040e619 <find_unequals+5611>: mov %eax,0x133c(%rbx) 0x000000000040e61f <find_unequals+5617>: mov 0x133c(%rbx),%eax 0x000000000040e625 <find_unequals+5623>: cmp %esi,%eax 0x000000000040e627 <find_unequals+5625>: jg 0x40ea50 <find_unequals+6690> 0x000000000040e62d <find_unequals+5631>: jmp 0x40e630 <find_unequals+5634> 0x000000000040e62f <find_unequals+5633>: nop 0x000000000040e630 <find_unequals+5634>: mov 0x133c(%rbx),%eax 0x000000000040e636 <find_unequals+5640>: cltq 0x000000000040e638 <find_unequals+5642>: test %rax,%rax 0x000000000040e63b <find_unequals+5645>: setle %dl 0x000000000040e63e <find_unequals+5648>: movzbl %dl,%edx 0x000000000040e641 <find_unequals+5651>: mov %edx,%edx 0x000000000040e643 <find_unequals+5653>: and $0x1,%edx 0x000000000040e646 <find_unequals+5656>: test %edx,%edx 0x000000000040e648 <find_unequals+5658>: je 0x40e666 <find_unequals+5688> 0x000000000040e64a <find_unequals+5660>: mov $0x1,%ecx 0x000000000040e64f <find_unequals+5665>: mov %rax,%rdx 0x000000000040e652 <find_unequals+5668>: mov $0x4820d8,%esi 0x000000000040e657 <find_unequals+5673>: mov $0x4827f0,%edi 0x000000000040e65c <find_unequals+5678>: mov $0x0,%eax 0x000000000040e661 <find_unequals+5683>: callq 0x401d70 <_gfortran_runtime_error_at@plt> 0x000000000040e666 <find_unequals+5688>: cmp $0x12,%rax 0x000000000040e66a <find_unequals+5692>: setg %dl 0x000000000040e66d <find_unequals+5695>: movzbl %dl,%edx 0x000000000040e670 <find_unequals+5698>: mov %edx,%edx 0x000000000040e672 <find_unequals+5700>: and $0x1,%edx 0x000000000040e675 <find_unequals+5703>: test %edx,%edx 0x000000000040e677 <find_unequals+5705>: je 0x40e695 <find_unequals+5735> 0x000000000040e679 <find_unequals+5707>: mov $0x12,%ecx 0x000000000040e67e <find_unequals+5712>: mov %rax,%rdx 0x000000000040e681 <find_unequals+5715>: mov $0x482148,%esi 0x000000000040e686 <find_unequals+5720>: mov $0x4827f0,%edi 0x000000000040e68b <find_unequals+5725>: mov $0x0,%eax 0x000000000040e690 <find_unequals+5730>: callq 0x401d70 <_gfortran_runtime_error_at@plt> 0x000000000040e695 <find_unequals+5735>: sub $0x1,%rax 0x000000000040e699 <find_unequals+5739>: add $0x4b8,%rax 0x000000000040e69f <find_unequals+5745>: mov 0x4(%rbx,%rax,4),%eax 0x000000000040e6a3 <find_unequals+5749>: mov %eax,0x1200(%rbx) 0x000000000040e6a9 <find_unequals+5755>: mov 0x1200(%rbx),%eax 0x000000000040e6af <find_unequals+5761>: add $0x1,%eax 0x000000000040e6b2 <find_unequals+5764>: movslq %eax,%rdx 0x000000000040e6b5 <find_unequals+5767>: test %rdx,%rdx 0x000000000040e6b8 <find_unequals+5770>: setle %al 0x000000000040e6bb <find_unequals+5773>: movzbl %al,%eax 0x000000000040e6be <find_unequals+5776>: mov %eax,%eax 0x000000000040e6c0 <find_unequals+5778>: and $0x1,%eax 0x000000000040e6c3 <find_unequals+5781>: test %eax,%eax 0x000000000040e6c5 <find_unequals+5783>: je 0x40e6e0 <find_unequals+5810> 0x000000000040e6c7 <find_unequals+5785>: mov $0x1,%ecx 0x000000000040e6cc <find_unequals+5790>: mov $0x481190,%esi 0x000000000040e6d1 <find_unequals+5795>: mov $0x482818,%edi 0x000000000040e6d6 <find_unequals+5800>: mov $0x0,%eax 0x000000000040e6db <find_unequals+5805>: callq 0x401d70 <_gfortran_runtime_error_at@plt> 0x000000000040e6e0 <find_unequals+5810>: cmp $0x21,%rdx 0x000000000040e6e4 <find_unequals+5814>: setg %al 0x000000000040e6e7 <find_unequals+5817>: movzbl %al,%eax 0x000000000040e6ea <find_unequals+5820>: mov %eax,%eax 0x000000000040e6ec <find_unequals+5822>: and $0x1,%eax 0x000000000040e6ef <find_unequals+5825>: test %eax,%eax End of assembler dump.