Bug 114189

Summary: Target implements obsolete vcond{,u,eq} expanders
Product: gcc Reporter: Richard Biener <rguenth>
Component: targetAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: normal CC: ams, chenglulu, ebotcazou, liuhongt, pinskia, rearnsha
Priority: P3 Keywords: internal-improvement
Version: 15.0   
Target Milestone: ---   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109955
Host: Target: sparc, mips, ia64, gcn, arm, aarch64,
Build: Known to work:
Known to fail: Last reconfirmed: 2024-06-17 00:00:00
Bug Depends on: 115519, 115683, 115490, 115517, 115659, 116041    
Bug Blocks:    
Attachments: patch to remove use of the legacy optabs

Description Richard Biener 2024-03-01 10:16:05 UTC
The listed targets implement any of vcond, vcondu or vcondeq expanders where
the modern way of exposing vector conditional instructions is using
mask generating vec_cmp{,u,eq} and vcond_mask expanders.

vcond, vcondu and vcondeq optabs will be retired in the future.
Comment 1 Richard Biener 2024-03-01 10:23:55 UTC
The following shows them all:

grep 'vcond[<eu]' gcc/config/*/*.md

ia64 and sparc are the only targets that do not implement any vec_cmp{,u,eq}
pattern.

mips, sparc and ia64 do not implement any vcond_mask pattern.
Comment 2 Richard Biener 2024-06-14 10:24:45 UTC
Created attachment 58426 [details]
patch to remove use of the legacy optabs
Comment 4 Richard Biener 2024-06-17 05:48:11 UTC
aarch64 reports just

FAIL: gcc.target/aarch64/if-compare_2.c check-function-bodies bar1
FAIL: gcc.target/aarch64/if-compare_2.c check-function-bodies bar2
Comment 5 Andrew Pinski 2024-06-17 15:48:52 UTC
.
Comment 6 GCC Commits 2024-06-26 03:13:25 UTC
The master branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>:

https://gcc.gnu.org/g:aac00d09859cc5934bd0f7493d537b8430337773

commit r15-1638-gaac00d09859cc5934bd0f7493d537b8430337773
Author: liuhongt <hongtao.liu@intel.com>
Date:   Thu Jun 20 12:41:13 2024 +0800

    Optimize a < 0 ? -1 : 0 to (signed)a >> 31.
    
    Try to optimize x < 0 ? -1 : 0 into (signed) x >> 31
    and x < 0 ? 1 : 0 into (unsigned) x >> 31.
    
    Move the optimization did in ix86_expand_int_vcond to match.pd
    
    gcc/ChangeLog:
    
            PR target/114189
            * match.pd: Simplify a < 0 ? -1 : 0 to (signed) >> 31 and a <
            0 ? 1 : 0 to (unsigned) a >> 31 for vector integer type.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/i386/avx2-pr115517.c: New test.
            * gcc.target/i386/avx512-pr115517.c: New test.
            * g++.target/i386/avx2-pr115517.C: New test.
            * g++.target/i386/avx512-pr115517.C: New test.
            * g++.dg/tree-ssa/pr88152-1.C: Adjust testcase.
Comment 7 Richard Biener 2024-07-12 07:11:17 UTC
powerpc has removed the obsolete expanders.
Comment 8 Eric Botcazou 2024-07-12 08:51:19 UTC
There are 2 entries for vcond_mask in the internal manual:

'vcond_mask_MN'
     Similar to 'vcondMN' but operand 3 holds a pre-computed result of
     vector comparison.

'vcond_mask_MN'
     Set each element of operand 0 to the corresponding element of
     operand 2 or operand 3.  Choose operand 2 if both the element index
     is less than operand 4 plus operand 5 and the corresponding element
     of operand 1 is nonzero:

          for (i = 0; i < GET_MODE_NUNITS (M); i++)
            op0[i] = i < op4 + op5 && op1[i] ? op2[i] : op3[i];

     Operands 0, 2 and 3 have mode M.  Operand 1 has mode N.  Operands 4
     and 5 have a target-dependent scalar integer mode
Comment 9 rguenther@suse.de 2024-07-12 12:45:33 UTC
On Fri, 12 Jul 2024, ebotcazou at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114189
> 
> Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |ebotcazou at gcc dot gnu.org
> 
> --- Comment #8 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
> There are 2 entries for vcond_mask in the internal manual:
> 
> 'vcond_mask_MN'
>      Similar to 'vcondMN' but operand 3 holds a pre-computed result of
>      vector comparison.
> 
> 'vcond_mask_MN'

This should be vcond_mask_len_MN I think.

>      Set each element of operand 0 to the corresponding element of
>      operand 2 or operand 3.  Choose operand 2 if both the element index
>      is less than operand 4 plus operand 5 and the corresponding element
>      of operand 1 is nonzero:
> 
>           for (i = 0; i < GET_MODE_NUNITS (M); i++)
>             op0[i] = i < op4 + op5 && op1[i] ? op2[i] : op3[i];
> 
>      Operands 0, 2 and 3 have mode M.  Operand 1 has mode N.  Operands 4
>      and 5 have a target-dependent scalar integer mode
Comment 10 GCC Commits 2024-07-16 08:43:47 UTC
The master branch has been updated by Stefan Schulze Frielinghaus <stefansf@gcc.gnu.org>:

https://gcc.gnu.org/g:75c0bf997d2808561451e62aa6b7ae7c8e32b9e9

commit r15-2058-g75c0bf997d2808561451e62aa6b7ae7c8e32b9e9
Author: Stefan Schulze Frielinghaus <stefansf@gcc.gnu.org>
Date:   Tue Jul 16 10:41:52 2024 +0200

    s390: Drop vcond{,u} expanders
    
    Optabs vcond{,u} will be removed for GCC 15.  Since regtest shows no
    fallout, dropping the expanders, now.
    
    gcc/ChangeLog:
    
            PR target/114189
            * config/s390/vector.md (V_HW2): Remove.
            (vcond<V_HW:mode><V_HW2:mode>): Remove.
            (vcondu<V_HW:mode><V_HW2:mode>): Remove.
Comment 11 Andrew Pinski 2024-07-22 18:17:28 UTC
(In reply to Richard Biener from comment #4)
> aarch64 reports just
> 
> FAIL: gcc.target/aarch64/if-compare_2.c check-function-bodies bar1
> FAIL: gcc.target/aarch64/if-compare_2.c check-function-bodies bar2

I think these 2 are now fixed after the fixes for PR 115659.
There is also missing andc/iorc patterns. 
Which I am testing a change for them. I am doing it as part of using andc/iorc for scalars change due to be able to use them for vectors too.
Comment 12 Andrew Pinski 2024-07-22 21:06:16 UTC
(In reply to Andrew Pinski from comment #11)
> (In reply to Richard Biener from comment #4)
> > aarch64 reports just
> > 
> > FAIL: gcc.target/aarch64/if-compare_2.c check-function-bodies bar1
> > FAIL: gcc.target/aarch64/if-compare_2.c check-function-bodies bar2
> 
> I think these 2 are now fixed after the fixes for PR 115659.
> There is also missing andc/iorc patterns. 
> Which I am testing a change for them. I am doing it as part of using
> andc/iorc for scalars change due to be able to use them for vectors too.

Actually I take that back, these are no longer vectorized. 
Let me file that as a seperate issue.
Comment 13 Richard Biener 2024-08-02 09:36:25 UTC
The i386 backend is also clear of vcond{,u,eq} patterns, there's some XFAILed fallout when just SSE is available (PR115683).
Comment 14 Richard Biener 2024-08-02 09:41:28 UTC
CCing maintainers for loongarch, arm/aarch64 and gcn.
Comment 15 GCC Commits 2024-08-12 01:33:43 UTC
The master branch has been updated by LuluCheng <chenglulu@gcc.gnu.org>:

https://gcc.gnu.org/g:0498f8bda1d08b8ed8100d759917792baf2da15f

commit r15-2878-g0498f8bda1d08b8ed8100d759917792baf2da15f
Author: Lulu Cheng <chenglulu@loongson.cn>
Date:   Thu Aug 8 10:39:54 2024 +0800

    LoongArch: Drop vcond{,u} expanders.
    
    Optabs vcond{,u} will be removed for GCC 15.  Since regtest shows no
    fallout, dropping the expanders, now.
    
    gcc/ChangeLog:
    
            PR target/114189
            * config/loongarch/lasx.md (vcondu<LASX:mode><ILASX:mode>): Delete.
            (vcond<LASX:mode><LASX_2:mode>): Likewise.
            * config/loongarch/lsx.md (vcondu<LSX:mode><ILSX:mode>): Likewise.
            (vcond<LSX:mode><LSX_2:mode>): Likewise.