public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/114544] New: [x86] stv should transform (subreg DI (V1TI) 8) as (vec_select:DI (V2DI) (const_int 1))
@ 2024-04-01  7:31 liuhongt at gcc dot gnu.org
  2024-04-01  7:44 ` [Bug target/114544] " liuhongt at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: liuhongt at gcc dot gnu.org @ 2024-04-01  7:31 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114544
           Summary: [x86] stv should transform (subreg DI (V1TI) 8) as
                    (vec_select:DI (V2DI) (const_int 1))
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: liuhongt at gcc dot gnu.org
  Target Milestone: ---

typedef __uint128_t v128_t __attribute__((vector_size(16)));

v128_t c;


v128_t
foo1 (v128_t *a, v128_t *b)
{
    c =  (*a >> 1 & *b) / (__extension__(v128_t){(__int128_t)0x3 << 120
    | (__int128_t)0x3 << 112
    | (__int128_t)0x3 << 104
    | (__int128_t)0x3 << 96
    | (__int128_t)0x3 << 88
    | (__int128_t)0x3 << 80
    | (__int128_t)0x3 << 72
    | (__int128_t)0x3 << 64
    | (__int128_t)0x3 << 56
    | (__int128_t)0x3 << 48
    | (__int128_t)0x3 << 40
    | (__int128_t)0x3 << 32
    | (__int128_t)0x3 << 24
    | (__int128_t)0x3 << 16
    | (__int128_t)0x3 << 8
    | (__int128_t)0x3 << 0});
}


stv generates

(insn 32 11 35 2 (set (reg:DI 124 [ _4 ])
        (subreg:DI (reg:V1TI 111 [ _4 ]) 0)) "/app/example.c":28:25 84
{*movdi_internal}
     (nil))
(insn 35 32 12 2 (set (reg:DI 127 [+8 ])
        (subreg:DI (reg:V1TI 111 [ _4 ]) 8)) "/app/example.c":28:25 84
{*movdi_internal}
     (expr_list:REG_DEAD (reg:V1TI 111 [ _4 ])

(subreg:DI (reg:V1TI 111 [ _4 ]) 8) makes reload spills.


foo1:
        movabsq $217020518514230019, %rdx # 57      [c=1 l=10] 
*movdi_internal/4
        subq    $24, %rsp       # 59  [c=4 l=4] 
pro_epilogue_adjust_stack_add_di/0
        vmovdqa (%rdi), %xmm0     # 8       [c=9 l=4]  movv1ti_internal/3
        movq    %rdx, %rcx      # 58        [c=4 l=3]  *movdi_internal/3
        vpsrldq $8, %xmm0, %xmm1  # 42        [c=4 l=5]  sse2_lshrv1ti3/1
        vpsrlq  $1, %xmm0, %xmm0    # 45    [c=4 l=5]  lshrv2di3/1
        vpsllq  $63, %xmm1, %xmm1   # 46  [c=4 l=5]  ashlv2di3/1
        vpor    %xmm1, %xmm0, %xmm0     # 47      [c=4 l=4]  *iorv2di3/1
        vpand   (%rsi), %xmm0, %xmm2  # 10        [c=13 l=4]  andv1ti3/1
        vmovdqa %xmm2, (%rsp)     # 52      [c=4 l=5]  movv1ti_internal/4
        movq    (%rsp), %rdi    # 56    [c=5 l=4]  *movdi_internal/3
        movq    8(%rsp), %rsi   # 35  [c=9 l=5]  *movdi_internal/3
        call    __udivti3       # 19  [c=13 l=5]  *call_value
        vmovq   %rax, %xmm3   # 53  [c=4 l=5]  *movdi_internal/20
        vpinsrq $1, %rdx, %xmm3, %xmm0    # 23    [c=4 l=6]  vec_concatv2di/2
        vmovdqa %xmm0, c(%rip)    # 25    [c=4 l=8]  movv1ti_internal/4
        addq    $24, %rsp       # 62  [c=4 l=4] 
pro_epilogue_adjust_stack_add_di/0
        ret       # 63        [c=0 l=1]  simple_return_internal

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

* [Bug target/114544] [x86] stv should transform (subreg DI (V1TI) 8) as (vec_select:DI (V2DI) (const_int 1))
  2024-04-01  7:31 [Bug target/114544] New: [x86] stv should transform (subreg DI (V1TI) 8) as (vec_select:DI (V2DI) (const_int 1)) liuhongt at gcc dot gnu.org
@ 2024-04-01  7:44 ` liuhongt at gcc dot gnu.org
  2024-04-01  8:10 ` liuhongt at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: liuhongt at gcc dot gnu.org @ 2024-04-01  7:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Hongtao Liu <liuhongt at gcc dot gnu.org> ---
20590;; Turn SImode or DImode extraction from arbitrary SSE/AVX/AVX512F
20591;; vector modes into vec_extract*.
20592(define_split
20593  [(set (match_operand:SWI48x 0 "nonimmediate_operand")
20594        (subreg:SWI48x (match_operand 1 "register_operand") 0))]
20595  "can_create_pseudo_p ()
20596   && REG_P (operands[1])
20597   && VECTOR_MODE_P (GET_MODE (operands[1]))
20598   && ((TARGET_SSE && GET_MODE_SIZE (GET_MODE (operands[1])) == 16)
20599       || (TARGET_AVX && GET_MODE_SIZE (GET_MODE (operands[1])) == 32)
20600       || (TARGET_AVX512F && TARGET_EVEX512
20601           && GET_MODE_SIZE (GET_MODE (operands[1])) == 64))
20602   && (<MODE>mode == SImode || TARGET_64BIT || MEM_P (operands[0]))"
20603  [(set (match_dup 0) (vec_select:SWI48x (match_dup 1)
20604                                         (parallel [(const_int 0)])))]
20605{
20606  rtx tmp;

We need to do something similar.

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

* [Bug target/114544] [x86] stv should transform (subreg DI (V1TI) 8) as (vec_select:DI (V2DI) (const_int 1))
  2024-04-01  7:31 [Bug target/114544] New: [x86] stv should transform (subreg DI (V1TI) 8) as (vec_select:DI (V2DI) (const_int 1)) liuhongt at gcc dot gnu.org
  2024-04-01  7:44 ` [Bug target/114544] " liuhongt at gcc dot gnu.org
