Bug 11599 - gcc generates wrong code when predicate are used
Summary: gcc generates wrong code when predicate are used
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.3.1
: P1 critical
Target Milestone: 3.3.1
Assignee: Not yet assigned to anyone
Keywords: wrong-code
Depends on:
Reported: 2003-07-19 23:40 UTC by H.J. Lu
Modified: 2003-07-25 16:31 UTC (History)
1 user (show)

See Also:
Target: ia64-*-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2003-07-19 23:41:01


Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2003-07-19 23:40:33 UTC
[hjl@gnu-3 predicate]$ cat bar.i
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
        .align 16
        .global prefetch#
        .proc prefetch#
        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.
Comment 1 Andrew Pinski 2003-07-19 23:52:03 UTC
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:
        dcbtst 0,r3

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);
        li r0,0
        dst r3,r0,0
So very much a generic bug.
Comment 2 H.J. Lu 2003-07-20 05:04:07 UTC
I think they are 2 different bugs.


fixes the ia64 bug.
Comment 3 Andrew Pinski 2003-07-20 12:00:33 UTC
There are two different bugs as the powerpc-*-* one is caused by the if-conversion, I will 
file it seperately.
Comment 4 Falk Hueffner 2003-07-20 17:12:52 UTC
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
Comment 5 CVS Commits 2003-07-21 17:56:17 UTC
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.


Comment 6 Andrew Pinski 2003-07-21 18:17:41 UTC
Fixed on the mainline (for 3.4) and for 3.3.1 by the patch above.