public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/40809]  New: wrong conversion from unsigned int to float
@ 2009-07-20 19:52 foldy at rmki dot kfki dot hu
  2009-07-20 21:13 ` [Bug target/40809] " hjl dot tools at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: foldy at rmki dot kfki dot hu @ 2009-07-20 19:52 UTC (permalink / raw)
  To: gcc-bugs

The following program produces wrong results at -m64 -O3:

// a.cc

#include <iostream>

#define N 5

void
cvt_u4_f4(int n, unsigned int* u4, float* f4)
{
    for (int j=0; j<n; j++)
         f4[j]=u4[j];
}


int main()
{
  unsigned int u4[N];
  float f4[N];

  for (unsigned int j=0; j<N; j++) u4[j]=4000000000u+j;

  cvt_u4_f4(N, u4, f4);

  for (int j=0; j<N; j++) std::cout << f4[j] << std::endl;
}

g++-4.4 -m64 -O3 a.cc && ./a.out prints:

-2.94967e+08
-2.94967e+08
-2.94967e+08
-2.94967e+08
4e+09

At -O0/-O1/-O2 the results are correct:

4e+09
4e+09
4e+09
4e+09
4e+09


-- 
           Summary: wrong conversion from unsigned int to float
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: foldy at rmki dot kfki dot hu
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40809


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug target/40809] wrong conversion from unsigned int to float
  2009-07-20 19:52 [Bug c++/40809] New: wrong conversion from unsigned int to float foldy at rmki dot kfki dot hu
@ 2009-07-20 21:13 ` hjl dot tools at gmail dot com
  2009-07-20 21:16 ` hjl dot tools at gmail dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: hjl dot tools at gmail dot com @ 2009-07-20 21:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from hjl dot tools at gmail dot com  2009-07-20 21:13 -------
Vectorizer needs to check signs when vectorizing conversions from
unsigned int to float if int > float vector insn is used. For example:

        cvtdq2ps  u4(%rip), %xmm2   
        movaps    %xmm2, %xmm1                              
        pxor      %xmm0, %xmm0                                
        cmpltps   %xmm0, %xmm1                               
        andps     _2il0floatpacket.1(%rip), %xmm1       
        addps     %xmm1, %xmm2
...
_2il0floatpacket.1:
        .long   0x4f800000,0x4f800000,0x4f800000,0x4f800000


-- 

hjl dot tools at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |irar at il dot ibm dot com,
                   |                            |rguenth at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-07-20 21:13:31
               date|                            |
            Version|4.4.0                       |4.3.4


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40809


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug target/40809] wrong conversion from unsigned int to float
  2009-07-20 19:52 [Bug c++/40809] New: wrong conversion from unsigned int to float foldy at rmki dot kfki dot hu
  2009-07-20 21:13 ` [Bug target/40809] " hjl dot tools at gmail dot com
@ 2009-07-20 21:16 ` hjl dot tools at gmail dot com
  2009-07-20 22:47 ` ubizjak at gmail dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: hjl dot tools at gmail dot com @ 2009-07-20 21:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from hjl dot tools at gmail dot com  2009-07-20 21:16 -------
(In reply to comment #1)
> Vectorizer needs to check signs when vectorizing conversions from
> unsigned int to float if int > float vector insn is used. For example:
> 

Should it be done in vectorizer or in backend?


-- 

hjl dot tools at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ubizjak at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40809


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug target/40809] wrong conversion from unsigned int to float
  2009-07-20 19:52 [Bug c++/40809] New: wrong conversion from unsigned int to float foldy at rmki dot kfki dot hu
  2009-07-20 21:13 ` [Bug target/40809] " hjl dot tools at gmail dot com
  2009-07-20 21:16 ` hjl dot tools at gmail dot com
@ 2009-07-20 22:47 ` ubizjak at gmail dot com
  2009-07-20 22:51 ` hjl dot tools at gmail dot com
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ubizjak at gmail dot com @ 2009-07-20 22:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from ubizjak at gmail dot com  2009-07-20 22:46 -------
PR 39943 ?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40809


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug target/40809] wrong conversion from unsigned int to float
  2009-07-20 19:52 [Bug c++/40809] New: wrong conversion from unsigned int to float foldy at rmki dot kfki dot hu
                   ` (2 preceding siblings ...)
  2009-07-20 22:47 ` ubizjak at gmail dot com