@ 2024-04-01  8:10 ` liuhongt at gcc dot gnu.org
  2024-04-07 22:06 ` roger at nextmovesoftware dot com
  2024-04-08  2:54 ` liuhongt at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: liuhongt at gcc dot gnu.org @ 2024-04-01  8:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Hongtao Liu <liuhongt at gcc dot gnu.org> ---
Also for 
void
foo2 (v128_t* a, v128_t* b)
{
   c = (*a & *b)+ *b;
}

(insn 9 8 10 2 (set (reg:V1TI 108 [ _3 ])
        (and:V1TI (reg:V1TI 99 [ _2 ])
            (mem:V1TI (reg:DI 113) [1 *a_6(D)+0 S16 A128])))
"/app/example.c":49:12 7100 {andv1ti3}
     (expr_list:REG_DEAD (reg:DI 113)
        (nil)))
(insn 10 9 13 2 (parallel [
            (set (reg:TI 109 [ _11 ])
                (plus:TI (subreg:TI (reg:V1TI 108 [ _3 ]) 0)
                    (subreg:TI (reg:V1TI 99 [ _2 ]) 0)))
            (clobber (reg:CC 17 flags))
        ]) "/app/example.c":49:17 256 {*addti3_doubleword}
     (expr_list:REG_DEAD (reg:V1TI 108 [ _3 ])
        (expr_list:REG_DEAD (reg:V1TI 99 [ _2 ])
            (expr_list:REG_UNUSED (reg:CC 17 flags)
                (nil)))))

Since V1TImode can only be accocated as SSE_REGS, reload use stack for
(subreg:TI (reg:V1TI 108 [ _3 ]) 0) since the latter only support GENERAL_REGS.

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

* [Bug target/114544] [x86] stv should transform (subreg DI (V1TI) 8) as (vec_select:DI (V2DI) (const_int 1))
  2024-04-01  7:31 [Bug target/114544] New: [x86] stv should transform (subreg DI (V1TI) 8) as (vec_select:DI (V2DI) (const_int 1)) liuhongt at gcc dot gnu.org
  2024-04-01  7:44 ` [Bug target/114544] " liuhongt at gcc dot gnu.org
  2024-04-01  8:10 ` liuhongt at gcc dot gnu.org
@ 2024-04-07 22:06 ` roger at nextmovesoftware dot com
  2024-04-08  2:54 ` liuhongt at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: roger at nextmovesoftware dot com @ 2024-04-07 22:06 UTC (permalink / raw)
  To: gcc-bugs

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

Roger Sayle <roger at nextmovesoftware dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-04-07
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
                 CC|                            |roger at nextmovesoftware dot com

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

* [Bug target/114544] [x86] stv should transform (subreg DI (V1TI) 8) as (vec_select:DI (V2DI) (const_int 1))
  2024-04-01  7:31 [Bug target/114544] New: [x86] stv should transform (subreg DI (V1TI) 8) as (vec_select:DI (V2DI) (const_int 1)) liuhongt at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-04-07 22:06 ` roger at nextmovesoftware dot com
@ 2024-04-08  2:54 ` liuhongt at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: liuhongt at gcc dot gnu.org @ 2024-04-08  2:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Hongtao Liu <liuhongt at gcc dot gnu.org> ---
0000000000000000 <__umodti3>:
...

 37  58:   66 48 0f 6e c7          movq   %rdi,%xmm0
 38  5d:   66 48 0f 6e d6          movq   %rsi,%xmm2
 39  62:   66 0f 6c c2             punpcklqdq %xmm2,%xmm0
 40  66:   0f 29 44 24 f0          movaps %xmm0,-0x10(%rsp)
 41  6b:   48 8b 44 24 f0          mov    -0x10(%rsp),%rax
 42  70:   48 8b 54 24 f8          mov    -0x8(%rsp),%rdx
 43  75:   5b                      pop    %rbx
 44  76:   c3                      ret

Look like the misoptimization is also in __umodti3.

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

end of thread, other threads:[~2024-04-08  2:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-01  7:31 [Bug target/114544] New: [x86] stv should transform (subreg DI (V1TI) 8) as (vec_select:DI (V2DI) (const_int 1)) liuhongt at gcc dot gnu.org
2024-04-01  7:44 ` [Bug target/114544] " liuhongt at gcc dot gnu.org
2024-04-01  8:10 ` liuhongt at gcc dot gnu.org
2024-04-07 22:06 ` roger at nextmovesoftware dot com
2024-04-08  2:54 ` liuhongt at gcc dot gnu.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).