[hjl@gnu-3 predicate]$ cat bar.i void prefetch (void *p, int s) { if (s) __builtin_prefetch (p, 1, 1); } [hjl@gnu-3 predicate]$ make /usr/gcc-3.4/bin/gcc -Wall -O bar.i -S [hjl@gnu-3 predicate]$ cat bar.s .pred.safe_across_calls p1-p5,p16-p63 .text .align 16 .global prefetch# .proc prefetch# prefetch: .prologue .body cmp4.eq p6, p7 = 0, r33 ;; lfetch.excl.nt1 [r32] br.ret.sptk.many rp ;; .endp prefetch# The problem is there is no (p7) before "lfetch.excl.nt1 [r32]". That means __builtin_prefetch (p, 1, 1); is always executed even if 's' is 0.
Do not confirm your own bugs, please. We like to use peer review. It also happens on powerpc-apple-darwin6.6 so it looks like a generic bug: _prefetch: dcbtst 0,r3 blr gcc -S -O -Wall -o - pr11599.c -v -maltivec, where pr11599.c contains: void t(void *p, int s) { if (s) __builtin_altivec_dst (p, 0, 0); } produces: _t: li r0,0 dst r3,r0,0 blr So very much a generic bug.
I think they are 2 different bugs. http://gcc.gnu.org/ml/gcc-patches/2003-07/msg01997.html fixes the ia64 bug.
There are two different bugs as the powerpc-*-* one is caused by the if-conversion, I will file it seperately.
I'm not convinced this is a bug. __builtin_prefetch is supposed to have no visible effect, so gcc should be free to move it out of conditions, as it also does with arithmetics. Does this also occur with anything else than __builtin_prefetch?
Subject: Bug 11599 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: hjl@gcc.gnu.org 2003-07-21 17:56:14 Modified files: gcc : ChangeLog gcc/config/ia64: ia64.md Log message: 2003-07-21 H.J. Lu <hongjiu.lu@intel.com> PR optimization/11599 * config/ia64/ia64.md (prefetch): Support predicate. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.679&r2=1.16114.2.680 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/ia64/ia64.md.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.94.4.6&r2=1.94.4.7
Fixed on the mainline (for 3.4) and for 3.3.1 by the patch above.