@ 2009-07-20 22:51 ` hjl dot tools at gmail dot com
  2009-07-20 23:12 ` ubizjak at gmail dot com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: hjl dot tools at gmail dot com @ 2009-07-20 22:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from hjl dot tools at gmail dot com  2009-07-20 22:51 -------
(In reply to comment #3)
> PR 39943 ?
> 

Yes, it is. Gcc 4.5.0 revision 149104 works fine. Should the fix
backported to 4.3/4.4 branches?


-- 

hjl dot tools at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|4.3.4 4.4.1 4.5.0           |4.3.4 4.4.1
      Known to work|                            |4.5.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40809


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug target/40809] wrong conversion from unsigned int to float
  2009-07-20 19:52 [Bug c++/40809] New: wrong conversion from unsigned int to float foldy at rmki dot kfki dot hu
                   ` (3 preceding siblings ...)
  2009-07-20 22:51 ` hjl dot tools at gmail dot com
@ 2009-07-20 23:12 ` ubizjak at gmail dot com
  2009-07-21  9:58 ` uros at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ubizjak at gmail dot com @ 2009-07-20 23:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from ubizjak at gmail dot com  2009-07-20 23:12 -------
(In reply to comment #4)
> (In reply to comment #3)
> > PR 39943 ?
> > 
> 
> Yes, it is. Gcc 4.5.0 revision 149104 works fine. Should the fix
> backported to 4.3/4.4 branches?

Yes, please reopen PR 39943 as a regression for 4.3 and 4.4.

As for comment #2:

The sequence from comment #1 should be implemented in a backend due to use of
cmpltps and andps. We should invent IX86_BUILTIN_CVTUDQ2PS that expands to the
sequence via ix86_build_const_vector.

(See for example recent IX86_BUILTIN_CPYSGNP? if you want to give a shot at the
implementation for 4.5.0.)

*** This bug has been marked as a duplicate of 39943 ***


-- 

ubizjak at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40809


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug target/40809] wrong conversion from unsigned int to float
  2009-07-20 19:52 [Bug c++/40809] New: wrong conversion from unsigned int to float foldy at rmki dot kfki dot hu
                   ` (4 preceding siblings ...)
  2009-07-20 23:12 ` ubizjak at gmail dot com
@ 2009-07-21  9:58 ` uros at gcc dot gnu dot org
  2009-07-21 10:01 ` ubizjak at gmail dot com
  2009-07-21 15:17 ` uros at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: uros at gcc dot gnu dot org @ 2009-07-21  9:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from uros at gcc dot gnu dot org  2009-07-21 09:57 -------
Subject: Bug 40809

Author: uros
Date: Tue Jul 21 09:57:46 2009
New Revision: 149851

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149851
Log:
        Backport from mainline:
        2009-04-29  Richard Guenther  <rguenther@suse.de>

        PR target/39943
        * config/i386/i386.c (ix86_vectorize_builtin_conversion): Only
        allow conversion to signed integers.

testsuite/ChangeLog:

        PR target/40809
        * gcc.target/i386/pr40809.c: New test.

        Backport from mainline:
        2009-04-29  Richard Guenther  <rguenther@suse.de>

        PR target/39943
        * lib/target-supports.exp (check_effective_target_vect_uintfloat_cvt):
        New.
        (check_effective_target_vect_floatuint_cvt): Likewise.
        * gcc.dg/vect/slp-10.c: Adjust.
        * gcc.dg/vect/slp-11.c: Adjust.
        * gcc.dg/vect/slp-12b.c: Adjust.
        * gcc.dg/vect/slp-33.c: Adjust.
        * gcc.c-torture/compile/pr39943.c: New testcase.


Added:
    branches/gcc-4_3-branch/gcc/testsuite/gcc.c-torture/compile/pr39943.c
    branches/gcc-4_3-branch/gcc/testsuite/gcc.target/i386/pr40809.c
Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/config/i386/i386.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_3-branch/gcc/testsuite/gcc.dg/vect/slp-10.c
    branches/gcc-4_3-branch/gcc/testsuite/gcc.dg/vect/slp-11.c
    branches/gcc-4_3-branch/gcc/testsuite/gcc.dg/vect/slp-12b.c
    branches/gcc-4_3-branch/gcc/testsuite/gcc.dg/vect/slp-33.c
    branches/gcc-4_3-branch/gcc/testsuite/lib/target-supports.exp


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40809


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug target/40809] wrong conversion from unsigned int to float
  2009-07-20 19:52 [Bug c++/40809] New: wrong conversion from unsigned int to float foldy at rmki dot kfki dot hu
                   ` (5 preceding siblings ...)
  2009-07-21  9:58 ` uros at gcc dot gnu dot org
@ 2009-07-21 10:01 ` ubizjak at gmail dot com
  2009-07-21 15:17 ` uros at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: ubizjak at gmail dot com @ 2009-07-21 10:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from ubizjak at gmail dot com  2009-07-21 10:00 -------
Subject: Bug 40811

Author: uros
Date: Tue Jul 21 07:22:51 2009
New Revision: 149847

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149847
Log:
        Backport from mainline:
        2009-04-29  Richard Guenther  <rguenther@suse.de>

        PR target/39943
        * config/i386/i386.c (ix86_vectorize_builtin_conversion): Only
        allow conversion to signed integers.

testsuite/ChangeLog:

        PR target/40809
        * gcc.target/i386/pr40809.c: New test.

        Backport from mainline:
        2009-04-29  Richard Guenther  <rguenther@suse.de>

        PR target/39943
        * lib/target-supports.exp (check_effective_target_vect_uintfloat_cvt):
        New.
        (check_effective_target_vect_floatuint_cvt): Likewise.
        * gcc.dg/vect/slp-10.c: Adjust.
        * gcc.dg/vect/slp-11.c: Adjust.
        * gcc.dg/vect/slp-12b.c: Adjust.
        * gcc.dg/vect/slp-33.c: Adjust.
        * gcc.c-torture/compile/pr39943.c: New testcase.


Added:
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/compile/pr39943.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.target/i386/pr40809.c
Modified:
    branches/gcc-4_4-branch/gcc/ChangeLog
    branches/gcc-4_4-branch/gcc/config/i386/i386.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/vect/slp-10.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/vect/slp-11.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/vect/slp-12b.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/vect/slp-33.c
    branches/gcc-4_4-branch/gcc/testsuite/lib/target-supports.exp


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40809


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug target/40809] wrong conversion from unsigned int to float
  2009-07-20 19:52 [Bug c++/40809] New: wrong conversion from unsigned int to float foldy at rmki dot kfki dot hu
                   ` (6 preceding siblings ...)
  2009-07-21 10:01 ` ubizjak at gmail dot com
@ 2009-07-21 15:17 ` uros at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: uros at gcc dot gnu dot org @ 2009-07-21 15:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from uros at gcc dot gnu dot org  2009-07-21 15:17 -------
Subject: Bug 40809

Author: uros
Date: Tue Jul 21 15:17:23 2009
New Revision: 149861

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149861
Log:
        PR target/40811
        * config/i386/sse.md (sse2_cvtudq2ps): New expander.
        (enum ix86_builtins): Add IX86_BUILTIN_CVTUDQ2PS.
        (builtin_description): Add __builtin_ia32_cvtudq2ps.
        (ix86_vectorize_builtin_conversion): Handle IX86_BUILTIN_CVTUDQ2PS.

testsuite/ChangeLog:

        PR target/40811
        * lib/target-supports.exp (check_effective_target_vect_uintfloat_cvt):
        Add i?86 and x86_64 targets.
        * gcc.target/i386/vectorize7.c: New test.

        PR target/40809
        * gcc.target/i386/pr40809.c: New test.


Added:
    trunk/gcc/testsuite/gcc.target/i386/pr40809.c
    trunk/gcc/testsuite/gcc.target/i386/vectorize7.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c
    trunk/gcc/config/i386/sse.md
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/lib/target-supports.exp


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40809


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-07-21 15:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-20 19:52 [Bug c++/40809] New: wrong conversion from unsigned int to float foldy at rmki dot kfki dot hu
2009-07-20 21:13 ` [Bug target/40809] " hjl dot tools at gmail dot com
2009-07-20 21:16 ` hjl dot tools at gmail dot com
2009-07-20 22:47 ` ubizjak at gmail dot com
2009-07-20 22:51 ` hjl dot tools at gmail dot com
2009-07-20 23:12 ` ubizjak at gmail dot com
2009-07-21  9:58 ` uros at gcc dot gnu dot org
2009-07-21 10:01 ` ubizjak at gmail dot com
2009-07-21 15:17 ` uros at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).