Bug 7374 - __builtin_fabsl broken on alpha
Summary: __builtin_fabsl broken on alpha
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.2
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2002-07-22 09:26 UTC by snyder
Modified: 2003-07-25 17:33 UTC (History)
2 users (show)

See Also:
Host: alpha-dec-osf5.1
Target: alpha-dec-osf5.1
Build: alpha-dec-osf5.1
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description snyder 2002-07-22 09:26:01 UTC
On the alpha, the program below is miscompiled --- it prints -1
instead of 1:

$ gcc -o x x.c 
$ ./x
-1.000000
$


Here's the generated code for foo().
It looks to me like this code is negating the argument, rather
than taking the absolute value.


        .ent foo
$foo..ng:
foo:
        .frame $15,16,$26,0
        .mask 0x4008000,-16
        lda $30,-16($30)
        stq $26,0($30)
        stq $15,8($30)
        bis $31,$30,$15
        .prologue 0
        bis $31,$16,$0
        bis $31,$17,$1
        ldq $2,0($1)
        ldq $3,8($1)
        lda $1,-1($31)
        sll $1,63,$1
        xor $1,$3,$3
        bis $31,$2,$1
        bis $31,$3,$2
        stq $1,0($0)
        stq $2,8($0)
        bis $31,$15,$30
        ldq $26,0($30)
        ldq $15,8($30)
        lda $30,16($30)
        ret $31,($26),1
        .end foo


Indeed, in alpha.md, i find this:

(define_expand "abstf2"
  [(parallel [(set (match_operand:TF 0 "register_operand" "")
		   (neg:TF (match_operand:TF 1 "reg_or_0_operand" "")))
	      (use (match_dup 2))])]
  "TARGET_HAS_XFLOATING_LIBS"
{
#if HOST_BITS_PER_WIDE_INT >= 64
  operands[2] = force_reg (DImode, GEN_INT ((HOST_WIDE_INT) 1 << 63));
#else
  operands[2] = force_reg (DImode, immed_double_const (0, 0x80000000, DImode));
#endif
})


Note the `neg' here.  If i change this to `abs' (patch below),
then i get the correct results from this test program.

Release:
3.2 20020718 (experimental)

Environment:
System: OSF1 d0ola.fnal.gov V5.1 732 alpha
Machine: alpha
	
host: alpha-dec-osf5.1
build: alpha-dec-osf5.1
target: alpha-dec-osf5.1
configured with: ../gcc/configure --prefix=/usr/local/egcs --enable-threads=posix --enable-long-long : (reconfigured) ../gcc/configure --prefix=/scratch/snyder/gcc/inst --enable-threads=posix --enable-long-long : (reconfigured) ../gcc/configure --prefix=/scratch/snyder/gcc/inst --enable-threads=posix --enable-long-long --enable-languages=c,c++,f77

How-To-Repeat:

------------------------------------------------------------------------
long double foo (long double xx)
{
  return __builtin_fabsl (xx);
}


int main() {
  long double xx = 1.0;
  long double yy = foo (xx);
  printf ("%f\n", (float) (yy));
  return 0;
}

------------------------------------------------------------------------
Comment 1 snyder 2002-07-22 09:26:01 UTC
Fix:

2002-07-22  scott snyder  <snyder@fnal.gov>

	* config/alpha/alpha.md (abstf2): Fix typo: `neg' for `abs'.

Index: config/alpha/alpha.md
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/alpha/alpha.md,v
retrieving revision 1.194
diff -u -c -r1.194 alpha.md
*** config/alpha/alpha.md	14 Jun 2002 20:26:23 -0000	1.194
--- config/alpha/alpha.md	22 Jul 2002 16:15:23 -0000
***************
*** 2134,2140 ****
  
  (define_expand "abstf2"
    [(parallel [(set (match_operand:TF 0 "register_operand" "")
! 		   (neg:TF (match_operand:TF 1 "reg_or_0_operand" "")))
  	      (use (match_dup 2))])]
    "TARGET_HAS_XFLOATING_LIBS"
  {
--- 2134,2140 ----
  
  (define_expand "abstf2"
    [(parallel [(set (match_operand:TF 0 "register_operand" "")
! 		   (abs:TF (match_operand:TF 1 "reg_or_0_operand" "")))
  	      (use (match_dup 2))])]
    "TARGET_HAS_XFLOATING_LIBS"
  {
Comment 2 Roger Sayle 2002-09-07 23:03:37 UTC
State-Changed-From-To: open->closed
State-Changed-Why: This should now be fixed, both on mainline and on the
    3.2 branch (3.2.1 pre-release), by the following patch:
    
    2002-09-07  Scott Snyder  <snyder@fnal.gov>
    
            PR target/7374
            * config/alpha/alpha.md (abstf2): Fix typo: 'neg' for 'abs'.
    
    This is the patch originally proposed in the GNATS PR.
Comment 3 Roger Sayle 2002-09-08 05:22:54 UTC
From: sayle@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: target/7374
Date: 8 Sep 2002 05:22:54 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	sayle@gcc.gnu.org	2002-09-07 22:22:54
 
 Modified files:
 	gcc            : ChangeLog 
 	gcc/config/alpha: alpha.md 
 
 Log message:
 	2002-09-07  Scott Snyder  <snyder@fnal.gov>
 	
 	PR target/7374
 	* config/alpha/alpha.md (abstf2): Fix typo: 'neg' for 'abs'.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=1.15354&r2=1.15355
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/alpha/alpha.md.diff?cvsroot=gcc&r1=1.195&r2=1.196
 

Comment 4 Roger Sayle 2002-09-08 05:30:20 UTC
From: sayle@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: target/7374
Date: 8 Sep 2002 05:30:20 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	sayle@gcc.gnu.org	2002-09-07 22:30:19
 
 Modified files:
 	gcc            : ChangeLog 
 	gcc/config/alpha: alpha.md 
 
 Log message:
 	2002-09-07  Scott Snyder  <snyder@fnal.gov>
 	
 	PR target/7374
 	* config/alpha/alpha.md (abstf2): Fix typo: 'neg' for 'abs'.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.13152.2.657.2.33&r2=1.13152.2.657.2.34
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/alpha/alpha.md.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.182.2.4&r2=1.182.2.4.4.1