public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/62191] New: extra shift generated for vector integer division by constant 2
@ 2014-08-19 18:24 spatel at rotateright dot com
  2020-09-03 20:50 ` [Bug target/62191] " gabravier at gmail dot com
  0 siblings, 1 reply; 2+ messages in thread
From: spatel at rotateright dot com @ 2014-08-19 18:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62191

            Bug ID: 62191
           Summary: extra shift generated for vector integer division by
                    constant 2
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: spatel at rotateright dot com

Using gcc 4.9:

$ cat sdiv.c
typedef int vecint __attribute__((vector_size(16))); 
vecint f(vecint x) { 
    return x/2;
} 

$ gcc -O2 sdiv.c -S -o  -
...
    movdqa    %xmm0, %xmm1
    psrad    $31, %xmm1    <--- splat the sign bit
    psrld    $31, %xmm1    <--- then shift sign bit down to LSB
    paddd    %xmm1, %xmm0  <--- add sign bit to quotient
    psrad    $1, %xmm0     <--- div via alg shift right
    ret

--------------------------------------------------------------

I don't think the first shift right algebraic is necessary. We splat the sign
bit and then shift that right logically, so the upper bits are all zero'd
anyway. 

This is a special case for signed integer division by 2. You need that first
'psrad' for any other power of 2 because the subsequent logical shift would not
also be a shift of 31.


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

* [Bug target/62191] extra shift generated for vector integer division by constant 2
  2014-08-19 18:24 [Bug target/62191] New: extra shift generated for vector integer division by constant 2 spatel at rotateright dot com
@ 2020-09-03 20:50 ` gabravier at gmail dot com
  0 siblings, 0 replies; 2+ messages in thread
From: gabravier at gmail dot com @ 2020-09-03 20:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62191

Gabriel Ravier <gabravier at gmail dot com> changed:

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

--- Comment #2 from Gabriel Ravier <gabravier at gmail dot com> ---
The first arithmetic shift doesn't seem to be emitted anymore, so presumably
this should be fixed now. I can't mark it as fixed myself, but I can confirm it
seems to be so.

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

end of thread, other threads:[~2020-09-03 20:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-19 18:24 [Bug target/62191] New: extra shift generated for vector integer division by constant 2 spatel at rotateright dot com
2020-09-03 20:50 ` [Bug target/62191] " gabravier at gmail dot com

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).