This makes builtin-bitops-1.c fail at -O3. Test case: int main (void) { unsigned long long x; int i; x = 2; for (i = 0; i < 64; i++) if (x & (1ULL << (64 - i - 1))) break; x = 4; for (i = 0; i < 64; i++) if (x & (1ULL << (64 - i - 1))) break; if (i != 61) abort (); return 0; } This aborts at -O and higher. version: 3.5-tree-ssa 20031106
In combine, the shift in the second loop gets lost somehow. However, combine on tree-ssa does the same as on mainline AFAIK, so most likely something went wrong earlier already.
How does the tree dumps look?
Subject: Re: [tree-ssa] loop miscompilation "pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes: > How does the tree dumps look? ;; Function main (main) main () { int T.1; long long unsigned int T.2; unsigned int T.3; int T.4; int T.5; _Bool T.6; long long unsigned int x; int i; extern abort; x = 2;; i = 0;; goto <D42f>;; <D427>:;; T.1 = 63 - i;; T.2 = x >> T.1;; T.3 = (unsigned int)T.2;; T.4 = (int)T.3;; T.5 = T.4 & 1;; T.6 = (_Bool)T.5;; if (T.6) { goto <D426>;; } else { }; i = i + 1;; <D42f>:;; if (i <= 63) { goto <D427>;; } else { goto <D426>;; }; <D426>:;; x = 4;; i = 0;; goto <D433>;; <D431>:;; T.1 = 63 - i;; T.2 = x >> T.1;; T.3 = (unsigned int)T.2;; T.4 = (int)T.3;; T.5 = T.4 & 1;; T.6 = (_Bool)T.5;; if (T.6) { goto <D430>;; } else { }; i = i + 1;; <D433>:;; if (i <= 63) { goto <D431>;; } else { goto <D430>;; }; <D430>:;; if (i != 61) { abort ();; } else { }; return 0;; }
Must be another RTL miscompiling problem.
Does this work now?
(In reply to comment #5) > Does this work now? No, still present with 20031201. Interestingly, Diego's latest test result (http://gcc.gnu.org/ml/gcc-testresults/2003-11/msg01294.html) doesn't show builtin-bitops-1.c as failing, which is weird, because it does fail for me...
This is not loop, but combine. Its line of reasoning goes 1) (2 & (1 << (63 - i))) != 0) 2) = (((2 >> (63 - i)) & 1) != 0) 3) = (((2 >> ~i) & 1) != 0) # From SHIFT_COUNT_TRUNCATED 4) = ~i == 1 # Since only 2 >> 1 & 1 != 0 5) = i == -2 Of course, I is never negative; the correct result is I == 62. Clearly the reasoning in step 4 is flawed if SHIFT_COUNT_TRUNCATED is set. I've not yet located the exact place in combine that makes this leap...
Subject: Bug 12941 CVSROOT: /cvs/gcc Module name: gcc Branch: tree-ssa-20020619-branch Changes by: rth@gcc.gnu.org 2004-01-23 20:27:39 Modified files: gcc : ChangeLog.tree-ssa combine.c Log message: PR opt/12941 * combine.c (SHIFT_COUNT_TRUNCATED): Provide default value. (simplify_comparison): Don't simplify (eq (zero_extract c 1 r) 0) if SHIFT_COUNT_TRUNCATED is set. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.tree-ssa.diff?cvsroot=gcc&only_with_tag=tree-ssa-20020619-branch&r1=1.1.2.1125&r2=1.1.2.1126 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/combine.c.diff?cvsroot=gcc&only_with_tag=tree-ssa-20020619-branch&r1=1.299.2.32&r2=1.299.2.33
http://gcc.gnu.org/ml/gcc-patches/2004-01/msg02512.html
Subject: Re: [tree-ssa] builtin-bitops-1.c miscompilation On Fri, Jan 30, 2004 at 07:57:10PM -0000, jbuck at gcc dot gnu dot org wrote: > What |Removed |Added > ---------------------------------------------------------------------------- > Target Milestone|3.3.3 |tree-ssa No, the bug was latent. I backported it. r~
RTH writes: > No, the bug was latent. I backported it. OK; since there was no record of a backport or a reference to anything other than the tree-ssa branch, I assumed that the target milestone was an error.