Bug 11599 - gcc generates wrong code when predicate are used
Summary: gcc generates wrong code when predicate are used
Status: RESOLVED FIXED
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
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2003-07-19 23:40 UTC by H.J. Lu
Modified: 2003-07-25 16:31 UTC (History)
1 user (show)

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


Attachments

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
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.
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:
_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.
Comment 2 H.J. Lu 2003-07-20 05:04:07 UTC
I think they are 2 different bugs.

http://gcc.gnu.org/ml/gcc-patches/2003-07/msg01997.html

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
__builtin_prefetch?
Comment 5 GCC 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.

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

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.