Re: [PATCH] Adjust memory_move_cost for MASK_REGS when MODE_SIZE > 8.

2023-03-30 Thread Uros Bizjak via Gcc-patches
On Fri, Mar 31, 2023 at 7:11 AM liuhongt  wrote:
>
> RA sometimes will use lowest the cost of the mode with all different 
> regclasses
> w/o check if it's hard_regno_mode_ok.
> It's impossible to put modes whose size > 8 into MASK_REGS, ajdust the cost to
> avoid potential performance issue.

I was going to ask to open a PR in order to fix RA instead of the
proposed workaround, but the patch just prevents a theoretical issue
and follows the established practice with other regclasses. Perhaps
these workarounds are not needed with the current RA, but this is a
tangential issue which should be fixed for all regclasses.

> Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
> Ok for trunk?

OK.

Thanks,
Uros.

>
> gcc/ChangeLog:
>
> * config/i386/i386.cc (inline_memory_move_cost): Return 100
> for MASK_REGS when MODE_SIZE > 8.
> ---
>  gcc/config/i386/i386.cc | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> index 2cc8e9548a9..2581b800a06 100644
> --- a/gcc/config/i386/i386.cc
> +++ b/gcc/config/i386/i386.cc
> @@ -19847,9 +19847,12 @@ inline_memory_move_cost (machine_mode mode, enum 
> reg_class regclass, int in)
>   index = 1;
>   break;
> /* DImode loads and stores assumed to cost the same as SImode.  */
> -   default:
> +   case 4:
> +   case 8:
>   index = 2;
>   break;
> +   default:
> + return 100;
> }
>
>if (in == 2)
> --
> 2.39.1.388.g2fc9e9ca3c
>


[r13-6945 Regression] FAIL: 23_containers/vector/bool/allocator/copy.cc (test for excess errors) on Linux/x86_64

2023-03-30 Thread haochen.jiang via Gcc-patches
On Linux/x86_64,

429a7a88438cc80e7c58d9f63d44838089899b12 is the first bad commit
commit 429a7a88438cc80e7c58d9f63d44838089899b12
Author: Andrew MacLeod 
Date:   Tue Mar 28 12:16:34 2023 -0400

Add recursive GORI recompuations with a depth limit.

caused

FAIL: 23_containers/vector/bool/allocator/copy.cc (test for excess errors)
FAIL: g++.dg/warn/Wstringop-overflow-4.C  -std=gnu++98 pr106120 (test for bogus 
messages, line 144)

with GCC configured with

../../gcc/configure 
--prefix=/export/users/haochenj/src/gcc-bisect/master/master/r13-6945/usr 
--enable-clocale=gnu --with-system-zlib --with-demangler-in-ld 
--with-fpmath=sse --enable-languages=c,c++,fortran --enable-cet --without-isl 
--enable-libmpx x86_64-linux --disable-bootstrap

To reproduce:

$ cd {build_dir}/x86_64-linux/libstdc++-v3/testsuite && make check 
RUNTESTFLAGS="conformance.exp=23_containers/vector/bool/allocator/copy.cc 
--target_board='unix{-m64}'"
$ cd {build_dir}/x86_64-linux/libstdc++-v3/testsuite && make check 
RUNTESTFLAGS="conformance.exp=23_containers/vector/bool/allocator/copy.cc 
--target_board='unix{-m64\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="dg.exp=g++.dg/warn/Wstringop-overflow-4.C 
--target_board='unix{-m64}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="dg.exp=g++.dg/warn/Wstringop-overflow-4.C 
--target_board='unix{-m64\ -march=cascadelake}'"

(Please do not reply to this email, for question about this report, contact me 
at haochen dot jiang at intel.com)


[GCC14 QUEUE PATCH] RISC-V: Support chunk = 128bit for 'V' Extension

2023-03-30 Thread juzhe . zhong
From: Juzhe-Zhong 

Currently, we only support chunk = 32 bit for zve32*
and chunk = 64 for zve64*.

According to RVV ISA chapter 18.3 V: Vector Extension for Application Processors
We should also support chunk = 128 bit for Full 'V' extension.

Also, currently, LMUL = 1 for INT64 is VNx1DImode which blocks interleaved 
vector
auto-vectorization.

After this patch, this issue will be addressed since LMUL = 1 for INT64 is 
VNx2DImode
then, we can enable interleaved vector auto-vectorization for LMUL = 1 of INT64.

gcc/ChangeLog:

* config/riscv/riscv-modes.def (FLOAT_MODE): Add chunk 128 bit modes.
(VECTOR_BOOL_MODE): Ditto.
(ADJUST_NUNITS): Ditto.
(ADJUST_ALIGNMENT): Ditto.
(ADJUST_BYTESIZE): Ditto.
(ADJUST_PRECISION): Ditto.
(RVV_MODES): Ditto.
* config/riscv/riscv-v.cc (ENTRY): Ditto.
(get_vlmul): Ditto.
(get_ratio): Ditto.
* config/riscv/riscv-vector-builtins.cc (DEF_RVV_TYPE): Ditto.
* config/riscv/riscv-vector-builtins.def (DEF_RVV_TYPE): Ditto.
(vbool64_t): Ditto.
(vbool32_t): Ditto.
(vbool16_t): Ditto.
(vbool8_t): Ditto.
(vbool4_t): Ditto.
(vbool2_t): Ditto.
(vbool1_t): Ditto.
(vint8mf8_t): Ditto.
(vuint8mf8_t): Ditto.
(vint8mf4_t): Ditto.
(vuint8mf4_t): Ditto.
(vint8mf2_t): Ditto.
(vuint8mf2_t): Ditto.
(vint8m1_t): Ditto.
(vuint8m1_t): Ditto.
(vint8m2_t): Ditto.
(vuint8m2_t): Ditto.
(vint8m4_t): Ditto.
(vuint8m4_t): Ditto.
(vint8m8_t): Ditto.
(vuint8m8_t): Ditto.
(vint16mf4_t): Ditto.
(vuint16mf4_t): Ditto.
(vint16mf2_t): Ditto.
(vuint16mf2_t): Ditto.
(vint16m1_t): Ditto.
(vuint16m1_t): Ditto.
(vint16m2_t): Ditto.
(vuint16m2_t): Ditto.
(vint16m4_t): Ditto.
(vuint16m4_t): Ditto.
(vint16m8_t): Ditto.
(vuint16m8_t): Ditto.
(vint32mf2_t): Ditto.
(vuint32mf2_t): Ditto.
(vint32m1_t): Ditto.
(vuint32m1_t): Ditto.
(vint32m2_t): Ditto.
(vuint32m2_t): Ditto.
(vint32m4_t): Ditto.
(vuint32m4_t): Ditto.
(vint32m8_t): Ditto.
(vuint32m8_t): Ditto.
(vint64m1_t): Ditto.
(vuint64m1_t): Ditto.
(vint64m2_t): Ditto.
(vuint64m2_t): Ditto.
(vint64m4_t): Ditto.
(vuint64m4_t): Ditto.
(vint64m8_t): Ditto.
(vuint64m8_t): Ditto.
(vfloat32mf2_t): Ditto.
(vfloat32m1_t): Ditto.
(vfloat32m2_t): Ditto.
(vfloat32m4_t): Ditto.
(vfloat32m8_t): Ditto.
(vfloat64m1_t): Ditto.
(vfloat64m2_t): Ditto.
(vfloat64m4_t): Ditto.
(vfloat64m8_t): Ditto.
* config/riscv/riscv-vector-switch.def (ENTRY): Ditto.
* config/riscv/riscv.cc (riscv_legitimize_poly_move): Ditto.
(riscv_convert_vector_bits): Ditto.
* config/riscv/riscv.h (UNITS_PER_FP_REG): Ditto.
* config/riscv/riscv.md: Ditto.
* config/riscv/vector-iterators.md: Ditto.
* config/riscv/vector.md 
(@pred_indexed_store): Ditto.
(@pred_indexed_store): Ditto.
(@pred_indexed_store): Ditto.
(@pred_indexed_store): Ditto.
(@pred_indexed_store): Ditto.
(@pred_reduc_): Ditto.
(@pred_widen_reduc_plus): Ditto.
(@pred_reduc_plus): Ditto.
(@pred_widen_reduc_plus): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/pr108185-4.c: Adapt test.
* gcc.target/riscv/rvv/base/spill-1.c: Adapt test.
* gcc.target/riscv/rvv/base/spill-11.c: Adapt test.
* gcc.target/riscv/rvv/base/spill-2.c: Adapt test.
* gcc.target/riscv/rvv/base/spill-3.c: Adapt test.
* gcc.target/riscv/rvv/base/spill-5.c: Adapt test.
* gcc.target/riscv/rvv/base/spill-9.c: Adapt test.

---
 gcc/config/riscv/riscv-modes.def  |  76 ++-
 gcc/config/riscv/riscv-v.cc   |  17 +-
 gcc/config/riscv/riscv-vector-builtins.cc |  15 +-
 gcc/config/riscv/riscv-vector-builtins.def| 171 +++---
 gcc/config/riscv/riscv-vector-switch.def  | 148 +++--
 gcc/config/riscv/riscv.cc |  12 +-
 gcc/config/riscv/riscv.h  |   3 +-
 gcc/config/riscv/riscv.md |  14 +-
 gcc/config/riscv/vector-iterators.md  | 577 +++---
 gcc/config/riscv/vector.md| 184 +-
 .../gcc.target/riscv/rvv/base/pr108185-4.c|   2 +-
 .../gcc.target/riscv/rvv/base/spill-1.c   |   2 +-
 .../gcc.target/riscv/rvv/base/spill-11.c  |   2 +-
 .../gcc.target/riscv/rvv/base/spill-2.c   |   2 +-
 .../gcc.target/riscv/rvv/base/spill-3.c   |   2 +-
 .../gcc.target/riscv/rvv/base/spill-5.c   |   2 +-
 .../gcc.target/riscv/rvv/base/spill-9.c   |   2 +-
 17 files changed, 791 insertions(+), 440 

[PATCH] Adjust memory_move_cost for MASK_REGS when MODE_SIZE > 8.

2023-03-30 Thread liuhongt via Gcc-patches
RA sometimes will use lowest the cost of the mode with all different regclasses
w/o check if it's hard_regno_mode_ok.
It's impossible to put modes whose size > 8 into MASK_REGS, ajdust the cost to
avoid potential performance issue.

Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
Ok for trunk?

gcc/ChangeLog:

* config/i386/i386.cc (inline_memory_move_cost): Return 100
for MASK_REGS when MODE_SIZE > 8.
---
 gcc/config/i386/i386.cc | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 2cc8e9548a9..2581b800a06 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -19847,9 +19847,12 @@ inline_memory_move_cost (machine_mode mode, enum 
reg_class regclass, int in)
  index = 1;
  break;
/* DImode loads and stores assumed to cost the same as SImode.  */
-   default:
+   case 4:
+   case 8:
  index = 2;
  break;
+   default:
+ return 100;
}
 
   if (in == 2)
-- 
2.39.1.388.g2fc9e9ca3c



Re: [Patch] c-c++-common/Warray-bounds.c: fix excess warnings on LLP64

2023-03-30 Thread Jonathan Yong via Gcc-patches

On 3/31/23 00:09, Mike Stump wrote:

On Feb 27, 2023, at 2:29 AM, Jonathan Yong via Gcc-patches 
 wrote:


Attached patch OK?


Ok.


* c-c++-common/Warray-bounds.c: Fix excess warnings on

LLP64.<0001-c-c-common-Warray-bounds.c-fix-excess-warnings-on-LL.patch>




Thanks for reviewing, pushed to master branch.



Re: [PATCH v4] rs6000: Fix incorrect RTL for Power LE when removing the UNSPECS [PR106069]

2023-03-30 Thread Xionghu Luo via Gcc-patches

Thanks,

On 2023/3/31 03:30, Segher Boessenkool wrote:

Hi!

On Fri, Feb 10, 2023 at 10:59:52AM +0800, Xionghu Luo via Gcc-patches wrote:

The native RTL expression for vec_mrghw should be same for BE and LE as
they are register and endian-independent.


This isn't so obvious at all.  All elements of these constructs are
very much not endian-independent, because of very unfortunate choices
in the meaning of some RTL constructs.  It is possible all things in
this negate all other things, but please show that then.


  So both BE and LE need
generate exactly same RTL with index [0 4 1 5] when expanding vec_mrghw
with vec_select and vec_concat.

(set (reg:V4SI 141) (vec_select:V4SI (vec_concat:V8SI
   (subreg:V4SI (reg:V16QI 139) 0)
   (subreg:V4SI (reg:V16QI 140) 0))
   [const_int 0 4 1 5]))


With BE, if the source vecs are ABCD and EFGH, the vec_concat gives
ABCDEFGH, and the vec_select than gives AEBF.

What happens for LE?


on LE, the sources looks like DCBA and HGFE, vec_concat gives HGFEACBA 
with index reversed [7 6 5 4 3 2 1 0], so it also chooses FBEA like BE.



Take the case as example on P8LE:

test.c

__attribute__ ((__noinline__))
vector int bar (vector int a, vector int b)
{
  return vec_vmrghw (a, b);
}

int main ()
{

  vector int a = {0xa1345678, 0xa2345678,0xa3345678, 0xa4345678};
  vector int b = {0xb1345678, 0xb2345678,0xb3345678, 0xb4345678};
  vector int c = bar (a, b);
  printf("%x,%x,%x,%x\n", c[0], c[1], c[2], c[3]);
  return c[0];
}


.expand:

_3 = VEC_PERM_EXPR ;

(insn 7 4 8 2 (set (reg:V16QI 122)
(subreg:V16QI (reg/v:V4SI 118 [ a ]) 0)) "test.c":15:10 -1
 (nil))
(insn 8 7 9 2 (set (reg:V16QI 123)
(subreg:V16QI (reg/v:V4SI 119 [ b ]) 0)) "test.c":15:10 -1
 (nil))
(insn 9 8 10 2 (set (reg:V4SI 124)
(vec_select:V4SI (vec_concat:V8SI (subreg:V4SI (reg:V16QI 122) 0)
(subreg:V4SI (reg:V16QI 123) 0))
(parallel [
(const_int 0 [0])
(const_int 4 [0x4])
(const_int 1 [0x1])
(const_int 5 [0x5])
]))) "test.c":15:10 -1
 (nil))


And .vregs to .final:

(insn 15 9 16 (set (reg/i:V4SI 66 %v2)
(vec_select:V4SI (vec_concat:V8SI (reg:V4SI 66 %v2 [125])
(reg:V4SI 67 %v3 [126]))
(parallel [
(const_int 0 [0])
(const_int 4 [0x4])
(const_int 1 [0x1])
(const_int 5 [0x5])
]))) "test.c":16:1 1825 {altivec_vmrglw_direct_v4si_le}
 (expr_list:REG_DEAD (reg:V4SI 67 %v3 [126])
(nil)))


As altivec_vmrglw_direct_v4si_le is defined as with this patch:


(define_insn "altivec_vmrglw_direct__le"
  [(set (match_operand:VSX_W 0 "register_operand" "=wa,v")
(vec_select:VSX_W
  (vec_concat:
(match_operand:VSX_W 2 "register_operand" "wa,v")
(match_operand:VSX_W 1 "register_operand" "wa,v"))
  (parallel [(const_int 0) (const_int 4)
 (const_int 1) (const_int 5)])))]
  "TARGET_ALTIVEC && !BYTES_BIG_ENDIAN"
  "@
   xxmrglw %x0,%x1,%x2
   vmrglw %0,%1,%2"
  [(set_attr "type" "vecperm")])


ASM:

bar:
.LFB11:
.cfi_startproc
xxmrglw 34,35,34
blr


./test
a1345678,b1345678,a2345678,b2345678

Exactly matches [a1 b1 a2 b2].  Does this look reasonable?


BR,
Xionghu



Re: [Patch] c-c++-common/Warray-bounds.c: fix excess warnings on LLP64

2023-03-30 Thread Mike Stump via Gcc-patches
On Feb 27, 2023, at 2:29 AM, Jonathan Yong via Gcc-patches 
 wrote:
> 
> Attached patch OK?

Ok.

>* c-c++-common/Warray-bounds.c: Fix excess warnings on
>
> LLP64.<0001-c-c-common-Warray-bounds.c-fix-excess-warnings-on-LL.patch>



Re: [PATCH] rtl-optimization: ppc backend generates unnecessary signed extension.

2023-03-30 Thread Hans-Peter Nilsson
On Fri, 24 Mar 2023, Peter Bergner via Gcc-patches wrote:

> On 3/23/23 6:12 PM, Jeff Law via Gcc-patches wrote:
>  Is there a reason why REE cannot see that our (reg:QI 4) is a param 
>  register
>  and thus due to our ABI, already correctly sign/zero extended?
> >>>
> >>> I don't think REE has ever considered exploiting ABI constraints. Handling
> >>> that might be a notable improvement on various targets.  It'd be a great
> >>> place to do some experimentation.
> >>
> >> Ok, so sounds like a good follow-on project after this patch is reviewed
> >> and committed (stage1).  Thanks for your input!
> >
> > Agreed.  I suspect that risc-v will benefit from such work as well. 
> > With that in mind, if y'all start poking at this, please loop in Raphael
> > (on cc) who's expressed an interest in this space.
> 
> Will do.  I suspect that it'll be best to come up with some generic interface
> using target hooks like "param regs are sign/zero extended" or "call return
> values are sign/zero extended", etc. that targets can conditionally opt into
> depending on their ABI that is in effect.

Pardon the arm-chair development mode but it sounds like 
re-inventing the TARGET_PROMOTE_* hooks...

Maybe just hook up TARGET_PROMOTE_FUNCTION_MODE to ree.c (as 
"you" already already define it for "rs6000")?

brgds, H-P


Re: [PATCH] Introduce -nolibstdc++ option

2023-03-30 Thread Gerald Pfeifer
On Thu, 30 Mar 2023, Alexandre Oliva wrote:
> How about this, does this seem useful?

I like it - helpful and easy to understand. :-)

Gerald


Re: [pushed] wwwdocs: gcc-4.7: Adjust dwarfstd.org links

2023-03-30 Thread Gerald Pfeifer
On Thu, 30 Mar 2023, Mark Wielaard wrote:
>>> Business as usual - 301 Moved Permanently.
>> Just FYI, dwarfstd is now hosted by sourceware too. So I doubt these
>> URLs will change after this.

Famous last words. :-)

> Indeed, see
> https://inbox.sourceware.org/overseers/20230327222524.ga20...@gnu.wildebeest.org/
> 
> And thanks for taking care of these new redirects. Please do let us
> (dwarf-disc...@lists.dwarfstd.org) know if any old URL is broken.

Yes, I'll advise, though so far I am draw my hat for you handling this
migration so smoothly: all links still have been working, and a proper
redirect - "301, please adjust links" - been issued.

Gerald


Re: [wwwdocs] Mention the GNU C enum changes in gcc-13/changes.html

2023-03-30 Thread Gerald Pfeifer
On Fri, 24 Mar 2023, Jakub Jelinek wrote:
> Shall we mention it in porting_to.html as well?
> The only known affected package is (was?) the Linux kernel.

If in a rebuild of Fedora (or openSUSE) the only affected package is the 
kernel, we probably don't need to go for porting_to.html?

> --- a/htdocs/gcc-13/changes.html
> +++ b/htdocs/gcc-13/changes.html
> +The behavior of the GNU C extension support of enumerators which
> +  don't fit into int has been changed to match the C2X
> +  behavior.  Previously, in enumerations where at least one enumerator
> +  didn't fit into int, only those enumerators that didn't
> +  fit into int had the enum type and others
> +  had int type 

So far I understand, and it feels intuitive.

>and while the enum is being
> +  defined enumerators that didn't fit into int had some
> +  unspecified type with the sign and precision of its value.

This, however, really confuses me.

Should this be "while" (without "and")?

And what are we trying to say here? Can we essentially omit this since
it is a bit more specific, but mostly redundant with the earlier 
statement?

Otherwise, maybe first talk about the elements that fit type int and
then merge the two statements about those that don't?


> +  In GCC13, in such enumerations all enumerators have the
> +  enum type and while the enum is being
> +  defined enumerators that didn't fit into int have
> +  type of their value.

"don't" 

"the type of their value"?

>  If all enumerators fit into int
> +  type, as before all enumerators have int type, both
> +  while the enum is being defined and after it is defined.
> +  See https://gcc.gnu.org/PR36113;>PR36113 for details.
> +

Can we skip this? "In such enumerations" above refers to the special case,
and the simple case (where everything fits into int) has not changed, has 
it?

Gerald


Re: [PATCH]middle-end Guard value_replacement and store_elim from seeing diamonds.

2023-03-30 Thread Andrew Pinski via Gcc-patches
On Fri, Aug 5, 2022 at 6:16 AM Tamar Christina via Gcc-patches
 wrote:
>
> Hi All,
>
> This excludes value_replacement and store_elim from diamonds as they don't
> handle the form properly.
>
> Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu
> and no issues.
>
> Ok for master?

I just noticed this changes the behavior of the store elimination pass
to also act like phi-opt if bb layout was a diamond.
I will be submitting a patch for GCC 14 to revert back that behavior
with some refactoring I am doing to improve the readability of the
code.

Thanks,
Andrew Pinski

>
> Thanks,
> Tamar
>
> gcc/ChangeLog:
>
> PR middle-end/106534
> * tree-ssa-phiopt.cc (tree_ssa_phiopt_worker): Guard the
> value_replacement and store_elim from diamonds.
>
> --- inline copy of patch --
> diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
> index 
> bdbf52916b0f88ee4f475e1fa306046d61f13d53..1e002c608591836ffb001724b3f469a8d042ae5e
>  100644
> --- a/gcc/tree-ssa-phiopt.cc
> +++ b/gcc/tree-ssa-phiopt.cc
> @@ -283,7 +283,7 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool 
> do_hoist_loads, bool early_p)
>   || (e1->flags & EDGE_FALLTHRU) == 0)
>  continue;
>
> -  if (do_store_elim)
> +  if (do_store_elim && !diamond_p)
> {
>   /* Also make sure that bb1 only have one predecessor and that it
>  is bb.  */
> @@ -310,7 +310,7 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool 
> do_hoist_loads, bool early_p)
>
>   /* Value replacement can work with more than one PHI
>  so try that first. */
> - if (!early_p)
> + if (!early_p && !diamond_p)
> for (gsi = gsi_start (phis); !gsi_end_p (gsi); gsi_next ())
>   {
> phi = as_a  (gsi_stmt (gsi));
>
>
>
>
> --


[pushed] c++: generic lambda and function ptr conv [PR105221]

2023-03-30 Thread Jason Merrill via Gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

We weren't properly considering the function pointer conversions in
deduction between FUNCTION_TYPE; we just hardcoded the
UNIFY_ALLOW_MORE_CV_QUAL semantics, which are backwards when deducing for a
template conversion function like the one in a generic lambda.  And when I
started checking the ALLOW flags, I needed to make sure they stay set to
avoid breaking trailing13.C.

PR c++/105221

gcc/cp/ChangeLog:

* pt.cc (unify) [FUNCTION_TYPE]: Handle function pointer
conversions.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/noexcept-type27.C: New test.
---
 gcc/cp/pt.cc | 33 ++--
 gcc/testsuite/g++.dg/cpp1z/noexcept-type27.C |  8 +
 2 files changed, 38 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1z/noexcept-type27.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index e514a277872..dd7f0db9658 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -24472,9 +24472,12 @@ unify (tree tparms, tree targs, tree parm, tree arg, 
int strict,
 return unify_cv_qual_mismatch (explain_p, parm, arg);
 
   if (!(strict & UNIFY_ALLOW_OUTER_LEVEL)
-  && TYPE_P (parm) && !CP_TYPE_CONST_P (parm))
+  && TYPE_P (parm) && !CP_TYPE_CONST_P (parm)
+  && !FUNC_OR_METHOD_TYPE_P (parm))
 strict &= ~UNIFY_ALLOW_MORE_CV_QUAL;
-  strict &= ~UNIFY_ALLOW_OUTER_LEVEL;
+  /* PMFs recurse at the same level, so don't strip this yet.  */
+  if (!TYPE_PTRMEMFUNC_P (parm))
+strict &= ~UNIFY_ALLOW_OUTER_LEVEL;
   strict &= ~UNIFY_ALLOW_DERIVED;
   strict &= ~UNIFY_ALLOW_OUTER_MORE_CV_QUAL;
   strict &= ~UNIFY_ALLOW_OUTER_LESS_CV_QUAL;
@@ -25022,7 +25025,31 @@ unify (tree tparms, tree targs, tree parm, tree arg, 
int strict,
  RECUR_AND_CHECK_FAILURE (tparms, targs, TREE_PURPOSE (pspec),
   TREE_PURPOSE (aspec),
   UNIFY_ALLOW_NONE, explain_p);
-   else if (nothrow_spec_p (pspec) && !nothrow_spec_p (aspec))
+   else
+ {
+   bool pn = nothrow_spec_p (pspec);
+   bool an = nothrow_spec_p (aspec);
+   /* Here "less cv-qual" means the deduced arg (i.e. parm) has
+  /more/ noexcept, since function pointer conversions are the
+  reverse of qualification conversions.  */
+   if (an == pn
+   || (an < pn && (strict & UNIFY_ALLOW_LESS_CV_QUAL))
+   || (an > pn && (strict & UNIFY_ALLOW_MORE_CV_QUAL)))
+ /* OK.  */;
+   else
+ return unify_type_mismatch (explain_p, parm, arg);
+ }
+ }
+   if (flag_tm)
+ {
+   /* As for noexcept.  */
+   bool pn = tx_safe_fn_type_p (parm);
+   bool an = tx_safe_fn_type_p (arg);
+   if (an == pn
+   || (an < pn && (strict & UNIFY_ALLOW_LESS_CV_QUAL))
+   || (an > pn && (strict & UNIFY_ALLOW_MORE_CV_QUAL)))
+ /* OK.  */;
+   else
  return unify_type_mismatch (explain_p, parm, arg);
  }
 
diff --git a/gcc/testsuite/g++.dg/cpp1z/noexcept-type27.C 
b/gcc/testsuite/g++.dg/cpp1z/noexcept-type27.C
new file mode 100644
index 000..a691f695389
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/noexcept-type27.C
@@ -0,0 +1,8 @@
+// PR c++/105221
+// { dg-do compile { target c++14 } }
+
+void (*p)(int) = [](auto) noexcept {};
+
+int main() {
+  true ? [](auto) noexcept {} : [](int) {};
+}

base-commit: 83d2b1ccd17d394d546a38562815ef83daa05e85
-- 
2.31.1



[pushed] c++: anonymous union member reference [PR105452]

2023-03-30 Thread Jason Merrill via Gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

While parsing the anonymous union, we don't yet know that it's an anonymous
union, so we build the reference to 'v' in the static_assert relative to the
union type.  But at instantiation time we know it's an anonymous union, so
we need to avoid trying to check access for 'v' in the union again; the
simplest approach seemed to be to make accessible_p step out to the
containing class.

While looking at this I also noticed that we were having trouble with DMI in
an anonymous union referring to members of the containing class; there
we just need to give current_class_ptr the right type.

PR c++/105452

gcc/cp/ChangeLog:

* search.cc (type_context_for_name_lookup): New.
(accessible_p): Handle anonymous union.
* init.cc (maybe_instantiate_nsdmi_init): Use
type_context_for_name_lookup.
* parser.cc (cp_parser_class_specifier): Likewise.
* cp-tree.h (type_context_for_name_lookup): Declare.

gcc/testsuite/ChangeLog:

* g++.dg/lookup/anon8.C: New test.
---
 gcc/cp/cp-tree.h|  1 +
 gcc/cp/init.cc  |  2 +-
 gcc/cp/parser.cc|  5 +++--
 gcc/cp/search.cc| 23 +++
 gcc/testsuite/g++.dg/lookup/anon8.C | 16 
 5 files changed, 44 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/lookup/anon8.C

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 0e37d4043d0..d450b3d5b78 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -7534,6 +7534,7 @@ extern int at_function_scope_p(void);
 extern bool at_class_scope_p   (void);
 extern bool at_namespace_scope_p   (void);
 extern tree context_for_name_lookup(tree);
+extern tree type_context_for_name_lookup   (tree);
 extern tree lookup_conversions (tree);
 extern tree binfo_from_vbase   (tree);
 extern tree binfo_for_vbase(tree, tree);
diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index c5a55dae563..9571d18170e 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -597,7 +597,7 @@ maybe_instantiate_nsdmi_init (tree member, tsubst_flags_t 
complain)
  DECL_INSTANTIATING_NSDMI_P (member) = 1;
 
  bool pushed = false;
- tree ctx = DECL_CONTEXT (member);
+ tree ctx = type_context_for_name_lookup (member);
 
  processing_template_decl_sentinel ptds (/*reset*/false);
  if (!currently_open_class (ctx))
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index e8efc32f2c2..a6341b98af2 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -26439,11 +26439,12 @@ cp_parser_class_specifier (cp_parser* parser)
   /* Now parse any NSDMIs.  */
   FOR_EACH_VEC_SAFE_ELT (unparsed_nsdmis, ix, decl)
{
- if (class_type != DECL_CONTEXT (decl))
+ tree ctx = type_context_for_name_lookup (decl);
+ if (class_type != ctx)
{
  if (pushed_scope)
pop_scope (pushed_scope);
- class_type = DECL_CONTEXT (decl);
+ class_type = ctx;
  pushed_scope = push_scope (class_type);
}
  inject_this_parameter (class_type, TYPE_UNQUALIFIED);
diff --git a/gcc/cp/search.cc b/gcc/cp/search.cc
index e472a97679d..3f521b3bd72 100644
--- a/gcc/cp/search.cc
+++ b/gcc/cp/search.cc
@@ -485,6 +485,25 @@ context_for_name_lookup (tree decl)
   return context;
 }
 
+/* Like the above, but always return a type, because it's simpler for member
+   handling to refer to the anonymous aggr rather than a function.  */
+
+tree
+type_context_for_name_lookup (tree decl)
+{
+  tree context = DECL_P (decl) ? DECL_CONTEXT (decl) : decl;
+  gcc_checking_assert (CLASS_TYPE_P (context));
+
+  while (context && TYPE_P (context) && ANON_AGGR_TYPE_P (context))
+{
+  tree next = TYPE_CONTEXT (context);
+  if (!TYPE_P (next))
+   break;
+  context = next;
+}
+  return context;
+}
+
 /* Returns true iff DECL is declared in TYPE.  */
 
 static bool
@@ -881,6 +900,10 @@ accessible_p (tree type, tree decl, bool consider_local_p)
   else
 otype = type;
 
+  /* Anonymous unions don't have their own access.  */
+  if (ANON_AGGR_TYPE_P (type))
+type = type_context_for_name_lookup (type);
+
   /* [class.access.base]
 
  A member m is accessible when named in class N if
diff --git a/gcc/testsuite/g++.dg/lookup/anon8.C 
b/gcc/testsuite/g++.dg/lookup/anon8.C
new file mode 100644
index 000..80124caba63
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lookup/anon8.C
@@ -0,0 +1,16 @@
+// PR c++/105452
+// { dg-do compile { target c++11 } }
+
+template 
+struct C {
+  int i = 42;
+  union {
+T v = i;
+static_assert(sizeof(v) == sizeof(char), "");
+  };
+};
+
+int main() {
+  C x;
+  return x.v;
+}

base-commit: a23b33a1bdeff7bc2289d9ebb7cb7b7ec0a605f5
prerequisite-patch-id: 

Re: [PATCH] c++tools: Fix Makefile to properly clean and rebuild [PR101834]

2023-03-30 Thread Jason Merrill via Gcc-patches

On 3/30/23 08:15, Jonathan Wakely wrote:

Tested with various combinations of 'make clean all' etc.

OK for trunk?

And backport to gcc-12 and gcc-11 after some soak time on trunk?


OK.


-- >8 --

The c++tools makefile doesn't remove progressively more files in each of
mostlyclean, clean, and distclean. Instead, each removes a different set
of files (and some files are not removed by any target). Use
prerequisites so that everything is removed.

Also, building in the $objdir/c++tools directory doesn't work, because
the INSTALL variable is never set. It works when building from the
top-level because INSTALL is set in the environment when recursively
invoking make for sub-directories.

c++tools/ChangeLog:

PR bootstrap/101834
* Makefile.in (INSTALL): Set variable.
(mostlyclean): Mark as a phony target.
(clean): Add mostlyclean as a prerequisite.
(distclean): Add clean as a prerequisite and remove more files.
(maintainer-clean): Add distclean as a prerequisite.
---
  c++tools/Makefile.in | 12 +++-
  1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/c++tools/Makefile.in b/c++tools/Makefile.in
index 56cba090135..77bda3d56dc 100644
--- a/c++tools/Makefile.in
+++ b/c++tools/Makefile.in
@@ -22,6 +22,7 @@ libexecdir := @libexecdir@
  target_noncanonical := @target_noncanonical@
  gcc_version := $(shell @get_gcc_base_ver@ $(srcdir)/../gcc/BASE-VER)
  libexecsubdir := $(libexecdir)/gcc/$(target_noncanonical)/$(gcc_version)
+INSTALL := @INSTALL@
  INSTALL_PROGRAM := @INSTALL_PROGRAM@
  INSTALL_STRIP_PROGRAM := $(srcdir)/../install-sh -c -s
  AUTOCONF := @AUTOCONF@
@@ -41,13 +42,14 @@ all::
  mostlyclean::
rm -f $(MAPPER.O)
  
-clean::

+clean:: mostlyclean
rm -f g++-mapper-server$(exeext)
  
-distclean::

-   rm -f config.log config.status config.h
+distclean:: clean
+   rm -f config.log config.status config.h config.cache Makefile
+   rm -f $(MAPPER.O:%.o=%.d)
  
-maintainer-clean::

+maintainer-clean:: distclean
  
  install::
  
@@ -132,6 +134,6 @@ config.h: config.status config.h.in

  config.status: $(srcdir)/configure $(srcdir)/config.h.in
if test -x $@; then ./$@ -recheck; else $< @configure_args@; fi
  
-.PHONY: all check clean distclean maintainer-clean

+.PHONY: all check mostlyclean clean distclean maintainer-clean
  
  -include $(MAPPER.O:.o=.d)




Re: [PATCH 1/2] c++: improve "NTTP argument considered unused" fix [PR53164, PR105848]

2023-03-30 Thread Jason Merrill via Gcc-patches

On 3/30/23 14:53, Patrick Palka wrote:

On Wed, 29 Mar 2023, Jason Merrill wrote:


On 3/27/23 09:30, Patrick Palka wrote:

On Thu, 23 Mar 2023, Patrick Palka wrote:


r13-995-g733a792a2b2e16 worked around the problem of FUNCTION_DECL
template arguments not always getting marked as odr-used by redundantly
calling mark_used on the substituted ADDR_EXPR callee of a CALL_EXPR.
This is just a narrow workaround however, since using a FUNCTION_DECL as
a template argument alone should constitutes an odr-use; we shouldn't
need to subsequently e.g. call the function or take its address.


Agreed.  But why didn't we already wrap it in an ADDR_EXPR?  Even for
reference tparms convert_nontype_argument should do that.


Indeed we do, the commit message was just rather sloppy/inaccurate...
I'll try to correct it.




This patch fixes this in a more general way at template specialization
time by walking the template arguments of the specialization and calling
mark_used on all entities used within.  As before, the call to mark_used
as it worst a no-op, but it compensates for the situation where we end up
forming a specialization from a template context in which mark_used is
inhibited.  Another approach would be to call mark_used whenever we
substitute a TEMPLATE_PARM_INDEX, but that would result in many more
redundant calls to mark_used compared to this approach.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk?

PR c++/53164
PR c++/105848

gcc/cp/ChangeLog:

* pt.cc (instantiate_class_template): Call
mark_template_arguments_used.
(tsubst_copy_and_build) : Revert r13-995 change.
(mark_template_arguments_used): Define.
(instantiate_template): Call mark_template_arguments_used.

gcc/testsuite/ChangeLog:

* g++.dg/template/fn-ptr3a.C: New test.
* g++.dg/template/fn-ptr4.C: New test.
---
   gcc/cp/pt.cc | 51 
   gcc/testsuite/g++.dg/template/fn-ptr3a.C | 25 
   gcc/testsuite/g++.dg/template/fn-ptr4.C  | 14 +++
   3 files changed, 74 insertions(+), 16 deletions(-)
   create mode 100644 gcc/testsuite/g++.dg/template/fn-ptr3a.C
   create mode 100644 gcc/testsuite/g++.dg/template/fn-ptr4.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 7e4a8de0c8b..9b3cc1c 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -220,6 +220,7 @@ static tree make_argument_pack (tree);
   static tree enclosing_instantiation_of (tree tctx);
   static void instantiate_body (tree pattern, tree args, tree d, bool
nested);
   static tree maybe_dependent_member_ref (tree, tree, tsubst_flags_t,
tree);
+static void mark_template_arguments_used (tree);
 /* Make the current scope suitable for access checking when we are
  processing T.  T can be FUNCTION_DECL for instantiated function
@@ -12142,6 +12143,9 @@ instantiate_class_template (tree type)
 cp_unevaluated_operand = 0;
 c_inhibit_evaluation_warnings = 0;
   }
+
+  mark_template_arguments_used (INNERMOST_TEMPLATE_ARGS (args));
+
 /* Use #pragma pack from the template context.  */
 saved_maximum_field_alignment = maximum_field_alignment;
 maximum_field_alignment = TYPE_PRECISION (pattern);
@@ -21173,22 +21177,10 @@ tsubst_copy_and_build (tree t,
  }
/* Remember that there was a reference to this entity.  */
-   if (function != NULL_TREE)
- {
-   tree inner = function;
-   if (TREE_CODE (inner) == ADDR_EXPR
-   && TREE_CODE (TREE_OPERAND (inner, 0)) == FUNCTION_DECL)
- /* We should already have called mark_used when taking the
-address of this function, but do so again anyway to make
-sure it's odr-used: at worst this is a no-op, but if we
-obtained this FUNCTION_DECL as part of ahead-of-time overload
-resolution then that call to mark_used wouldn't have marked
it
-odr-used yet (53164).  */
- inner = TREE_OPERAND (inner, 0);
-   if (DECL_P (inner)
-   && !mark_used (inner, complain) && !(complain & tf_error))
- RETURN (error_mark_node);
- }
+   if (function != NULL_TREE
+   && DECL_P (function)
+   && !mark_used (function, complain) && !(complain & tf_error))
+ RETURN (error_mark_node);
if (!maybe_fold_fn_template_args (function, complain))
  return error_mark_node;
@@ -21883,6 +21875,31 @@ check_instantiated_args (tree tmpl, tree args,
tsubst_flags_t complain)
 return result;
   }
   +/* Call mark_used on each entity within the template arguments ARGS of
some
+   template specialization, to ensure that each such entity is considered
+   odr-used regardless of whether the specialization was first formed in
a
+   template context.
+
+   This function assumes push_to_top_level has been called beforehand,
and
+   that processing_template_decl has been set iff 

Re: [PATCH] c++: Fix up ICE in build_min_non_dep_op_overload [PR109319]

2023-03-30 Thread Jason Merrill via Gcc-patches

On 3/30/23 03:47, Jakub Jelinek wrote:

Hi!

The following testcase ICEs, because grok_array_decl during
processing_template_decl handling of a non-dependent subscript
emits a -Wcomma-subscript pedwarn, we decide to pass to the
single index argument the index expressions as if it was wrapped
with () around it, but then when preparing it for later instantiation
we don't actually take that into account and ICE on a mismatch of
number of index arguments (the overload expects a single index,
testcase has two index expressions in this case).
For non-dependent subscript which are builtin subscripts we also
emit the same pedwarn and don't ICE, but emit the same pedwarn
again whenever we instantiate it, which is also IMHO undesirable,
it is enough to warn once during parsing the template.

The following patch fixes it by turning even the original index expressions
(those which didn't go through make_args_non_dependent) into a single
index using comma expression(s).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?


OK.


2023-03-30  Jakub Jelinek  

PR c++/109319
* decl2.cc (grok_array_decl): After emitting a pedwarn for
-Wcomma-subscript, if processing_template_decl set orig_index_exp
to compound expr from orig_index_exp_list.

* g++.dg/cpp23/subscript14.C: New test.

--- gcc/cp/decl2.cc.jj  2023-03-20 20:29:34.0 +0100
+++ gcc/cp/decl2.cc 2023-03-29 15:17:14.952173134 +0200
@@ -474,11 +474,23 @@ grok_array_decl (location_t loc, tree ar
 , complain);
}
  else
-   /* If it would be valid albeit deprecated expression in C++20,
-  just pedwarn on it and treat it as if wrapped in ().  */
-   pedwarn (loc, OPT_Wcomma_subscript,
-"top-level comma expression in array subscript "
-"changed meaning in C++23");
+   {
+ /* If it would be valid albeit deprecated expression in
+C++20, just pedwarn on it and treat it as if wrapped
+in ().  */
+ pedwarn (loc, OPT_Wcomma_subscript,
+  "top-level comma expression in array subscript "
+  "changed meaning in C++23");
+ if (processing_template_decl)
+   {
+ orig_index_exp
+   = build_x_compound_expr_from_vec (orig_index_exp_list,
+ NULL, complain);
+ if (orig_index_exp == error_mark_node)
+   expr = error_mark_node;
+ release_tree_vector (orig_index_exp_list);
+   }
+   }
}
}
  }
@@ -519,6 +531,15 @@ grok_array_decl (location_t loc, tree ar
  return error_mark_node;
}
  index_exp = idx;
+ if (processing_template_decl)
+   {
+ orig_index_exp
+   = build_x_compound_expr_from_vec (orig_index_exp_list,
+ NULL, complain);
+ release_tree_vector (orig_index_exp_list);
+ if (orig_index_exp == error_mark_node)
+   return error_mark_node;
+   }
}
  
if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE)

--- gcc/testsuite/g++.dg/cpp23/subscript14.C.jj 2023-03-29 15:29:46.037076158 
+0200
+++ gcc/testsuite/g++.dg/cpp23/subscript14.C2023-03-29 15:34:18.645051075 
+0200
@@ -0,0 +1,42 @@
+// PR c++/109319
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+struct A { static int [] (int x) { static int a[2]; return a[x]; } }; // { dg-warning 
"may be a static member function only with" "" { target c++20_down } }
+struct B { int [] (int x) { static int b[2]; return b[x]; } };
+int c[2];
+
+template 
+int
+foo ()
+{
+  A a;
+  ++a[0, 1];   // { dg-warning "top-level comma expression in array subscript changed 
meaning" "" { target c++23 } }
+  B b; // { dg-warning "top-level comma expression in array subscript is 
deprecated" "" { target c++20_only } .-1 }
+  ++b[0, 1];   // { dg-warning "top-level comma expression in array subscript changed 
meaning" "" { target c++23 } }
+   // { dg-warning "top-level comma expression in array subscript is 
deprecated" "" { target c++20_only } .-1 }
+  ++c[0, 1];   // { dg-warning "top-level comma expression in array subscript changed 
meaning" "" { target c++23 } }
+  T d; // { dg-warning "top-level comma expression in array subscript is 
deprecated" "" { target c++20_only } .-1 }
+  ++d[0, 1];   // { dg-warning "top-level comma expression in array subscript changed 
meaning" "" { target c++23 } }
+  U e; // { dg-warning "top-level comma expression in array subscript is 

Re: [PATCH] c++,coroutines: Stabilize names of promoted slot vars [PR101118].

2023-03-30 Thread Jason Merrill via Gcc-patches

On 3/30/23 03:53, Iain Sandoe wrote:

Hi Jason,


On 30 Mar 2023, at 00:53, Jason Merrill  wrote:

On 3/26/23 12:54, Iain Sandoe wrote:

Tested on x86_64-darwin21, x86-64-linux-gnu



  +/* This is used to make a stable, but unique-per-function, sequence number 
for
+   each TARGET_EXPR slot variable that we 'promote' to a frame entry.  It needs
+   to be stable because the frame type is visible to LTO ODR checking.  */
+static unsigned tmpno = 0;


How about using temps_used->elements() for the index instead of a separate 
static counter?


That’s a good idea (the only slightly weird effect is that the count does not 
start at 0,
because we’ve added one or more entries by the time we get to produce a name, 
but
that does not affect functionality).


Perhaps promoted->elements() would be a better choice?  OK either way.


re-tested on x86_64-darwin21, as below,
OK for trunk?
thanks
Iain

===

[PATCH] c++,coroutines: Stabilize names of promoted slot vars  [PR101118].

When we need to 'promote' a value (i.e. store it in the coroutine frame) it
is given a frame entry name.  This was based on the DECL_UID for slot vars.
However, when LTO is used, the names from multiple TUs become visible at the
same time, and the DECL_UIDs usually differ between units.  This leads to a
"ODR mismatch" warning for the frame type.

The fix here is to use the current promoted temporaries count to produce
the name, this is stable between TUs and computed per coroutine.

Signed-off-by: Iain Sandoe 

PR c++/101118

gcc/cp/ChangeLog:

* coroutines.cc (flatten_await_stmt): Use the current count of
promoted temporaries to build a unique name for the frame entries.
---
  gcc/cp/coroutines.cc | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index a2189e43db8..9f546db7437 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -2889,7 +2889,7 @@ flatten_await_stmt (var_nest_node *n, hash_set 
*promoted,
  tree init = t;
  temps_used->add (init);
  tree var_type = TREE_TYPE (init);
- char *buf = xasprintf ("D.%d", DECL_UID (TREE_OPERAND (init, 0)));
+ char *buf = xasprintf ("T%03u", temps_used->elements());
  tree var = build_lang_decl (VAR_DECL, get_identifier (buf), var_type);
  DECL_ARTIFICIAL (var) = true;
  free (buf);
—






Re: recomputation and PR 109154

2023-03-30 Thread Andrew MacLeod via Gcc-patches
I committed it.   ran it again for fun.  sigh.  Looks like its also 
triggering another issue now in g++.dg/warn/Wstringop-overflow-4.C

where its issuing:

b.C: In function ‘void test_strcpy_new_int16_t(size_t, const size_t*)’:
b.C:76:12: warning: ‘void* __builtin_memcpy(void*, const void*, long 
unsigned int)’ writing 3 bytes into a region of size 0 
[-Wstringop-overflow=]

   76 | strcpy (d, s);  \
  | ~~~^~
b.C:90:3: note: in expansion of macro ‘T’
   90 |   T (S (2), new int16_t[r_imin_imax + 1]); // { dg-bogus "into 
a region of size" "pr106120" { xfail { ilp32 && c++98_only } } }



previously, by VRP2 time we hadn't figured out the edge case, couldn't 
recalculate _29 and iftmp.1_38 was unknown.


   iftmp.1_38 = _29 * 2;
  _40 = operator new [] (iftmp.1_38);
  __builtin_memcpy (_40,   [(void 
*)"0123456789abcdefghijklmnopqrstuvwxyz" + 34B], 3);


Now, by VRP2 we have figured it out...

    _40 = operator new [] (0);
    __builtin_memcpy (_40,   [(void 
*)"0123456789abcdefghijklmnopqrstuvwxyz" + 34B], 3);


And that info is available earlier for the warnings,  just hasn't  been 
explcitly exposed:


Do we want to change the cfail to always? something like:

diff --git a/gcc/testsuite/g++.dg/warn/Wstringop-overflow-4.C 
b/gcc/testsuite/g++.dg/warn/Wstringop-overflow-4.C

index 35fb59e0232..faad5bed074 100644
--- a/gcc/testsuite/g++.dg/warn/Wstringop-overflow-4.C
+++ b/gcc/testsuite/g++.dg/warn/Wstringop-overflow-4.C
@@ -141,7 +141,7 @@ void test_strcpy_new_int16_t (size_t n, const size_t 
vals[])


   int r_imin_imax = SR (INT_MIN, INT_MAX);
   T (S (1), new int16_t[r_imin_imax]);
-  T (S (2), new int16_t[r_imin_imax + 1]); // { dg-bogus "into a region 
of size" "pr106120" { xfail { ilp32 && c++98_only } } }
+  T (S (2), new int16_t[r_imin_imax + 1]); // { dg-bogus "into a region 
of size" "pr106120" { xfail { c++98_only } } }

   T (S (9), new int16_t[r_imin_imax * 2 + 1]);

   int r_0_imax = SR (0, INT_MAX);


Of course, I dont know what this is doing on other arches... perhaps 
wait for the fallout to be complete?


Andrew

On 3/30/23 12:05, Jakub Jelinek wrote:

On Thu, Mar 30, 2023 at 11:58:19AM -0400, Andrew MacLeod wrote:

On 3/30/23 09:41, Jakub Jelinek wrote:

On Wed, Mar 29, 2023 at 01:22:27PM -0400, Andrew MacLeod wrote:

however, as seems to be the case often, better ranges result in, I now get:

FAIL: 23_containers/vector/bool/allocator/copy.cc (test for excess errors)

Our middle-end warnings are just badly designed :(, the better value ranges
are, the more false positives they have.


commit 358d0ca44faf2e20fbacd0f74386308b5ca52cd4
Author: Andrew MacLeod 
Date:   Tue Mar 28 12:16:34 2023 -0400

  Add recursive GORI recompuations with a depth limit.

LGTM for trunk, let's do with the regression incrementally.
Or as Richard mentioned on IRC, one possibility would be to force this
param temporarily to 1 (or whatever matches previous behavior) for the
diagnostic range queries).

You need a ChangeLog entry though...


Attached. I also removed the bogus warning in Walloc-13.c that no longer
happens

So incrementally deal with it.. what? just let it fail?

For today?  Yes.

Ok for trunk.


commit debb8ce1f9b9d5a72d88d0ae90a6b4da5130ff59
Author: Andrew MacLeod 
Date:   Tue Mar 28 12:16:34 2023 -0400

 Add recursive GORI recompuations with a depth limit.
 
 PR tree-optimization/109154

 gcc/
 * gimple-range-gori.cc (gori_compute::may_recompute_p): Add depth 
limit.
 * gimple-range-gori.h (may_recompute_p): Add depth param.
 * params.opt (ranger-recompute-depth): New param.
 
 gcc/testsuite/

 * gcc.dg/Walloca-13.c: Remove bogus warning that is now fixed.

Jakub





Re: [PATCH v4] rs6000: Fix incorrect RTL for Power LE when removing the UNSPECS [PR106069]

2023-03-30 Thread Segher Boessenkool
Hi!

On Fri, Feb 10, 2023 at 10:59:52AM +0800, Xionghu Luo via Gcc-patches wrote:
> The native RTL expression for vec_mrghw should be same for BE and LE as
> they are register and endian-independent.

This isn't so obvious at all.  All elements of these constructs are
very much not endian-independent, because of very unfortunate choices
in the meaning of some RTL constructs.  It is possible all things in
this negate all other things, but please show that then.

>  So both BE and LE need
> generate exactly same RTL with index [0 4 1 5] when expanding vec_mrghw
> with vec_select and vec_concat.
> 
> (set (reg:V4SI 141) (vec_select:V4SI (vec_concat:V8SI
>  (subreg:V4SI (reg:V16QI 139) 0)
>  (subreg:V4SI (reg:V16QI 140) 0))
>  [const_int 0 4 1 5]))

With BE, if the source vecs are ABCD and EFGH, the vec_concat gives
ABCDEFGH, and the vec_select than gives AEBF.

What happens for LE?


Segher


Re: [PATCH] Fix fc-prototypes usage with C_INT64_T and non LP64 Targets.

2023-03-30 Thread Steve Kargl via Gcc-patches
On Thu, Mar 30, 2023 at 07:39:55PM +0200, Thomas Koenig via Fortran wrote:
> Hi Andrew,
> 
> > "long long". This was just an oversight and a missing check.
> > 
> > Committed as obvious after a bootstrap/test on x86_64-linux-gnu.
> 
> Thanks!
> 
> I think this one is obvious enough that it deserves a backport.
> I've cherry-picked this for gcc12, will do gcc11 tomorrow.
> 

The patch is incomplete.

module foo
 use, intrinsic :: iso_c_binding
 implicit none
 public :: bar
 type, bind(c) :: bar
  real(10) a
 end type
end module

This yields

typedef struct bar {
long_double a /* WARNING: Converting 'REAL(10)' to interoperable type */;
} bar;

That should be 'long double'.

-- 
Steve


Re: [PATCH 1/2] c++: improve "NTTP argument considered unused" fix [PR53164, PR105848]

2023-03-30 Thread Patrick Palka via Gcc-patches
On Wed, 29 Mar 2023, Jason Merrill wrote:

> On 3/27/23 09:30, Patrick Palka wrote:
> > On Thu, 23 Mar 2023, Patrick Palka wrote:
> > 
> > > r13-995-g733a792a2b2e16 worked around the problem of FUNCTION_DECL
> > > template arguments not always getting marked as odr-used by redundantly
> > > calling mark_used on the substituted ADDR_EXPR callee of a CALL_EXPR.
> > > This is just a narrow workaround however, since using a FUNCTION_DECL as
> > > a template argument alone should constitutes an odr-use; we shouldn't
> > > need to subsequently e.g. call the function or take its address.
> 
> Agreed.  But why didn't we already wrap it in an ADDR_EXPR?  Even for
> reference tparms convert_nontype_argument should do that.

Indeed we do, the commit message was just rather sloppy/inaccurate...
I'll try to correct it.

> 
> > > This patch fixes this in a more general way at template specialization
> > > time by walking the template arguments of the specialization and calling
> > > mark_used on all entities used within.  As before, the call to mark_used
> > > as it worst a no-op, but it compensates for the situation where we end up
> > > forming a specialization from a template context in which mark_used is
> > > inhibited.  Another approach would be to call mark_used whenever we
> > > substitute a TEMPLATE_PARM_INDEX, but that would result in many more
> > > redundant calls to mark_used compared to this approach.
> > > 
> > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> > > trunk?
> > > 
> > >   PR c++/53164
> > >   PR c++/105848
> > > 
> > > gcc/cp/ChangeLog:
> > > 
> > >   * pt.cc (instantiate_class_template): Call
> > >   mark_template_arguments_used.
> > >   (tsubst_copy_and_build) : Revert r13-995 change.
> > >   (mark_template_arguments_used): Define.
> > >   (instantiate_template): Call mark_template_arguments_used.
> > > 
> > > gcc/testsuite/ChangeLog:
> > > 
> > >   * g++.dg/template/fn-ptr3a.C: New test.
> > >   * g++.dg/template/fn-ptr4.C: New test.
> > > ---
> > >   gcc/cp/pt.cc | 51 
> > >   gcc/testsuite/g++.dg/template/fn-ptr3a.C | 25 
> > >   gcc/testsuite/g++.dg/template/fn-ptr4.C  | 14 +++
> > >   3 files changed, 74 insertions(+), 16 deletions(-)
> > >   create mode 100644 gcc/testsuite/g++.dg/template/fn-ptr3a.C
> > >   create mode 100644 gcc/testsuite/g++.dg/template/fn-ptr4.C
> > > 
> > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> > > index 7e4a8de0c8b..9b3cc1c 100644
> > > --- a/gcc/cp/pt.cc
> > > +++ b/gcc/cp/pt.cc
> > > @@ -220,6 +220,7 @@ static tree make_argument_pack (tree);
> > >   static tree enclosing_instantiation_of (tree tctx);
> > >   static void instantiate_body (tree pattern, tree args, tree d, bool
> > > nested);
> > >   static tree maybe_dependent_member_ref (tree, tree, tsubst_flags_t,
> > > tree);
> > > +static void mark_template_arguments_used (tree);
> > > /* Make the current scope suitable for access checking when we are
> > >  processing T.  T can be FUNCTION_DECL for instantiated function
> > > @@ -12142,6 +12143,9 @@ instantiate_class_template (tree type)
> > > cp_unevaluated_operand = 0;
> > > c_inhibit_evaluation_warnings = 0;
> > >   }
> > > +
> > > +  mark_template_arguments_used (INNERMOST_TEMPLATE_ARGS (args));
> > > +
> > > /* Use #pragma pack from the template context.  */
> > > saved_maximum_field_alignment = maximum_field_alignment;
> > > maximum_field_alignment = TYPE_PRECISION (pattern);
> > > @@ -21173,22 +21177,10 @@ tsubst_copy_and_build (tree t,
> > > }
> > >   /* Remember that there was a reference to this entity.  */
> > > - if (function != NULL_TREE)
> > > -   {
> > > - tree inner = function;
> > > - if (TREE_CODE (inner) == ADDR_EXPR
> > > - && TREE_CODE (TREE_OPERAND (inner, 0)) == FUNCTION_DECL)
> > > -   /* We should already have called mark_used when taking the
> > > -  address of this function, but do so again anyway to make
> > > -  sure it's odr-used: at worst this is a no-op, but if we
> > > -  obtained this FUNCTION_DECL as part of ahead-of-time overload
> > > -  resolution then that call to mark_used wouldn't have marked
> > > it
> > > -  odr-used yet (53164).  */
> > > -   inner = TREE_OPERAND (inner, 0);
> > > - if (DECL_P (inner)
> > > - && !mark_used (inner, complain) && !(complain & tf_error))
> > > -   RETURN (error_mark_node);
> > > -   }
> > > + if (function != NULL_TREE
> > > + && DECL_P (function)
> > > + && !mark_used (function, complain) && !(complain & tf_error))
> > > +   RETURN (error_mark_node);
> > >   if (!maybe_fold_fn_template_args (function, complain))
> > > return error_mark_node;
> > > @@ -21883,6 +21875,31 @@ check_instantiated_args (tree tmpl, tree args,
> > > tsubst_flags_t complain)
> > > return result;
> > >   }
> > >   +/* Call mark_used on 

[PATCH v2 7/7] libstdc++: make std::is_object dispatch to new built-in traits

2023-03-30 Thread Ken Matsui via Gcc-patches
This patch gets std::is_object to dispatch to new built-in traits,
__is_function, __is_reference, and __is_void.

libstdc++-v3/ChangeLog:
* include/std/type_traits (is_object): Use new built-in traits,
__is_function, __is_reference, and __is_void.

Signed-off-by: Ken Matsui 
---
 libstdc++-v3/include/std/type_traits | 9 +
 1 file changed, 9 insertions(+)

diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index 98764685a39..5d50c55b70f 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -689,11 +689,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 { };
 
   /// is_object
+#if __has_builtin(__is_function) && __has_builtin(__is_reference) \
+&& __has_builtin(__is_void)
+  template
+struct is_object
+: public __bool_constant
+{ };
+#else
   template
 struct is_object
 : public __not_<__or_, is_reference<_Tp>,
   is_void<_Tp>>>::type
 { };
+#endif
 
   template
 struct is_member_pointer;
-- 
2.40.0



[PATCH v2 5/7] c++, libstdc++: implement __is_void built-in trait

2023-03-30 Thread Ken Matsui via Gcc-patches
This patch implements built-in trait for std::is_void. Since the new built-in
name is __is_void, to avoid unintentional macro replacement, this patch also
involves the removal of the existing __is_void in helper_functions.h and
cpp_type_traits.h and renaming __is_void to is_void in the test file,
pr46567.C.

gcc/cp/ChangeLog:

* cp-trait.def: Define __is_void.
* constraint.cc (diagnose_trait_expr): Handle CPTK_IS_VOID.
* semantics.cc (trait_expr_value): Likewise.
(finish_trait_expr): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/tm/pr46567.C (__is_void): Rename to ...
(is_void): ... this.
* g++.dg/ext/has-builtin-1.C: Test existence of __is_void.
* g++.dg/ext/is_void.C: New test.

libstdc++-v3/ChangeLog:

* include/debug/helper_functions.h (_DiffTraits): Stop using
__is_void.
* include/bits/cpp_type_traits.h (__is_void): Remove unused __is_void.

Signed-off-by: Ken Matsui 
---
 gcc/cp/constraint.cc  |  3 ++
 gcc/cp/cp-trait.def   |  1 +
 gcc/cp/semantics.cc   |  4 +++
 gcc/testsuite/g++.dg/ext/has-builtin-1.C  |  3 ++
 gcc/testsuite/g++.dg/ext/is_void.C| 35 +++
 gcc/testsuite/g++.dg/tm/pr46567.C |  6 ++--
 libstdc++-v3/include/bits/cpp_type_traits.h   | 15 
 libstdc++-v3/include/debug/helper_functions.h |  5 ++-
 8 files changed, 51 insertions(+), 21 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/is_void.C

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 500ac9177c7..e67c0ffeaac 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3753,6 +3753,9 @@ diagnose_trait_expr (tree expr, tree args)
 case CPTK_IS_FUNCTION:
   inform (loc, "  %qT is not a function", t1);
   break;
+case CPTK_IS_VOID:
+  inform (loc, "  %qT is not a void type", t1);
+  break;
 case CPTK_IS_AGGREGATE:
   inform (loc, "  %qT is not an aggregate", t1);
   break;
diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
index 99195201676..6284924630a 100644
--- a/gcc/cp/cp-trait.def
+++ b/gcc/cp/cp-trait.def
@@ -84,6 +84,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, 
"__is_trivially_constructible", -1)
 DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
 DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
 DEFTRAIT_EXPR (IS_FUNCTION, "__is_function", 1)
+DEFTRAIT_EXPR (IS_VOID, "__is_void", 1)
 DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, 
"__reference_constructs_from_temporary", 2)
 DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, 
"__reference_converts_from_temporary", 2)
 /* FIXME Added space to avoid direct usage in GCC 13.  */
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 36fe370da2d..a6598fedfbc 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -11996,6 +11996,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree 
type2)
 case CPTK_IS_FUNCTION:
   return type_code1 == FUNCTION_TYPE;
 
+case CPTK_IS_VOID:
+  return VOID_TYPE_P (type1);
+
 case CPTK_IS_FINAL:
   return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
 
@@ -12209,6 +12212,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, 
tree type1, tree type2)
 case CPTK_IS_SAME:
 case CPTK_IS_REFERENCE:
 case CPTK_IS_FUNCTION:
+case CPTK_IS_VOID:
   break;
 
 case CPTK_IS_LAYOUT_COMPATIBLE:
diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C 
b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
index 90eb00ebf2d..b96cc9e6f50 100644
--- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
+++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
@@ -152,3 +152,6 @@
 #if !__has_builtin (__is_function)
 # error "__has_builtin (__is_function) failed"
 #endif
+#if !__has_builtin (__is_void)
+# error "__has_builtin (__is_void) failed"
+#endif
diff --git a/gcc/testsuite/g++.dg/ext/is_void.C 
b/gcc/testsuite/g++.dg/ext/is_void.C
new file mode 100644
index 000..707f0d6875b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_void.C
@@ -0,0 +1,35 @@
+// { dg-do compile { target c++11 } }
+
+#include 
+
+using namespace __gnu_test;
+
+#define SA(X) static_assert((X),#X)
+#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT)  \
+  SA(TRAIT(TYPE) == EXPECT);   \
+  SA(TRAIT(const TYPE) == EXPECT); \
+  SA(TRAIT(volatile TYPE) == EXPECT);  \
+  SA(TRAIT(const volatile TYPE) == EXPECT)
+
+SA_TEST_CATEGORY(__is_void, void, true);
+
+SA_TEST_CATEGORY(__is_void, char, false);
+SA_TEST_CATEGORY(__is_void, signed char, false);
+SA_TEST_CATEGORY(__is_void, unsigned char, false);
+SA_TEST_CATEGORY(__is_void, wchar_t, false);
+SA_TEST_CATEGORY(__is_void, short, false);
+SA_TEST_CATEGORY(__is_void, unsigned short, false);
+SA_TEST_CATEGORY(__is_void, int, false);
+SA_TEST_CATEGORY(__is_void, unsigned int, false);
+SA_TEST_CATEGORY(__is_void, long, false);
+SA_TEST_CATEGORY(__is_void, 

[PATCH v2 6/7] libstdc++: use new built-in trait __is_void for std::is_void

2023-03-30 Thread Ken Matsui via Gcc-patches
This patch gets std::is_void to dispatch to new built-in trait __is_void.

libstdc++-v3/ChangeLog:

* include/std/type_traits (is_void): Use __is_void built-in trait.

Signed-off-by: Ken Matsui 
---
 libstdc++-v3/include/std/type_traits | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index 9eafd6b16f2..98764685a39 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -294,6 +294,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // Primary type categories.
 
   /// is_void
+#if __has_builtin(__is_void)
+  template
+struct is_void
+: public __bool_constant<__is_void(_Tp)>
+{ };
+#else
   template
 struct is_void
 : public false_type { };
@@ -313,6 +319,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<>
 struct is_void
 : public true_type { };
+#endif
 
   /// @cond undocumented
   template
-- 
2.40.0



[PATCH v2 4/7] libstdc++: use new built-in trait __is_function for std::is_function

2023-03-30 Thread Ken Matsui via Gcc-patches
This patch gets std::is_function to dispatch to new built-in trait
__is_function.

libstdc++-v3/ChangeLog:

* include/std/type_traits (is_function): Use __is_function built-in
trait.

Signed-off-by: Ken Matsui 
---
 libstdc++-v3/include/std/type_traits | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index 58a732735c8..9eafd6b16f2 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -594,6 +594,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 { };
 
   /// is_function
+#if __has_builtin(__is_function)
+  template
+struct is_function
+: public __bool_constant<__is_function(_Tp)>
+{ };
+#else
   template
 struct is_function
 : public __bool_constant::value> { };
@@ -605,6 +611,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 struct is_function<_Tp&&>
 : public false_type { };
+#endif
 
 #define __cpp_lib_is_null_pointer 201309L
 
-- 
2.40.0



[PATCH v2 1/7] c++: implement __is_reference built-in trait

2023-03-30 Thread Ken Matsui via Gcc-patches
This patch implements built-in trait for std::is_reference.

gcc/cp/ChangeLog:

* cp-trait.def: Define __is_reference.
* constraint.cc (diagnose_trait_expr): Handle CPTK_IS_REFERENCE.
* semantics.cc (trait_expr_value): Likewise.
(finish_trait_expr): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/ext/has-builtin-1.C: Test existence of __is_reference.
* g++.dg/ext/is_reference.C: New test.

Signed-off-by: Ken Matsui 
---
 gcc/cp/constraint.cc |  3 +++
 gcc/cp/cp-trait.def  |  1 +
 gcc/cp/semantics.cc  |  4 +++
 gcc/testsuite/g++.dg/ext/has-builtin-1.C |  3 +++
 gcc/testsuite/g++.dg/ext/is_reference.C  | 34 
 5 files changed, 45 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/ext/is_reference.C

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 273d15ab097..23e5bc24dbb 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3701,6 +3701,9 @@ diagnose_trait_expr (tree expr, tree args)
 case CPTK_HAS_VIRTUAL_DESTRUCTOR:
   inform (loc, "  %qT does not have a virtual destructor", t1);
   break;
+case CPTK_IS_REFERENCE:
+  inform (loc, "  %qT is not a reference", t1);
+  break;
 case CPTK_IS_ABSTRACT:
   inform (loc, "  %qT is not an abstract class", t1);
   break;
diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
index bac593c0094..63a64152ce6 100644
--- a/gcc/cp/cp-trait.def
+++ b/gcc/cp/cp-trait.def
@@ -67,6 +67,7 @@ DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2)
 DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1)
 DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1)
 DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1)
+DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1)
 DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2)
 DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1)
 DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2)
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 99a76e3ed65..b17fbf8005d 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -11996,6 +11996,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree 
type2)
 case CPTK_IS_FINAL:
   return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
 
+case CPTK_IS_REFERENCE:
+  return type_code1 == REFERENCE_TYPE;
+
 case CPTK_IS_LAYOUT_COMPATIBLE:
   return layout_compatible_type_p (type1, type2);
 
@@ -12201,6 +12204,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, 
tree type1, tree type2)
 case CPTK_IS_ENUM:
 case CPTK_IS_UNION:
 case CPTK_IS_SAME:
+case CPTK_IS_REFERENCE:
   break;
 
 case CPTK_IS_LAYOUT_COMPATIBLE:
diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C 
b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
index f343e153e56..b697673790c 100644
--- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
+++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
@@ -146,3 +146,6 @@
 #if !__has_builtin (__remove_cvref)
 # error "__has_builtin (__remove_cvref) failed"
 #endif
+#if !__has_builtin (__is_reference)
+# error "__has_builtin (__is_reference) failed"
+#endif
diff --git a/gcc/testsuite/g++.dg/ext/is_reference.C 
b/gcc/testsuite/g++.dg/ext/is_reference.C
new file mode 100644
index 000..b5ce4db7afd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_reference.C
@@ -0,0 +1,34 @@
+// { dg-do compile { target c++11 } }
+
+#include 
+
+using namespace __gnu_test;
+
+#define SA(X) static_assert((X),#X)
+#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT)  \
+  SA(TRAIT(TYPE) == EXPECT);   \
+  SA(TRAIT(const TYPE) == EXPECT); \
+  SA(TRAIT(volatile TYPE) == EXPECT);  \
+  SA(TRAIT(const volatile TYPE) == EXPECT)
+
+// Positive tests.
+SA_TEST_CATEGORY(__is_reference, int&, true);
+SA_TEST_CATEGORY(__is_reference, ClassType&, true);
+SA(__is_reference(int(&)(int)));
+SA_TEST_CATEGORY(__is_reference, int&&, true);
+SA_TEST_CATEGORY(__is_reference, ClassType&&, true);
+SA(__is_reference(int(&&)(int)));
+SA_TEST_CATEGORY(__is_reference, IncompleteClass&, true);
+
+// Negative tests
+SA_TEST_CATEGORY(__is_reference, void, false);
+SA_TEST_CATEGORY(__is_reference, int*, false);
+SA_TEST_CATEGORY(__is_reference, int[3], false);
+SA(!__is_reference(int(int)));
+SA(!__is_reference(int(*const)(int)));
+SA(!__is_reference(int(*volatile)(int)));
+SA(!__is_reference(int(*const volatile)(int)));
+
+// Sanity check.
+SA_TEST_CATEGORY(__is_reference, ClassType, false);
+SA_TEST_CATEGORY(__is_reference, IncompleteClass, false);
-- 
2.40.0



[PATCH v2 3/7] c++: implement __is_function built-in trait

2023-03-30 Thread Ken Matsui via Gcc-patches
This patch implements built-in trait for std::is_function.

gcc/cp/ChangeLog:

* cp-trait.def: Define __is_function.
* constraint.cc (diagnose_trait_expr): Handle CPTK_IS_FUNCTION.
* semantics.cc (trait_expr_value): Likewise.
(finish_trait_expr): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/ext/has-builtin-1.C: Test existence of __is_function.
* g++.dg/ext/is_function.C: New test.

Signed-off-by: Ken Matsui 
---
 gcc/cp/constraint.cc |  3 ++
 gcc/cp/cp-trait.def  |  1 +
 gcc/cp/semantics.cc  |  4 ++
 gcc/testsuite/g++.dg/ext/has-builtin-1.C |  3 ++
 gcc/testsuite/g++.dg/ext/is_function.C   | 58 
 5 files changed, 69 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/ext/is_function.C

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 23e5bc24dbb..500ac9177c7 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3750,6 +3750,9 @@ diagnose_trait_expr (tree expr, tree args)
 case CPTK_IS_UNION:
   inform (loc, "  %qT is not a union", t1);
   break;
+case CPTK_IS_FUNCTION:
+  inform (loc, "  %qT is not a function", t1);
+  break;
 case CPTK_IS_AGGREGATE:
   inform (loc, "  %qT is not an aggregate", t1);
   break;
diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
index 63a64152ce6..99195201676 100644
--- a/gcc/cp/cp-trait.def
+++ b/gcc/cp/cp-trait.def
@@ -83,6 +83,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, 
"__is_trivially_assignable", 2)
 DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1)
 DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
 DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
+DEFTRAIT_EXPR (IS_FUNCTION, "__is_function", 1)
 DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, 
"__reference_constructs_from_temporary", 2)
 DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, 
"__reference_converts_from_temporary", 2)
 /* FIXME Added space to avoid direct usage in GCC 13.  */
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index b17fbf8005d..36fe370da2d 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -11993,6 +11993,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree 
type2)
 case CPTK_IS_ENUM:
   return type_code1 == ENUMERAL_TYPE;
 
+case CPTK_IS_FUNCTION:
+  return type_code1 == FUNCTION_TYPE;
+
 case CPTK_IS_FINAL:
   return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
 
@@ -12205,6 +12208,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, 
tree type1, tree type2)
 case CPTK_IS_UNION:
 case CPTK_IS_SAME:
 case CPTK_IS_REFERENCE:
+case CPTK_IS_FUNCTION:
   break;
 
 case CPTK_IS_LAYOUT_COMPATIBLE:
diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C 
b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
index b697673790c..90eb00ebf2d 100644
--- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
+++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
@@ -149,3 +149,6 @@
 #if !__has_builtin (__is_reference)
 # error "__has_builtin (__is_reference) failed"
 #endif
+#if !__has_builtin (__is_function)
+# error "__has_builtin (__is_function) failed"
+#endif
diff --git a/gcc/testsuite/g++.dg/ext/is_function.C 
b/gcc/testsuite/g++.dg/ext/is_function.C
new file mode 100644
index 000..2e1594b12ad
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_function.C
@@ -0,0 +1,58 @@
+// { dg-do compile { target c++11 } }
+
+#include 
+
+using namespace __gnu_test;
+
+#define SA(X) static_assert((X),#X)
+#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT)  \
+  SA(TRAIT(TYPE) == EXPECT);   \
+  SA(TRAIT(const TYPE) == EXPECT); \
+  SA(TRAIT(volatile TYPE) == EXPECT);  \
+  SA(TRAIT(const volatile TYPE) == EXPECT)
+
+struct A
+{ void fn(); };
+
+template
+struct AHolder { };
+
+template
+struct AHolder
+{ using type = U; };
+
+// Positive tests.
+SA(__is_function(int (int)));
+SA(__is_function(ClassType (ClassType)));
+SA(__is_function(float (int, float, int[], int&)));
+SA(__is_function(int (int, ...)));
+SA(__is_function(bool (ClassType) const));
+SA(__is_function(AHolder::type));
+
+void fn();
+SA(__is_function(decltype(fn)));
+
+// Negative tests.
+SA_TEST_CATEGORY(__is_function, int, false);
+SA_TEST_CATEGORY(__is_function, int*, false);
+SA_TEST_CATEGORY(__is_function, int&, false);
+SA_TEST_CATEGORY(__is_function, void, false);
+SA_TEST_CATEGORY(__is_function, void*, false);
+SA_TEST_CATEGORY(__is_function, void**, false);
+SA_TEST_CATEGORY(__is_function, std::nullptr_t, false);
+
+SA_TEST_CATEGORY(__is_function, AbstractClass, false);
+SA(!__is_function(int(&)(int)));
+SA(!__is_function(int(*)(int)));
+
+SA_TEST_CATEGORY(__is_function, A, false);
+SA_TEST_CATEGORY(__is_function, decltype(::fn), false);
+
+struct FnCallOverload
+{ void operator()(); };
+SA_TEST_CATEGORY(__is_function, FnCallOverload, false);
+
+// Sanity check.

[PATCH v2 0/7] c++, libstdc++: get std::is_object to dispatch to new built-in traits

2023-03-30 Thread Ken Matsui via Gcc-patches
Hi,

This patch series gets std::is_object to dispatch to built-in traits and
implements the following built-in traits, on which std::object depends.

* __is_reference
* __is_function
* __is_void

std::is_object was depending on them with disjunction and negation.

__not_<__or_, is_reference<_Tp>, is_void<_Tp>>>::type

Therefore, this patch uses them directly instead of implementing an additional
built-in trait __is_object, which makes the compiler slightly bigger and
slower.

__bool_constant

This would instantiate only __bool_constant and __bool_constant,
which can be mostly shared. That is, the purpose of built-in traits is
considered as achieved.

Changes in v2

* Stopped using std::is_void in helper_functions.h
* Squashed is_void-related commits into the commit of is_void 
implementation

Ken Matsui (7):
  c++: implement __is_reference built-in trait
  libstdc++: use new built-in trait __is_reference for std::is_reference
  c++: implement __is_function built-in trait
  libstdc++: use new built-in trait __is_function for std::is_function
  c++, libstdc++: implement __is_void built-in trait
  libstdc++: use new built-in trait __is_void for std::is_void
  libstdc++: make std::is_object dispatch to new built-in traits

 gcc/cp/constraint.cc  |  9 +++
 gcc/cp/cp-trait.def   |  3 +
 gcc/cp/semantics.cc   | 12 
 gcc/testsuite/g++.dg/ext/has-builtin-1.C  |  9 +++
 gcc/testsuite/g++.dg/ext/is_function.C| 58 +++
 gcc/testsuite/g++.dg/ext/is_reference.C   | 34 +++
 gcc/testsuite/g++.dg/ext/is_void.C| 35 +++
 gcc/testsuite/g++.dg/tm/pr46567.C |  6 +-
 libstdc++-v3/include/bits/cpp_type_traits.h   | 15 -
 libstdc++-v3/include/debug/helper_functions.h |  5 +-
 libstdc++-v3/include/std/type_traits  | 30 ++
 11 files changed, 195 insertions(+), 21 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/is_function.C
 create mode 100644 gcc/testsuite/g++.dg/ext/is_reference.C
 create mode 100644 gcc/testsuite/g++.dg/ext/is_void.C

-- 
2.40.0



[PATCH v2 2/7] libstdc++: use new built-in trait __is_reference for std::is_reference

2023-03-30 Thread Ken Matsui via Gcc-patches
This patch gets std::is_reference to dispatch to new built-in trait
__is_reference.

libstdc++-v3/ChangeLog:

* include/std/type_traits (is_reference): Use __is_reference built-in
trait.

Signed-off-by: Ken Matsui 
---
 libstdc++-v3/include/std/type_traits | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index 2bd607a8b8f..58a732735c8 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -639,6 +639,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // Composite type categories.
 
   /// is_reference
+#if __has_builtin(__is_reference)
+  template
+struct is_reference
+: public __bool_constant<__is_reference(_Tp)>
+{ };
+#else
   template
 struct is_reference
 : public false_type
@@ -653,6 +659,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 struct is_reference<_Tp&&>
 : public true_type
 { };
+#endif
 
   /// is_arithmetic
   template
-- 
2.40.0



[PATCH 0/7] c++, libstdc++: get std::is_object to dispatch to new built-in traits

2023-03-30 Thread Ken Matsui via Gcc-patches
Hi,

This patch series gets std::is_object to dispatch to built-in traits and
implements the following built-in traits, on which std::object depends.

* __is_reference
* __is_function
* __is_void

std::is_object was depending on them with disjunction and negation.

__not_<__or_, is_reference<_Tp>, is_void<_Tp>>>::type

Therefore, this patch uses them directly instead of implementing an additional
built-in trait __is_object, which makes the compiler slightly bigger and
slower.

__bool_constant

This would instantiate only __bool_constant and __bool_constant,
which can be mostly shared. That is, the purpose of built-in traits is
considered as achieved.

Ken Matsui (7):
  c++: implement __is_reference built-in trait
  libstdc++: use new built-in trait __is_reference for std::is_reference
  c++: implement __is_function built-in trait
  libstdc++: use new built-in trait __is_function for std::is_function
  c++, libstdc++: implement __is_void built-in trait
  libstdc++: use new built-in trait __is_void for std::is_void
  libstdc++: make std::is_object dispatch to new built-in traits

 gcc/cp/constraint.cc  |  9 +++
 gcc/cp/cp-trait.def   |  3 +
 gcc/cp/semantics.cc   | 12 
 gcc/testsuite/g++.dg/ext/has-builtin-1.C  |  9 +++
 gcc/testsuite/g++.dg/ext/is_function.C| 58 +++
 gcc/testsuite/g++.dg/ext/is_reference.C   | 34 +++
 gcc/testsuite/g++.dg/ext/is_void.C| 35 +++
 gcc/testsuite/g++.dg/tm/pr46567.C |  6 +-
 libstdc++-v3/include/bits/cpp_type_traits.h   | 15 -
 libstdc++-v3/include/debug/helper_functions.h |  5 +-
 libstdc++-v3/include/std/type_traits  | 30 ++
 11 files changed, 195 insertions(+), 21 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/is_function.C
 create mode 100644 gcc/testsuite/g++.dg/ext/is_reference.C
 create mode 100644 gcc/testsuite/g++.dg/ext/is_void.C

-- 
2.40.0



Re: [PATCH] Fix fc-prototypes usage with C_INT64_T and non LP64 Targets.

2023-03-30 Thread Thomas Koenig via Gcc-patches

Hi Andrew,


"long long". This was just an oversight and a missing check.

Committed as obvious after a bootstrap/test on x86_64-linux-gnu.


Thanks!

I think this one is obvious enough that it deserves a backport.
I've cherry-picked this for gcc12, will do gcc11 tomorrow.

Best regards

Thomas


Re: [PATCH] c++tools: Fix Makefile to properly clean and rebuild [PR101834]

2023-03-30 Thread Segher Boessenkool
On Thu, Mar 30, 2023 at 01:15:46PM +0100, Jonathan Wakely wrote:
> The c++tools makefile doesn't remove progressively more files in each of
> mostlyclean, clean, and distclean. Instead, each removes a different set
> of files (and some files are not removed by any target). Use
> prerequisites so that everything is removed.

This solves the PR (PR101834).  Thanks!


Segher


Re: recomputation and PR 109154

2023-03-30 Thread Jakub Jelinek via Gcc-patches
On Thu, Mar 30, 2023 at 11:58:19AM -0400, Andrew MacLeod wrote:
> 
> On 3/30/23 09:41, Jakub Jelinek wrote:
> > On Wed, Mar 29, 2023 at 01:22:27PM -0400, Andrew MacLeod wrote:
> > > however, as seems to be the case often, better ranges result in, I now 
> > > get:
> > > 
> > > FAIL: 23_containers/vector/bool/allocator/copy.cc (test for excess errors)
> > Our middle-end warnings are just badly designed :(, the better value ranges
> > are, the more false positives they have.
> > 
> > > commit 358d0ca44faf2e20fbacd0f74386308b5ca52cd4
> > > Author: Andrew MacLeod 
> > > Date:   Tue Mar 28 12:16:34 2023 -0400
> > > 
> > >  Add recursive GORI recompuations with a depth limit.
> > LGTM for trunk, let's do with the regression incrementally.
> > Or as Richard mentioned on IRC, one possibility would be to force this
> > param temporarily to 1 (or whatever matches previous behavior) for the
> > diagnostic range queries).
> > 
> > You need a ChangeLog entry though...
> > 
> Attached. I also removed the bogus warning in Walloc-13.c that no longer
> happens
> 
> So incrementally deal with it.. what? just let it fail?

For today?  Yes.

Ok for trunk.

> commit debb8ce1f9b9d5a72d88d0ae90a6b4da5130ff59
> Author: Andrew MacLeod 
> Date:   Tue Mar 28 12:16:34 2023 -0400
> 
> Add recursive GORI recompuations with a depth limit.
> 
> PR tree-optimization/109154
> gcc/
> * gimple-range-gori.cc (gori_compute::may_recompute_p): Add depth 
> limit.
> * gimple-range-gori.h (may_recompute_p): Add depth param.
> * params.opt (ranger-recompute-depth): New param.
> 
> gcc/testsuite/
> * gcc.dg/Walloca-13.c: Remove bogus warning that is now fixed.

Jakub



Re: [committed] libstdc++: Fix constexpr functions in

2023-03-30 Thread Daniel Krügler via Gcc-patches
Am Do., 30. März 2023 um 18:00 Uhr schrieb Jonathan Wakely via
Libstdc++ :
>
[..]
>
> In fact, thinking about P2641 some more, I might revert this change.
> Instead of adding an extra bool member to support constexpr, I think
> I'll just remove the 'constexpr' keywords from basic_endpoint for now,
> and implement it in terms of just inspecting the sa_family_t member of
> the union members. And then later, once we have something like P2641,
> we can re-add the constexpr keywords and use is_within_lifetime during
> constant evaluation. That way we don't add a bool then need to take it
> away again, changing the ABI each time.

I was just going to make the same suggestion.

- Daniel


Re: [committed] libstdc++: Fix constexpr functions in

2023-03-30 Thread Jonathan Wakely via Gcc-patches
On Thu, 30 Mar 2023 at 15:44, Jonathan Wakely wrote:
>
> On Thu, 30 Mar 2023 at 00:40, Jonathan Wakely via Libstdc++
>  wrote:
> >
> > Tested powerpc64le-linux. Pushed to trunk.
> >
> > -- >8 --
> >
> > Change ip::basic_endpoint to work in constant expressions, but only for
> > C++20 and later (due to the use of a union, which cannot change active
> > member in constexpr evaluation until C++20).
> >
> > During constant evaluation we cannot inspect the common initial sequence
> > of basic_endpoint's union members to check whether sin_family == AF_INET
> > or AF_INET6.  This means we need to store an additional boolean member
> > that remembers whether we have a v4 or v6 address. The address type can
> > change behind our backs if a user copies an address to the data()
> > pointer and then calls resize(n), so we need to inspect the sa_family_t
> > member in the union after a resize and update the boolean. POSIX only
> > guarantees that the sa_family_t member of each protocol-specific address
> > structure is at the same offset and of the same type, not that there is
> > a common initial sequence. The check in resize is done using memcmp, so
> > that we avoid accessing an inactive member of the union if the
> > sockaddr_in and sockaddr_in6 structures do not have a common initial
> > sequence that includes the sa_family_t member.
>
> If we had 
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2641r2.html
> then we wouldn't need the extra boolean. During constant evaluation we
> could use the new magic function to check which union member is
> active, and during runtime we could inspect the sa_family_t member
> (still using memcmp, because POSIX doesn't guarantee a common initial
> sequence, even though I think everybody does give it one in practice).

In fact, thinking about P2641 some more, I might revert this change.
Instead of adding an extra bool member to support constexpr, I think
I'll just remove the 'constexpr' keywords from basic_endpoint for now,
and implement it in terms of just inspecting the sa_family_t member of
the union members. And then later, once we have something like P2641,
we can re-add the constexpr keywords and use is_within_lifetime during
constant evaluation. That way we don't add a bool then need to take it
away again, changing the ABI each time.



Re: recomputation and PR 109154

2023-03-30 Thread Andrew MacLeod via Gcc-patches


On 3/30/23 09:41, Jakub Jelinek wrote:

On Wed, Mar 29, 2023 at 01:22:27PM -0400, Andrew MacLeod wrote:

however, as seems to be the case often, better ranges result in, I now get:

FAIL: 23_containers/vector/bool/allocator/copy.cc (test for excess errors)

Our middle-end warnings are just badly designed :(, the better value ranges
are, the more false positives they have.


commit 358d0ca44faf2e20fbacd0f74386308b5ca52cd4
Author: Andrew MacLeod 
Date:   Tue Mar 28 12:16:34 2023 -0400

 Add recursive GORI recompuations with a depth limit.

LGTM for trunk, let's do with the regression incrementally.
Or as Richard mentioned on IRC, one possibility would be to force this
param temporarily to 1 (or whatever matches previous behavior) for the
diagnostic range queries).

You need a ChangeLog entry though...

Attached. I also removed the bogus warning in Walloc-13.c that no longer 
happens


So incrementally deal with it.. what? just let it fail?

Andrew
commit debb8ce1f9b9d5a72d88d0ae90a6b4da5130ff59
Author: Andrew MacLeod 
Date:   Tue Mar 28 12:16:34 2023 -0400

Add recursive GORI recompuations with a depth limit.

PR tree-optimization/109154
gcc/
* gimple-range-gori.cc (gori_compute::may_recompute_p): Add depth limit.
* gimple-range-gori.h (may_recompute_p): Add depth param.
* params.opt (ranger-recompute-depth): New param.

gcc/testsuite/
* gcc.dg/Walloca-13.c: Remove bogus warning that is now fixed.

diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc
index 6e8dfa85ca8..5f4313b27dd 100644
--- a/gcc/gimple-range-gori.cc
+++ b/gcc/gimple-range-gori.cc
@@ -1308,7 +1308,7 @@ gori_compute::compute_operand1_and_operand2_range (vrange ,
 // direct dependent is exported, it may also change the computed value of NAME.
 
 bool
-gori_compute::may_recompute_p (tree name, basic_block bb)
+gori_compute::may_recompute_p (tree name, basic_block bb, int depth)
 {
   tree dep1 = depend1 (name);
   tree dep2 = depend2 (name);
@@ -1322,22 +1322,36 @@ gori_compute::may_recompute_p (tree name, basic_block bb)
   if (is_a (s) || gimple_has_side_effects (s))
 return false;
 
-  // If edge is specified, check if NAME can be recalculated on that edge.
-  if (bb)
-return ((is_export_p (dep1, bb))
-	|| (dep2 && is_export_p (dep2, bb)));
+  if (!dep2)
+{
+  // -1 indicates a default param, convert it to the real default.
+  if (depth == -1)
+	{
+	  depth = (int)param_ranger_recompute_depth;
+	  gcc_checking_assert (depth >= 1);
+	}
 
-  return (is_export_p (dep1)) || (dep2 && is_export_p (dep2));
+  bool res = (bb ? is_export_p (dep1, bb) : is_export_p (dep1));
+  if (res || depth <= 1)
+	return res;
+  // Check another level of recomputation.
+  return may_recompute_p (dep1, bb, --depth);
+}
+  // Two dependencies terminate the depth of the search.
+  if (bb)
+return is_export_p (dep1, bb) || is_export_p (dep2, bb);
+  else
+return is_export_p (dep1) || is_export_p (dep2);
 }
 
 // Return TRUE if NAME can be recomputed on edge E.  If any direct dependent
 // is exported on edge E, it may change the computed value of NAME.
 
 bool
-gori_compute::may_recompute_p (tree name, edge e)
+gori_compute::may_recompute_p (tree name, edge e, int depth)
 {
   gcc_checking_assert (e);
-  return may_recompute_p (name, e->src);
+  return may_recompute_p (name, e->src, depth);
 }
 
 
diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h
index 0fc90ec8a18..3ea4b45595b 100644
--- a/gcc/gimple-range-gori.h
+++ b/gcc/gimple-range-gori.h
@@ -172,8 +172,8 @@ private:
   bool refine_using_relation (tree op1, vrange _range,
 			  tree op2, vrange _range,
 			  fur_source , relation_kind k);
-  bool may_recompute_p (tree name, edge e);
-  bool may_recompute_p (tree name, basic_block bb = NULL);
+  bool may_recompute_p (tree name, edge e, int depth = -1);
+  bool may_recompute_p (tree name, basic_block bb = NULL, int depth = -1);
   bool compute_operand_range_switch (vrange , gswitch *s, const vrange ,
  tree name, fur_source );
   bool compute_operand1_range (vrange , gimple_range_op_handler ,
diff --git a/gcc/params.opt b/gcc/params.opt
index 2329d150ef0..b2ec436546c 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -900,6 +900,11 @@ Common Joined UInteger Var(param_ranger_logical_depth) Init(6) IntegerRange(1, 9
 Maximum depth of logical expression evaluation ranger will look through when
 evaluating outgoing edge ranges.
 
+-param=ranger-recompute-depth=
+Common Joined UInteger Var(param_ranger_recompute_depth) Init(5) IntegerRange(1, 100) Param Optimization
+Maximum depth of instruction chains to consider for recomputation in the
+outgoing range calculator.
+
 -param=relation-block-limit=
 Common Joined UInteger Var(param_relation_block_limit) Init(200) IntegerRange(0, ) Param Optimization
 Maximum number of relations the oracle will register in a basic block.

Re: [PATCH v2] rtl-optimization: ppc backend generates unnecessary extension.

2023-03-30 Thread Segher Boessenkool
Hi!

On Thu, Mar 30, 2023 at 04:28:51PM +0200, Bernhard Reutner-Fischer wrote:
> On Thu, 30 Mar 2023 17:30:43 +0530
> Ajit Agarwal via Gcc-patches  wrote:
> > * ree.cc(is_feasible_elim_across_basic_blocks):
> 
> We often use the lispy _p suffix for predicates.
> Maybe eliminate_across_bbs_p would be shorter.

A bit shorter, but much less clear, and that is the actual reason to
keep names short -- so this misses the goal.  Also, many things
currently called _p are not predicates (and/or in some cases are not
even functions!)

> > +  if (use == NULL) return NULL;
> 
> Missing newline before return.

And better style is
  if (!use)

> > +#if 0
> >  /* Get all the reaching definitions of an instruction.  The definitions are
> > desired for REG used in INSN.  Return the definition list or NULL if a
> > definition is missing.  If DEST is non-NULL, additionally push the INSN
> > @@ -593,7 +646,7 @@ get_defs (rtx_insn *insn, rtx reg, vec 
> > *dest)
> >  
> >return ref_chain;
> >  }
> > -
> > +#endif
> 
> Why did you move get_defs?

And we should not normally have #if 0, too.


Segher


Re: [committed] libstdc++: Fix constexpr functions in

2023-03-30 Thread Jonathan Wakely via Gcc-patches
On Thu, 30 Mar 2023 at 00:40, Jonathan Wakely via Libstdc++
 wrote:
>
> Tested powerpc64le-linux. Pushed to trunk.
>
> -- >8 --
>
> Change ip::basic_endpoint to work in constant expressions, but only for
> C++20 and later (due to the use of a union, which cannot change active
> member in constexpr evaluation until C++20).
>
> During constant evaluation we cannot inspect the common initial sequence
> of basic_endpoint's union members to check whether sin_family == AF_INET
> or AF_INET6.  This means we need to store an additional boolean member
> that remembers whether we have a v4 or v6 address. The address type can
> change behind our backs if a user copies an address to the data()
> pointer and then calls resize(n), so we need to inspect the sa_family_t
> member in the union after a resize and update the boolean. POSIX only
> guarantees that the sa_family_t member of each protocol-specific address
> structure is at the same offset and of the same type, not that there is
> a common initial sequence. The check in resize is done using memcmp, so
> that we avoid accessing an inactive member of the union if the
> sockaddr_in and sockaddr_in6 structures do not have a common initial
> sequence that includes the sa_family_t member.

If we had https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2641r2.html
then we wouldn't need the extra boolean. During constant evaluation we
could use the new magic function to check which union member is
active, and during runtime we could inspect the sa_family_t member
(still using memcmp, because POSIX doesn't guarantee a common initial
sequence, even though I think everybody does give it one in practice).



Re: [PATCH v2] rtl-optimization: ppc backend generates unnecessary extension.

2023-03-30 Thread Bernhard Reutner-Fischer via Gcc-patches
On Thu, 30 Mar 2023 17:30:43 +0530
Ajit Agarwal via Gcc-patches  wrote:

> Hello All:

Just some nits.

And this seems to be an incremental diff ontop of your v2.
You might want check for coding-style errors by running:
 contrib/check_GNU_style.py /tmp/ree-v2bis.patch

> 
> This patch added enhancement to extimination elimination for rs6000 target.

I think REE means redundant extension elimination.

> gcc/ChangeLog:
> 
>   * ree.cc(is_feasible_elim_across_basic_blocks):

We often use the lispy _p suffix for predicates.
Maybe eliminate_across_bbs_p would be shorter.

>   Add checks to enable extension elimination..
>   * ree.cc(combine_reaching_defs): Add checks to enable
>   extension elimination.
> ---
>  gcc/ree.cc | 121 ++---
>  1 file changed, 116 insertions(+), 5 deletions(-)
> 
> diff --git a/gcc/ree.cc b/gcc/ree.cc
> index d05d37f9a23..7e4cce5cee4 100644
> --- a/gcc/ree.cc
> +++ b/gcc/ree.cc
> @@ -253,6 +253,56 @@ struct ext_cand
>  
>  static int max_insn_uid;
>  
> +/* Get all the reaching definitions of an instruction.  The definitions are
> +   desired for REG used in INSN.  Return the definition list or NULL if a
> +   definition is missing.  If DEST is non-NULL, additionally push the INSN
> +   of the definitions onto DEST.  */
> +
> +static struct df_link *
> +get_defs (rtx_insn *insn, rtx reg, vec *dest)
> +{
> +  df_ref use;
> +  struct df_link *ref_chain, *ref_link;
> +
> +  FOR_EACH_INSN_USE (use, insn)
> +{
> +  if (GET_CODE (DF_REF_REG (use)) == SUBREG)
> + return NULL;
> +  if (REGNO (DF_REF_REG (use)) == REGNO (reg))
> + break;
> +}
> +
> +  if (use == NULL) return NULL;

Missing newline before return.

> +
> +  gcc_assert (use != NULL);

Either the assert or the if but both is a bit much.

> +
> +  ref_chain = DF_REF_CHAIN (use);
> +
> +  for (ref_link = ref_chain; ref_link; ref_link = ref_link->next)
> +{
> +  /* Problem getting some definition for this instruction.  */
> +  if (ref_link->ref == NULL)
> + return NULL;
> +  if (DF_REF_INSN_INFO (ref_link->ref) == NULL)
> + return NULL;
> +  /* As global regs are assumed to be defined at each function call
> +  dataflow can report a call_insn as being a definition of REG.
> +  But we can't do anything with that in this pass so proceed only
> +  if the instruction really sets REG in a way that can be deduced
> +  from the RTL structure.  */
> +  if (global_regs[REGNO (reg)]
> +   && !set_of (reg, DF_REF_INSN (ref_link->ref)))
> + return NULL;
> +}
> +
> +  if (dest)
> +for (ref_link = ref_chain; ref_link; ref_link = ref_link->next)
> +  dest->safe_push (DF_REF_INSN (ref_link->ref));
> +
> +  return ref_chain;
> +}
> +
> +
>  /* Identify instruction AND with identical zero extension.  */
>  
>  static unsigned int
> @@ -393,6 +443,7 @@ combine_set_extension (ext_cand *cand, rtx_insn 
> *curr_insn, rtx *orig_set)
>machine_mode orig_mode = GET_MODE (SET_DEST (*orig_set));
>rtx new_set = NULL_RTX;
>rtx cand_pat = single_set (cand->insn);
> +

superfluous whitespace change.

>if (insn_is_zext_p(cand->insn)
> && CONST_INT_P (orig_src) && INTVAL (orig_src) != 0)
>  return false;
> @@ -401,6 +452,7 @@ combine_set_extension (ext_cand *cand, rtx_insn 
> *curr_insn, rtx *orig_set)
>   then we need to change the original load to reference the destination
>   of the extension.  Then we need to emit a copy from that destination
>   to the original destination of the load.  */
> + // print_rtl_single(stdout, cand_pat);

Please remove that debug comment.

>rtx new_reg;
>bool copy_needed
>  = (REGNO (SET_DEST (cand_pat)) != REGNO (XEXP (SET_SRC (cand_pat), 0)));
> @@ -547,6 +599,7 @@ transform_ifelse (ext_cand *cand, rtx_insn *def_insn)
>return false;
>  }
>  
> +#if 0
>  /* Get all the reaching definitions of an instruction.  The definitions are
> desired for REG used in INSN.  Return the definition list or NULL if a
> definition is missing.  If DEST is non-NULL, additionally push the INSN
> @@ -593,7 +646,7 @@ get_defs (rtx_insn *insn, rtx reg, vec *dest)
>  
>return ref_chain;
>  }
> -
> +#endif

Why did you move get_defs?

>  /* Get all the reaching uses of an instruction.  The uses are desired for REG
> set in INSN.  Return use list or NULL if a use is missing or irregular.  
> */
>  
> @@ -848,6 +901,36 @@ is_feasible_elim_across_basic_blocks (ext_cand *cand,
>   && REGNO (XEXP (PATTERN (BB_END (bb)), 0)) != REGNO (SET_DEST 
> (cand->expr)))
>   return false;
>  
> +   if (cand->code == ZERO_EXTEND
> + && GET_CODE ((PATTERN (def_insn))) == PARALLEL)
> + return false;

Excess braces above.

> +
> +   if (cand->code == ZERO_EXTEND
> + && GET_CODE ((PATTERN (def_insn))) == SET

Excess braces above.

> + && GET_CODE (SET_SRC (PATTERN (def_insn))) != XOR)
> + return false;
> +
> +   if (cand->code 

Re: 'g++.dg/modules/modules.exp': don't leak local 'unsupported' proc [PR108899]

2023-03-30 Thread Alexandre Oliva via Gcc-patches
On Mar 30, 2023, Alexandre Oliva  wrote:

> If we're dropping the renaming, I suppose we could also revert Jakub's
> change.  I suppose this patch will take care of it, pending testing...

Regstrapped on x86_64-linux-gnu and also tested on arm-vx7r2 (with
gcc-12), where I used to get fails after an unsupported modules.exp
test, but there are no curly braces in the log files after the patch.
Ok to install?


[PR108899] testsuite: fix proc unsupported overriding in modules.exp

The overrider of proc unsupported in modules.exp had two problems
reported by Thomas Schwinge, even after Jakub Jelínek's fix:

- it remained in effect while running other dejagnu testsets

- it didn't quote correctly the argument list passed to it, which
  caused test names to be surrounded by curly braces, as in:

UNSUPPORTED: {...}

This patch fixes both issues, obsoleting and reverting Jakub's change,
by dropping the overrider and renaming the saved proc back, and by
using uplevel's argument list splicing.


for  gcc/testsuite/ChangeLog

PR testsuite/108899
* g++.dg/modules/modules.exp (unsupported): Drop renaming.
Fix quoting.
---
 gcc/testsuite/g++.dg/modules/modules.exp |   20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/gcc/testsuite/g++.dg/modules/modules.exp 
b/gcc/testsuite/g++.dg/modules/modules.exp
index 80aa392bc7f3b..dc302d3d0af48 100644
--- a/gcc/testsuite/g++.dg/modules/modules.exp
+++ b/gcc/testsuite/g++.dg/modules/modules.exp
@@ -319,15 +319,11 @@ cleanup_module_files [find $DEFAULT_REPO *.gcm]
 # so that, after an unsupported result in dg-test, we can skip rather
 # than fail subsequent related tests.
 set module_do {"compile" "P"}
-if { [info procs unsupported] != [list] \
-  && [info procs saved-unsupported] == [list] } {
-rename unsupported saved-unsupported
-
-proc unsupported { args } {
-   global module_do
-   lset module_do 1 "N"
-   return [saved-unsupported $args]
-}
+rename unsupported modules-saved-unsupported
+proc unsupported { args } {
+global module_do
+lset module_do 1 "N"
+return [uplevel 1 modules-saved-unsupported $args]
 }
 
 # not grouped tests, sadly tcl doesn't have negated glob
@@ -412,4 +408,10 @@ foreach src [lsort [find $srcdir/$subdir {*_a.[CHX}]] {
 }
 }
 
+# Restore the original unsupported proc, lest it will affect
+# subsequent test runs, or even fail renaming if we run modules.exp
+# for multiple targets/multilibs/options.
+rename unsupported {}
+rename modules-saved-unsupported unsupported
+
 dg-finish


-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


Re: [PATCH] Introduce -nolibstdc++ option

2023-03-30 Thread Arsen Arsenović via Gcc-patches
Hi Alexandre,

Alexandre Oliva via Gcc-patches  writes:

> Hello, Gerald,
>
> On Feb 11, 2023, Gerald Pfeifer  wrote:
>
>> On Thu, 23 Jun 2022, Alexandre Oliva via Gcc-patches wrote:
>>> Introduce -nostdlib++ option
>>> 
>>> Using g++ to link without libstdc++, as in g++.dg/abi/pure-virtual1.C,
>>> is error prone, because there's no way to tell g++ to drop libstdc++
>>> without also dropping libc and any other libraries that the target
>>> implicitly links in.
>
>> % grep -r nostdlib $WWWDOCS
>> %
>
>> Should this be documented in gcc-13/changes.html? Would you mind proposing 
>> a snippet (or going ahead and pushing it)?
>
> I can't make my mind up about this.
>
> At first, the goal of adding the option was just to aid this specific
> test.  But then, it transpired that other compilers offered a similar
> option, with the spelling that we ended up using, so perhaps it would
> make sense to document it, after all.

IMO, yes - in fact, the libstdc++ manual even has a use-case for this
(freestanding when the compiler is *not* built with libstdc++ in
freestanding mode) and documents using the gcc driver rather than the
g++ one.  See libstdc++-v3/doc/xml/manual/using.xml:

  If you're using a libstdc++ configured for hosted environments, and
  would like to not involve the libraries libstdc++ would depend on in
  your programs, you will need to use gcc to link your
  application with only libsupc++.a,
  like so:

If you think the flag you added fits here, would you mind also including
this file in your patch?

Note that this flag is only applicable here if MATH_LIBRARY is omitted
but libsupc++.a is kept on the linker command line (apologies for
not checking ahead of writing this email - I'm not currently in a
convenient spot to do so).

Thanks in advance, have a lovely day.

> How about this, does this seem useful?
>
> diff --git a/htdocs/gcc-13/changes.html b/htdocs/gcc-13/changes.html
> index ff70d2eefecec..c1bbbfa28e18e 100644
> --- a/htdocs/gcc-13/changes.html
> +++ b/htdocs/gcc-13/changes.html
> @@ -333,6 +333,9 @@ a work-in-progress.
>The  href="https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-Wpessimizing-move;>-Wpessimizing-move
>  and  href="https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-Wredundant-move;>-Wredundant-move
>  warnings have been extended to warn in more contexts.
> +  The  href="https://gcc.gnu.org/onlinedocs/gcc/Link_Options.html#index-nostdlib_002b_002b;>-nostdlib++
> +option has been added, to enable linking with g++
> +without implicitly linking in the C++ standard library.
>  
>  
>  Runtime Library (libstdc++)


-- 
Arsen Arsenović


signature.asc
Description: PGP signature


Re: [PATCH v2] rtl-optimization: ppc backend generates unnecessary extension.

2023-03-30 Thread Segher Boessenkool
Hi!

On Tue, Mar 28, 2023 at 10:19:27PM +0530, Ajit Agarwal wrote:
> This patch makes REE pass as a default pass in rs6000 target. And
> add necessary subroutines to eliminate extensions across basic blocks.

Please wait with this until stage 1?

Some comments:

>   rtl-optimization: ppc backend generates unnecessary
>   extension.

Subject can start with "ree: ", but not "rtl-optimization: ".  Subject
should start with a capital (the part after the colon, that is).  There
should not be a full stop in the subject.

Subjects should be in the mail subject, not elsewhere in the patch.

>   Eliminate unnecessary redundant zero extension across basic
>   blocks.

Not sure where you want this?  It doesn't belong in the changelog.

>   * ree.cc(insn_s_zext_p): New function.

Space before (.

>   * ree.cc(is_feasible_elim_across_basic_blocks):
>   New function.

This is the same file as the one before this.  You write that as
(is_feasible_elim_across_basic_blocks): New function.

(and no early line breaks please, certainly not after a colon).

>   * common/config/rs6000/rs6000-common.cc: Add free pass
>   as default pass in rs6000 target.

Changelog lines are 80 positions.  The leading tab is 8 positions.

> @@ -30,6 +30,8 @@
>  /* Implement TARGET_OPTION_OPTIMIZATION_TABLE.  */
>  static const struct default_options rs6000_option_optimization_table[] =
>{
> +/* Enable -free for zero extension and sign extension elimination.*/
> +{ OPT_LEVELS_2_PLUS, OPT_free, NULL, 1 },

>  /* Split multi-word types early.  */
>  { OPT_LEVELS_ALL, OPT_fsplit_wide_types_early, NULL, 1 },
>  /* Enable -fsched-pressure for first pass instruction scheduling.  */
> @@ -42,7 +44,6 @@ static const struct default_options 
> rs6000_option_optimization_table[] =
>  /* -frename-registers leads to non-optimal codegen and performance
> on rs6000, turn it off by default.  */
>  { OPT_LEVELS_ALL, OPT_frename_registers, NULL, 0 },
> -

Don't remove random lines please.  Never do this as part of unrelated
patches, too.

> +/* Identify instruction AND with identical zero extension.  */

What does that mean?

> +
> +static unsigned int
> +insn_is_zext_p(rtx insn)

Space before (.  If it is an insn, you probably want rtx_insn?

> +{
> +  if (GET_CODE (insn) == AND)
> +   {

Wrong indentation.

> + rtx set = XEXP (insn, 0);
> + if (REG_P(set))
> +   {
> +  if (CONST_INT_P (XEXP (insn, 1))

You can see that here: all indentations are a multiple of two, so a
single space indent is always wrong.

> +  && INTVAL (XEXP (insn, 1)) == 1)

This easily fits on the previous line.

> +return 1;
> +   }
> + else
> +   return 0;
> +   }
> +
> +  return 0;
> +}

Don't "else return 0" if you have a catch-all anyway?

> +/* Identify instruction AND with identical zero extension.  */
> +
> +static unsigned int
> +insn_is_zext_p(rtx_insn * insn)

No space after * for a pointer.

> +{
> +  rtx body = PATTERN (insn);
> +
> +  if (GET_CODE (body) == PARALLEL) return 0;

Always a new line before an "if" body.

> +  if (GET_CODE(body) == SET && GET_CODE (SET_SRC (body)) == AND)
> +   {
> + rtx set = XEXP (SET_SRC(body), 0);
> +
> + if (REG_P(set) && GET_MODE(SET_DEST(body))
> +  == GET_MODE(set))

What is this for?

> +   {
> +  if (CONST_INT_P (XEXP (SET_SRC (body), 1))
> +   && INTVAL (XEXP (SET_SRC (body), 1)) == 1)

The && should align with the previous "C".

You could just say
  if (XEXP (SET_SRC (body), 1) == const1_rtx)
.

> +  if (insn_is_zext_p(cand->insn)
> +   && CONST_INT_P (orig_src) && INTVAL (orig_src) != 0)
> +return false;

  if (insn_is_zext_p (cand->insn) && orig_src != const0_rtx)
return false;


So what is this patch doing?  At least two things, right?  It aims to
improve what REE does, and also enables it by default for rs6000?  So
make it two patches, please.

Can you talk a bit about what improvements to generated code you see?


Segher


Re: recomputation and PR 109154

2023-03-30 Thread Jakub Jelinek via Gcc-patches
On Wed, Mar 29, 2023 at 01:22:27PM -0400, Andrew MacLeod wrote:
> however, as seems to be the case often, better ranges result in, I now get:
> 
> FAIL: 23_containers/vector/bool/allocator/copy.cc (test for excess errors)

Our middle-end warnings are just badly designed :(, the better value ranges
are, the more false positives they have.

> commit 358d0ca44faf2e20fbacd0f74386308b5ca52cd4
> Author: Andrew MacLeod 
> Date:   Tue Mar 28 12:16:34 2023 -0400
> 
> Add recursive GORI recompuations with a depth limit.

LGTM for trunk, let's do with the regression incrementally.
Or as Richard mentioned on IRC, one possibility would be to force this
param temporarily to 1 (or whatever matches previous behavior) for the
diagnostic range queries).

You need a ChangeLog entry though...

> diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc
> index 6e8dfa85ca8..5f4313b27dd 100644
> --- a/gcc/gimple-range-gori.cc
> +++ b/gcc/gimple-range-gori.cc
> @@ -1308,7 +1308,7 @@ gori_compute::compute_operand1_and_operand2_range 
> (vrange ,
>  // direct dependent is exported, it may also change the computed value of 
> NAME.
>  
>  bool
> -gori_compute::may_recompute_p (tree name, basic_block bb)
> +gori_compute::may_recompute_p (tree name, basic_block bb, int depth)
>  {
>tree dep1 = depend1 (name);
>tree dep2 = depend2 (name);
> @@ -1322,22 +1322,36 @@ gori_compute::may_recompute_p (tree name, basic_block 
> bb)
>if (is_a (s) || gimple_has_side_effects (s))
>  return false;
>  
> -  // If edge is specified, check if NAME can be recalculated on that edge.
> -  if (bb)
> -return ((is_export_p (dep1, bb))
> - || (dep2 && is_export_p (dep2, bb)));
> +  if (!dep2)
> +{
> +  // -1 indicates a default param, convert it to the real default.
> +  if (depth == -1)
> + {
> +   depth = (int)param_ranger_recompute_depth;
> +   gcc_checking_assert (depth >= 1);
> + }
>  
> -  return (is_export_p (dep1)) || (dep2 && is_export_p (dep2));
> +  bool res = (bb ? is_export_p (dep1, bb) : is_export_p (dep1));
> +  if (res || depth <= 1)
> + return res;
> +  // Check another level of recomputation.
> +  return may_recompute_p (dep1, bb, --depth);
> +}
> +  // Two dependencies terminate the depth of the search.
> +  if (bb)
> +return is_export_p (dep1, bb) || is_export_p (dep2, bb);
> +  else
> +return is_export_p (dep1) || is_export_p (dep2);
>  }
>  
>  // Return TRUE if NAME can be recomputed on edge E.  If any direct dependent
>  // is exported on edge E, it may change the computed value of NAME.
>  
>  bool
> -gori_compute::may_recompute_p (tree name, edge e)
> +gori_compute::may_recompute_p (tree name, edge e, int depth)
>  {
>gcc_checking_assert (e);
> -  return may_recompute_p (name, e->src);
> +  return may_recompute_p (name, e->src, depth);
>  }
>  
>  
> diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h
> index 0fc90ec8a18..3ea4b45595b 100644
> --- a/gcc/gimple-range-gori.h
> +++ b/gcc/gimple-range-gori.h
> @@ -172,8 +172,8 @@ private:
>bool refine_using_relation (tree op1, vrange _range,
> tree op2, vrange _range,
> fur_source , relation_kind k);
> -  bool may_recompute_p (tree name, edge e);
> -  bool may_recompute_p (tree name, basic_block bb = NULL);
> +  bool may_recompute_p (tree name, edge e, int depth = -1);
> +  bool may_recompute_p (tree name, basic_block bb = NULL, int depth = -1);
>bool compute_operand_range_switch (vrange , gswitch *s, const vrange 
> ,
>tree name, fur_source );
>bool compute_operand1_range (vrange , gimple_range_op_handler ,
> diff --git a/gcc/params.opt b/gcc/params.opt
> index 2329d150ef0..b2ec436546c 100644
> --- a/gcc/params.opt
> +++ b/gcc/params.opt
> @@ -900,6 +900,11 @@ Common Joined UInteger Var(param_ranger_logical_depth) 
> Init(6) IntegerRange(1, 9
>  Maximum depth of logical expression evaluation ranger will look through when
>  evaluating outgoing edge ranges.
>  
> +-param=ranger-recompute-depth=
> +Common Joined UInteger Var(param_ranger_recompute_depth) Init(5) 
> IntegerRange(1, 100) Param Optimization
> +Maximum depth of instruction chains to consider for recomputation in the
> +outgoing range calculator.
> +
>  -param=relation-block-limit=
>  Common Joined UInteger Var(param_relation_block_limit) Init(200) 
> IntegerRange(0, ) Param Optimization
>  Maximum number of relations the oracle will register in a basic block.


Jakub



[PATCH] c++tools: Fix Makefile to properly clean and rebuild [PR101834]

2023-03-30 Thread Jonathan Wakely via Gcc-patches
Tested with various combinations of 'make clean all' etc.

OK for trunk?

And backport to gcc-12 and gcc-11 after some soak time on trunk?

-- >8 --

The c++tools makefile doesn't remove progressively more files in each of
mostlyclean, clean, and distclean. Instead, each removes a different set
of files (and some files are not removed by any target). Use
prerequisites so that everything is removed.

Also, building in the $objdir/c++tools directory doesn't work, because
the INSTALL variable is never set. It works when building from the
top-level because INSTALL is set in the environment when recursively
invoking make for sub-directories.

c++tools/ChangeLog:

PR bootstrap/101834
* Makefile.in (INSTALL): Set variable.
(mostlyclean): Mark as a phony target.
(clean): Add mostlyclean as a prerequisite.
(distclean): Add clean as a prerequisite and remove more files.
(maintainer-clean): Add distclean as a prerequisite.
---
 c++tools/Makefile.in | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/c++tools/Makefile.in b/c++tools/Makefile.in
index 56cba090135..77bda3d56dc 100644
--- a/c++tools/Makefile.in
+++ b/c++tools/Makefile.in
@@ -22,6 +22,7 @@ libexecdir := @libexecdir@
 target_noncanonical := @target_noncanonical@
 gcc_version := $(shell @get_gcc_base_ver@ $(srcdir)/../gcc/BASE-VER)
 libexecsubdir := $(libexecdir)/gcc/$(target_noncanonical)/$(gcc_version)
+INSTALL := @INSTALL@
 INSTALL_PROGRAM := @INSTALL_PROGRAM@
 INSTALL_STRIP_PROGRAM := $(srcdir)/../install-sh -c -s
 AUTOCONF := @AUTOCONF@
@@ -41,13 +42,14 @@ all::
 mostlyclean::
rm -f $(MAPPER.O)
 
-clean::
+clean:: mostlyclean
rm -f g++-mapper-server$(exeext)
 
-distclean::
-   rm -f config.log config.status config.h
+distclean:: clean
+   rm -f config.log config.status config.h config.cache Makefile
+   rm -f $(MAPPER.O:%.o=%.d)
 
-maintainer-clean::
+maintainer-clean:: distclean
 
 install::
 
@@ -132,6 +134,6 @@ config.h: config.status config.h.in
 config.status: $(srcdir)/configure $(srcdir)/config.h.in
if test -x $@; then ./$@ -recheck; else $< @configure_args@; fi
 
-.PHONY: all check clean distclean maintainer-clean
+.PHONY: all check mostlyclean clean distclean maintainer-clean
 
 -include $(MAPPER.O:.o=.d)
-- 
2.39.2



Re: [PATCH V2] Rename ufix_trunc/ufloat* patterns to fixuns_trunc/floatuns* to align with standard pattern name.

2023-03-30 Thread Uros Bizjak via Gcc-patches
On Thu, Mar 30, 2023 at 1:43 PM liuhongt  wrote:
>
> > > Just rename the instruction and fix all its call sites. The name of
> > > the insn pattern is internal to the compiler and can be renamed at
> > > will.
> >
> > Ideally, we should standardize all the names to a standard name, so
> > e.g. ufix_  -> fixuns_ and ufloat -> floatuns.
>
> Updated.
>
> There's some typo for the standard pattern name for unsigned_{float,fix},
> it should be floatunsmn2/fixuns_truncmn2, not ufloatmn2/ufix_truncmn2
> in current trunk, the patch fix the typo, also change all though
> ufix_trunc/ufloat patterns.
>
> Also vcvttps2udq is available under AVX512VL, so it can be generated
> directly instead of being emulated via vcvttps2dq.
>
> gcc/ChangeLog:
>
> PR target/85048
> * config/i386/i386-builtin.def (BDESC): Adjust icode name from 
> ufloat/ufix to floatuns/fixuns.
> * config/i386/i386-expand.cc (ix86_expand_vector_convert_uns_vsivsf): 
> Adjust comments.
> * config/i386/sse.md 
> (ufloat2):
> Renamed to ..
> 
> (floatuns2):.. 
> this.
> 
> (_ufix_notrunc):
> Renamed to ..
> 
> (_fixuns_notrunc):
> .. this.
> (fix_truncv16sfv16si2):
> Renamed to ..
> 
> (fix_truncv16sfv16si2):.. this.
> (ufloat2): Renamed to ..
> (floatuns2): .. this.
> (ufloatv2siv2df2): Renamed to ..
> (floatunsv2siv2df2): .. this.
> (ufix_notrunc2):
> Renamed to ..
> (fixuns_notrunc2):
> .. this.
> (ufix_notruncv2dfv2si2): Renamed to ..
> (fixuns_notruncv2dfv2si2):.. this.
> (ufix_notruncv2dfv2si2_mask): Renamed to ..
> (fixuns_notruncv2dfv2si2_mask): .. this.
> (*ufix_notruncv2dfv2si2_mask_1): Renamed to ..
> (*fixuns_notruncv2dfv2si2_mask_1): .. this.
> (ufix_truncv2dfv2si2): Renamed to ..
> (*fixuns_truncv2dfv2si2): .. this.
> (ufix_truncv2dfv2si2_mask): Renamed to ..
> (fixuns_truncv2dfv2si2_mask): .. this.
> (*ufix_truncv2dfv2si2_mask_1): Renamed to ..
> (*fixuns_truncv2dfv2si2_mask_1): .. this.
> (ufix_truncv4dfv4si2): Renamed to ..
> (fixuns_truncv4dfv4si2): .. this.
> (ufix_notrunc2):
> Renamed to ..
> (fixuns_notrunc2):
> .. this.
> (ufix_trunc2): Renamed to ..
> (fixuns_trunc2):
> .. this.
>
> gcc/testsuite/ChangeLog:
>
> * g++.target/i386/pr85048.C: New test.

OK for trunk.

Thanks,
Uros.

> ---
>  gcc/config/i386/i386-builtin.def| 40 +++---
>  gcc/config/i386/i386-expand.cc  |  2 +-
>  gcc/config/i386/sse.md  | 69 +++--
>  gcc/testsuite/g++.target/i386/pr85048.C | 33 
>  4 files changed, 84 insertions(+), 60 deletions(-)
>  create mode 100644 gcc/testsuite/g++.target/i386/pr85048.C
>
> diff --git a/gcc/config/i386/i386-builtin.def 
> b/gcc/config/i386/i386-builtin.def
> index 17dfe40fac7..6dae6972d81 100644
> --- a/gcc/config/i386/i386-builtin.def
> +++ b/gcc/config/i386/i386-builtin.def
> @@ -1384,7 +1384,7 @@ BDESC (OPTION_MASK_ISA_AVX512F, 0, 
> CODE_FOR_avx512f_compressv8df_mask, "__builti
>  BDESC (OPTION_MASK_ISA_AVX512F, 0, CODE_FOR_avx512f_compressv16sf_mask, 
> "__builtin_ia32_compresssf512_mask", IX86_BUILTIN_COMPRESSPS512, UNKNOWN, 
> (int) V16SF_FTYPE_V16SF_V16SF_UHI)
>  BDESC (OPTION_MASK_ISA_AVX512F, 0, CODE_FOR_floatv8siv8df2_mask, 
> "__builtin_ia32_cvtdq2pd512_mask", IX86_BUILTIN_CVTDQ2PD512, UNKNOWN, (int) 
> V8DF_FTYPE_V8SI_V8DF_UQI)
>  BDESC (OPTION_MASK_ISA_AVX512F, 0, CODE_FOR_avx512f_vcvtps2ph512_mask_sae,  
> "__builtin_ia32_vcvtps2ph512_mask", IX86_BUILTIN_CVTPS2PH512, UNKNOWN, (int) 
> V16HI_FTYPE_V16SF_INT_V16HI_UHI)
> -BDESC (OPTION_MASK_ISA_AVX512F, 0, CODE_FOR_ufloatv8siv8df2_mask, 
> "__builtin_ia32_cvtudq2pd512_mask", IX86_BUILTIN_CVTUDQ2PD512, UNKNOWN, (int) 
> V8DF_FTYPE_V8SI_V8DF_UQI)
> +BDESC (OPTION_MASK_ISA_AVX512F, 0, CODE_FOR_floatunsv8siv8df2_mask, 
> "__builtin_ia32_cvtudq2pd512_mask", IX86_BUILTIN_CVTUDQ2PD512, UNKNOWN, (int) 
> V8DF_FTYPE_V8SI_V8DF_UQI)
>  BDESC (OPTION_MASK_ISA_AVX512F, 0, CODE_FOR_cvtusi2sd32, 
> "__builtin_ia32_cvtusi2sd32", IX86_BUILTIN_CVTUSI2SD32, UNKNOWN, (int) 
> V2DF_FTYPE_V2DF_UINT)
>  BDESC (OPTION_MASK_ISA_AVX512F, 0, CODE_FOR_expandv8df_mask, 
> "__builtin_ia32_expanddf512_mask", IX86_BUILTIN_EXPANDPD512, UNKNOWN, (int) 
> V8DF_FTYPE_V8DF_V8DF_UQI)
>  BDESC (OPTION_MASK_ISA_AVX512F, 0, CODE_FOR_avx512f_expandv8df_maskz, 
> "__builtin_ia32_expanddf512_maskz", IX86_BUILTIN_EXPANDPD512Z, UNKNOWN, (int) 
> V8DF_FTYPE_V8DF_V8DF_UQI)
> @@ -1719,32 +1719,32 @@ BDESC (OPTION_MASK_ISA_AVX512DQ | 
> OPTION_MASK_ISA_AVX512VL, 0, CODE_FOR_fixuns_t
>  BDESC (OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, 0, 
> CODE_FOR_fixuns_truncv2dfv2di2_mask, "__builtin_ia32_cvttpd2uqq128_mask", 
> IX86_BUILTIN_CVTTPD2UQQ128, UNKNOWN, (int) V2DI_FTYPE_V2DF_V2DI_UQI)
>  BDESC 

Re: [PATCH v2] rtl-optimization: ppc backend generates unnecessary extension.

2023-03-30 Thread Ajit Agarwal via Gcc-patches
Hello All:

This patch added enhancement to extimination elimination for rs6000 target.
Bootstrapped and regtested on powerpc64-linux-gnu.

Thanks & Regards
Ajit
rtl-optimization: ppc backend generates unnecessary extension.

Eliminate unnecessary redundant zero extension within basic
blocks.

2023-03-30  Ajit Kumar Agarwal  

gcc/ChangeLog:

* ree.cc(is_feasible_elim_across_basic_blocks):
Add checks to enable extension elimination..
* ree.cc(combine_reaching_defs): Add checks to enable
extension elimination.
---
 gcc/ree.cc | 121 ++---
 1 file changed, 116 insertions(+), 5 deletions(-)

diff --git a/gcc/ree.cc b/gcc/ree.cc
index d05d37f9a23..7e4cce5cee4 100644
--- a/gcc/ree.cc
+++ b/gcc/ree.cc
@@ -253,6 +253,56 @@ struct ext_cand
 
 static int max_insn_uid;
 
+/* Get all the reaching definitions of an instruction.  The definitions are
+   desired for REG used in INSN.  Return the definition list or NULL if a
+   definition is missing.  If DEST is non-NULL, additionally push the INSN
+   of the definitions onto DEST.  */
+
+static struct df_link *
+get_defs (rtx_insn *insn, rtx reg, vec *dest)
+{
+  df_ref use;
+  struct df_link *ref_chain, *ref_link;
+
+  FOR_EACH_INSN_USE (use, insn)
+{
+  if (GET_CODE (DF_REF_REG (use)) == SUBREG)
+   return NULL;
+  if (REGNO (DF_REF_REG (use)) == REGNO (reg))
+   break;
+}
+
+  if (use == NULL) return NULL;
+
+  gcc_assert (use != NULL);
+
+  ref_chain = DF_REF_CHAIN (use);
+
+  for (ref_link = ref_chain; ref_link; ref_link = ref_link->next)
+{
+  /* Problem getting some definition for this instruction.  */
+  if (ref_link->ref == NULL)
+   return NULL;
+  if (DF_REF_INSN_INFO (ref_link->ref) == NULL)
+   return NULL;
+  /* As global regs are assumed to be defined at each function call
+dataflow can report a call_insn as being a definition of REG.
+But we can't do anything with that in this pass so proceed only
+if the instruction really sets REG in a way that can be deduced
+from the RTL structure.  */
+  if (global_regs[REGNO (reg)]
+ && !set_of (reg, DF_REF_INSN (ref_link->ref)))
+   return NULL;
+}
+
+  if (dest)
+for (ref_link = ref_chain; ref_link; ref_link = ref_link->next)
+  dest->safe_push (DF_REF_INSN (ref_link->ref));
+
+  return ref_chain;
+}
+
+
 /* Identify instruction AND with identical zero extension.  */
 
 static unsigned int
@@ -393,6 +443,7 @@ combine_set_extension (ext_cand *cand, rtx_insn *curr_insn, 
rtx *orig_set)
   machine_mode orig_mode = GET_MODE (SET_DEST (*orig_set));
   rtx new_set = NULL_RTX;
   rtx cand_pat = single_set (cand->insn);
+
   if (insn_is_zext_p(cand->insn)
&& CONST_INT_P (orig_src) && INTVAL (orig_src) != 0)
 return false;
@@ -401,6 +452,7 @@ combine_set_extension (ext_cand *cand, rtx_insn *curr_insn, 
rtx *orig_set)
  then we need to change the original load to reference the destination
  of the extension.  Then we need to emit a copy from that destination
  to the original destination of the load.  */
+ // print_rtl_single(stdout, cand_pat);
   rtx new_reg;
   bool copy_needed
 = (REGNO (SET_DEST (cand_pat)) != REGNO (XEXP (SET_SRC (cand_pat), 0)));
@@ -547,6 +599,7 @@ transform_ifelse (ext_cand *cand, rtx_insn *def_insn)
   return false;
 }
 
+#if 0
 /* Get all the reaching definitions of an instruction.  The definitions are
desired for REG used in INSN.  Return the definition list or NULL if a
definition is missing.  If DEST is non-NULL, additionally push the INSN
@@ -593,7 +646,7 @@ get_defs (rtx_insn *insn, rtx reg, vec *dest)
 
   return ref_chain;
 }
-
+#endif
 /* Get all the reaching uses of an instruction.  The uses are desired for REG
set in INSN.  Return use list or NULL if a use is missing or irregular.  */
 
@@ -848,6 +901,36 @@ is_feasible_elim_across_basic_blocks (ext_cand *cand,
&& REGNO (XEXP (PATTERN (BB_END (bb)), 0)) != REGNO (SET_DEST 
(cand->expr)))
  return false;
 
+   if (cand->code == ZERO_EXTEND
+   && GET_CODE ((PATTERN (def_insn))) == PARALLEL)
+ return false;
+
+   if (cand->code == ZERO_EXTEND
+   && GET_CODE ((PATTERN (def_insn))) == SET
+   && GET_CODE (SET_SRC (PATTERN (def_insn))) != XOR)
+ return false;
+
+   if (cand->code == ZERO_EXTEND
+   && GET_CODE ((PATTERN (def_insn))) == SET
+   && GET_CODE (SET_SRC (PATTERN (def_insn))) == XOR)
+ {
+   vec *dest = XCNEWVEC (vec, 4);
+   if (!get_defs (def_insn, XEXP (SET_SRC (PATTERN(def_insn)), 0), dest))
+ return false;
+
+   int i;
+   rtx_insn *def_insn;
+
+   FOR_EACH_VEC_ELT (*dest, i, def_insn)
+ {
+   if ((GET_CODE (PATTERN (def_insn)) == SET
+   && GET_CODE (SET_SRC (PATTERN (def_insn))) == ASHIFT)
+   || GET_CODE (PATTERN (def_insn)) == PARALLEL)
+  

Re: [PATCH RFC] c++: lambda mangling alias issues [PR107897]

2023-03-30 Thread Jan Hubicka via Gcc-patches
> 
> How about moving it to symtab_node and using dyn_cast for the cgraph bits,
> like this:

> From 1d869ceb04573727e59be6518903133c8654069a Mon Sep 17 00:00:00 2001
> From: Jason Merrill 
> Date: Mon, 6 Mar 2023 15:33:45 -0500
> Subject: [PATCH] c++: lambda mangling alias issues [PR107897]
> To: gcc-patches@gcc.gnu.org
> 
> In 107897, by the time we are looking at the mangling clash, the
> alias has already been removed from the symbol table by analyze_functions,
> so we can't look at n->cpp_implicit_alias.  So just assume that it's an
> alias if it's internal.
> 
> In 108887 the problem is that removing the mangling alias from the symbol
> table confuses analyze_functions, because it ended up as first_analyzed
> somehow, so it becomes a dangling pointer.  Fixed by clearing various flags
> to neutralize the alias.
> 
>   PR c++/107897
>   PR c++/108887
> 
> gcc/ChangeLog:
> 
>   * cgraph.h: Move reset() from cgraph_node to symtab_node.
>   * cgraphunit.cc (symtab_node::reset): Adjust.
> 
> gcc/cp/ChangeLog:
> 
>   * decl2.cc (record_mangling): Use symtab_node::reset.
> 
> gcc/testsuite/ChangeLog:
> 
>   * g++.dg/cpp2a/concepts-lambda3.C: Use -flto if supported.
>   * g++.dg/cpp0x/lambda/lambda-mangle7.C: New test.

OK and I apologize for the delay (my travels were more busy than I
hoped)
Honza


[PATCH V2] Rename ufix_trunc/ufloat* patterns to fixuns_trunc/floatuns* to align with standard pattern name.

2023-03-30 Thread liuhongt via Gcc-patches
> > Just rename the instruction and fix all its call sites. The name of
> > the insn pattern is internal to the compiler and can be renamed at
> > will.
>
> Ideally, we should standardize all the names to a standard name, so
> e.g. ufix_  -> fixuns_ and ufloat -> floatuns.

Updated.

There's some typo for the standard pattern name for unsigned_{float,fix},
it should be floatunsmn2/fixuns_truncmn2, not ufloatmn2/ufix_truncmn2
in current trunk, the patch fix the typo, also change all though
ufix_trunc/ufloat patterns.

Also vcvttps2udq is available under AVX512VL, so it can be generated
directly instead of being emulated via vcvttps2dq.

gcc/ChangeLog:

PR target/85048
* config/i386/i386-builtin.def (BDESC): Adjust icode name from 
ufloat/ufix to floatuns/fixuns.
* config/i386/i386-expand.cc (ix86_expand_vector_convert_uns_vsivsf): 
Adjust comments.
* config/i386/sse.md 
(ufloat2):
Renamed to ..

(floatuns2):.. 
this.

(_ufix_notrunc):
Renamed to ..

(_fixuns_notrunc):
.. this.
(fix_truncv16sfv16si2):
Renamed to ..
(fix_truncv16sfv16si2):.. 
this.
(ufloat2): Renamed to ..
(floatuns2): .. this.
(ufloatv2siv2df2): Renamed to ..
(floatunsv2siv2df2): .. this.
(ufix_notrunc2):
Renamed to ..
(fixuns_notrunc2):
.. this.
(ufix_notruncv2dfv2si2): Renamed to ..
(fixuns_notruncv2dfv2si2):.. this.
(ufix_notruncv2dfv2si2_mask): Renamed to ..
(fixuns_notruncv2dfv2si2_mask): .. this.
(*ufix_notruncv2dfv2si2_mask_1): Renamed to ..
(*fixuns_notruncv2dfv2si2_mask_1): .. this.
(ufix_truncv2dfv2si2): Renamed to ..
(*fixuns_truncv2dfv2si2): .. this.
(ufix_truncv2dfv2si2_mask): Renamed to ..
(fixuns_truncv2dfv2si2_mask): .. this.
(*ufix_truncv2dfv2si2_mask_1): Renamed to ..
(*fixuns_truncv2dfv2si2_mask_1): .. this.
(ufix_truncv4dfv4si2): Renamed to ..
(fixuns_truncv4dfv4si2): .. this.
(ufix_notrunc2):
Renamed to ..
(fixuns_notrunc2):
.. this.
(ufix_trunc2): Renamed to ..
(fixuns_trunc2):
.. this.

gcc/testsuite/ChangeLog:

* g++.target/i386/pr85048.C: New test.
---
 gcc/config/i386/i386-builtin.def| 40 +++---
 gcc/config/i386/i386-expand.cc  |  2 +-
 gcc/config/i386/sse.md  | 69 +++--
 gcc/testsuite/g++.target/i386/pr85048.C | 33 
 4 files changed, 84 insertions(+), 60 deletions(-)
 create mode 100644 gcc/testsuite/g++.target/i386/pr85048.C

diff --git a/gcc/config/i386/i386-builtin.def b/gcc/config/i386/i386-builtin.def
index 17dfe40fac7..6dae6972d81 100644
--- a/gcc/config/i386/i386-builtin.def
+++ b/gcc/config/i386/i386-builtin.def
@@ -1384,7 +1384,7 @@ BDESC (OPTION_MASK_ISA_AVX512F, 0, 
CODE_FOR_avx512f_compressv8df_mask, "__builti
 BDESC (OPTION_MASK_ISA_AVX512F, 0, CODE_FOR_avx512f_compressv16sf_mask, 
"__builtin_ia32_compresssf512_mask", IX86_BUILTIN_COMPRESSPS512, UNKNOWN, (int) 
V16SF_FTYPE_V16SF_V16SF_UHI)
 BDESC (OPTION_MASK_ISA_AVX512F, 0, CODE_FOR_floatv8siv8df2_mask, 
"__builtin_ia32_cvtdq2pd512_mask", IX86_BUILTIN_CVTDQ2PD512, UNKNOWN, (int) 
V8DF_FTYPE_V8SI_V8DF_UQI)
 BDESC (OPTION_MASK_ISA_AVX512F, 0, CODE_FOR_avx512f_vcvtps2ph512_mask_sae,  
"__builtin_ia32_vcvtps2ph512_mask", IX86_BUILTIN_CVTPS2PH512, UNKNOWN, (int) 
V16HI_FTYPE_V16SF_INT_V16HI_UHI)
-BDESC (OPTION_MASK_ISA_AVX512F, 0, CODE_FOR_ufloatv8siv8df2_mask, 
"__builtin_ia32_cvtudq2pd512_mask", IX86_BUILTIN_CVTUDQ2PD512, UNKNOWN, (int) 
V8DF_FTYPE_V8SI_V8DF_UQI)
+BDESC (OPTION_MASK_ISA_AVX512F, 0, CODE_FOR_floatunsv8siv8df2_mask, 
"__builtin_ia32_cvtudq2pd512_mask", IX86_BUILTIN_CVTUDQ2PD512, UNKNOWN, (int) 
V8DF_FTYPE_V8SI_V8DF_UQI)
 BDESC (OPTION_MASK_ISA_AVX512F, 0, CODE_FOR_cvtusi2sd32, 
"__builtin_ia32_cvtusi2sd32", IX86_BUILTIN_CVTUSI2SD32, UNKNOWN, (int) 
V2DF_FTYPE_V2DF_UINT)
 BDESC (OPTION_MASK_ISA_AVX512F, 0, CODE_FOR_expandv8df_mask, 
"__builtin_ia32_expanddf512_mask", IX86_BUILTIN_EXPANDPD512, UNKNOWN, (int) 
V8DF_FTYPE_V8DF_V8DF_UQI)
 BDESC (OPTION_MASK_ISA_AVX512F, 0, CODE_FOR_avx512f_expandv8df_maskz, 
"__builtin_ia32_expanddf512_maskz", IX86_BUILTIN_EXPANDPD512Z, UNKNOWN, (int) 
V8DF_FTYPE_V8DF_V8DF_UQI)
@@ -1719,32 +1719,32 @@ BDESC (OPTION_MASK_ISA_AVX512DQ | 
OPTION_MASK_ISA_AVX512VL, 0, CODE_FOR_fixuns_t
 BDESC (OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, 0, 
CODE_FOR_fixuns_truncv2dfv2di2_mask, "__builtin_ia32_cvttpd2uqq128_mask", 
IX86_BUILTIN_CVTTPD2UQQ128, UNKNOWN, (int) V2DI_FTYPE_V2DF_V2DI_UQI)
 BDESC (OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, 0, 
CODE_FOR_fix_notruncv4dfv4di2_mask, "__builtin_ia32_cvtpd2qq256_mask", 
IX86_BUILTIN_CVTPD2QQ256, UNKNOWN, (int) V4DI_FTYPE_V4DF_V4DI_UQI)
 BDESC (OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, 0, 
CODE_FOR_fix_notruncv2dfv2di2_mask, 

Re: [PATCH] Introduce -nolibstdc++ option

2023-03-30 Thread Alexandre Oliva via Gcc-patches
Hello, Gerald,

On Feb 11, 2023, Gerald Pfeifer  wrote:

> On Thu, 23 Jun 2022, Alexandre Oliva via Gcc-patches wrote:
>> Introduce -nostdlib++ option
>> 
>> Using g++ to link without libstdc++, as in g++.dg/abi/pure-virtual1.C,
>> is error prone, because there's no way to tell g++ to drop libstdc++
>> without also dropping libc and any other libraries that the target
>> implicitly links in.

> % grep -r nostdlib $WWWDOCS
> %

> Should this be documented in gcc-13/changes.html? Would you mind proposing 
> a snippet (or going ahead and pushing it)?

I can't make my mind up about this.

At first, the goal of adding the option was just to aid this specific
test.  But then, it transpired that other compilers offered a similar
option, with the spelling that we ended up using, so perhaps it would
make sense to document it, after all.

How about this, does this seem useful?

diff --git a/htdocs/gcc-13/changes.html b/htdocs/gcc-13/changes.html
index ff70d2eefecec..c1bbbfa28e18e 100644
--- a/htdocs/gcc-13/changes.html
+++ b/htdocs/gcc-13/changes.html
@@ -333,6 +333,9 @@ a work-in-progress.
   The https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-Wpessimizing-move;>-Wpessimizing-move
 and https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-Wredundant-move;>-Wredundant-move
 warnings have been extended to warn in more contexts.
+  The https://gcc.gnu.org/onlinedocs/gcc/Link_Options.html#index-nostdlib_002b_002b;>-nostdlib++
+option has been added, to enable linking with g++
+without implicitly linking in the C++ standard library.
 
 
 Runtime Library (libstdc++)


-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


Re: [PATCH] tree-optimization/107561 - reduce -Wstringop-overflow false positives

2023-03-30 Thread Richard Biener via Gcc-patches
On Wed, 29 Mar 2023, Richard Biener wrote:

> The following tells pointer-query to prefer a zero size when we
> are querying for the size range for a write into an object we've
> determined is of zero size.  That avoids diagnostics about really
> varying size arguments that just get a meaningful range for example
> because they are multiplied by an element size.
> 
> I've adjusted only one call to get_size_range since that's what
> I have a testcase for.  I think this is the most sensible
> "workaround" for some of the false positives we see.
> 
> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
> 
> OK if it succeeds?

It did, I have now pushed this, it seems like an obvious improvement.

Richard.

> Thanks,
> Richard.
> 
>   PR tree-optimization/107561
>   * gimple-ssa-warn-access.cc (get_size_range): Add flags
>   argument and pass it on.
>   (check_access): When querying for the size range pass
>   SR_ALLOW_ZERO when the known destination size is zero.
> 
>   * g++.dg/pr71488.C: Remove XFAILed bogus diagnostic again.
>   * g++.dg/warn/Warray-bounds-16.C: Likewise.
> ---
>  gcc/gimple-ssa-warn-access.cc| 19 +--
>  gcc/testsuite/g++.dg/pr71488.C   |  1 -
>  gcc/testsuite/g++.dg/warn/Warray-bounds-16.C |  1 -
>  3 files changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
> index 88d44690ade..b3de4b77924 100644
> --- a/gcc/gimple-ssa-warn-access.cc
> +++ b/gcc/gimple-ssa-warn-access.cc
> @@ -1198,10 +1198,10 @@ warn_for_access (location_t loc, tree func, tree 
> expr, int opt,
>  
>  static void
>  get_size_range (range_query *query, tree bound, gimple *stmt, tree range[2],
> - const offset_int bndrng[2])
> + int flags, const offset_int bndrng[2])
>  {
>if (bound)
> -get_size_range (query, bound, stmt, range);
> +get_size_range (query, bound, stmt, range, flags);
>  
>if (!bndrng || (bndrng[0] == 0 && bndrng[1] == HOST_WIDE_INT_M1U))
>  return;
> @@ -1347,7 +1347,12 @@ check_access (GimpleOrTree exp, tree dstwrite,
>/* Set RANGE to that of DSTWRITE if non-null, bounded by PAD->DST_BNDRNG
>   if valid.  */
>gimple *stmt = pad ? pad->stmt : nullptr;
> -  get_size_range (rvals, dstwrite, stmt, range, pad ? pad->dst_bndrng : 
> NULL);
> +  get_size_range (rvals, dstwrite, stmt, range,
> +   /* If the destination has known zero size prefer a zero
> +  size range to avoid false positives if that's a
> +  possibility.  */
> +   integer_zerop (dstsize) ? SR_ALLOW_ZERO : 0,
> +   pad ? pad->dst_bndrng : NULL);
>  
>tree func = get_callee_fndecl (exp);
>/* Read vs write access by built-ins can be determined from the const
> @@ -1442,7 +1447,8 @@ check_access (GimpleOrTree exp, tree dstwrite,
>  {
>/* Set RANGE to that of MAXREAD, bounded by PAD->SRC_BNDRNG if
>PAD is nonnull and BNDRNG is valid.  */
> -  get_size_range (rvals, maxread, stmt, range, pad ? pad->src_bndrng : 
> NULL);
> +  get_size_range (rvals, maxread, stmt, range, 0,
> +   pad ? pad->src_bndrng : NULL);
>  
>location_t loc = get_location (exp);
>tree size = dstsize;
> @@ -1489,7 +1495,8 @@ check_access (GimpleOrTree exp, tree dstwrite,
>  {
>/* Set RANGE to that of MAXREAD, bounded by PAD->SRC_BNDRNG if
>PAD is nonnull and BNDRNG is valid.  */
> -  get_size_range (rvals, maxread, stmt, range, pad ? pad->src_bndrng : 
> NULL);
> +  get_size_range (rvals, maxread, stmt, range, 0,
> +   pad ? pad->src_bndrng : NULL);
>/* Set OVERREAD for reads starting just past the end of an object.  */
>overread = pad->src.sizrng[1] - pad->src.offrng[0] < 
> pad->src_bndrng[0];
>range[0] = wide_int_to_tree (sizetype, pad->src_bndrng[0]);
> @@ -2679,7 +2686,7 @@ pass_waccess::check_strncmp (gcall *stmt)
>/* Determine the range of the bound first and bail if it fails; it's
>   cheaper than computing the size of the objects.  */
>tree bndrng[2] = { NULL_TREE, NULL_TREE };
> -  get_size_range (m_ptr_qry.rvals, bound, stmt, bndrng, adata1.src_bndrng);
> +  get_size_range (m_ptr_qry.rvals, bound, stmt, bndrng, 0, 
> adata1.src_bndrng);
>if (!bndrng[0] || integer_zerop (bndrng[0]))
>  return;
>  
> diff --git a/gcc/testsuite/g++.dg/pr71488.C b/gcc/testsuite/g++.dg/pr71488.C
> index a89e6465a94..ffe30f1afeb 100644
> --- a/gcc/testsuite/g++.dg/pr71488.C
> +++ b/gcc/testsuite/g++.dg/pr71488.C
> @@ -3,7 +3,6 @@
>  // { dg-options "-O3 -std=c++11" }
>  // { dg-additional-options "-msse4" { target sse4_runtime } }
>  // { dg-require-effective-target c++11 }
> -// { dg-bogus "size 0 overflows" "pr107561" { xfail *-*-* } 0 }
>  
>  #include 
>  
> diff --git a/gcc/testsuite/g++.dg/warn/Warray-bounds-16.C 
> b/gcc/testsuite/g++.dg/warn/Warray-bounds-16.C

[PATCH] tree-optimization/109342 - wrong code with edge equivalences in VN

2023-03-30 Thread Richard Biener via Gcc-patches
The following testcase shows a problem in how we query valitity for
equivalences on edges when the edge is a backedge and thus refering
to a block thats later in the iteration order we use for VN.  That
causes the dominated_by_p_w_unex helper to look at edge executable
state that's not yet computed and thus still at optimistic not
executable state.

The following makes sure to use a plain dominance check in these cases.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

PR tree-optimization/109342
* tree-ssa-sccvn.cc (vn_nary_op_get_predicated_value): New
overload for edge.  When that edge is a backedge use
dominated_by_p directly.

* g++.dg/torture/pr109342.C: New testcase.
---
 gcc/testsuite/g++.dg/torture/pr109342.C | 33 ++
 gcc/tree-ssa-sccvn.cc   | 37 ++---
 2 files changed, 60 insertions(+), 10 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/torture/pr109342.C

diff --git a/gcc/testsuite/g++.dg/torture/pr109342.C 
b/gcc/testsuite/g++.dg/torture/pr109342.C
new file mode 100644
index 000..2cdfa764faf
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr109342.C
@@ -0,0 +1,33 @@
+// { dg-do run }
+
+unsigned long int var_4 = 42;
+unsigned long int var_14 = 10;
+unsigned char var_16 = 1;
+unsigned short var_18 = 0;
+short var_75;
+
+inline const int (const int , const int )
+{
+  return b < c ? c : b;
+}
+inline unsigned long (unsigned long , unsigned long )
+{
+  return !c ? c : b;
+}
+
+void __attribute__((noipa))
+test(unsigned long var_4, unsigned long var_14,
+ unsigned char var_16, unsigned short var_18)
+{
+  for (bool h = 0; h < (bool)foo(var_16 ? -7 : 4, var_4 ? var_4 : var_18);
+   h = 2)
+var_75 = bar(var_4, var_14);
+}
+
+int main()
+{
+  test(var_4, var_14, var_16, var_18);
+  if (var_75 != 42)
+__builtin_abort();
+  return 0;
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 6b8d38b270c..99609538f54 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -4583,22 +4583,39 @@ static bool
 dominated_by_p_w_unex (basic_block bb1, basic_block bb2, bool);
 
 static tree
-vn_nary_op_get_predicated_value (vn_nary_op_t vno, basic_block bb)
+vn_nary_op_get_predicated_value (vn_nary_op_t vno, basic_block bb,
+edge e = NULL)
 {
   if (! vno->predicated_values)
 return vno->u.result;
   for (vn_pval *val = vno->u.values; val; val = val->next)
 for (unsigned i = 0; i < val->n; ++i)
-  /* Do not handle backedge executability optimistically since
-when figuring out whether to iterate we do not consider
-changed predication.  */
-  if (dominated_by_p_w_unex
-   (bb, BASIC_BLOCK_FOR_FN (cfun, val->valid_dominated_by_p[i]),
-false))
-   return val->result;
+  {
+   basic_block cand
+ = BASIC_BLOCK_FOR_FN (cfun, val->valid_dominated_by_p[i]);
+   /* Do not handle backedge executability optimistically since
+  when figuring out whether to iterate we do not consider
+  changed predication.
+  When asking for predicated values on an edge avoid looking
+  at edge executability for edges forward in our iteration
+  as well.  */
+   if (e && (e->flags & EDGE_DFS_BACK))
+ {
+   if (dominated_by_p (CDI_DOMINATORS, bb, cand))
+ return val->result;
+ }
+   else if (dominated_by_p_w_unex (bb, cand, false))
+ return val->result;
+  }
   return NULL_TREE;
 }
 
+static tree
+vn_nary_op_get_predicated_value (vn_nary_op_t vno, edge e)
+{
+  return vn_nary_op_get_predicated_value (vno, e->src, e);
+}
+
 /* Insert the rhs of STMT into the current hash table with a value number of
RESULT.  */
 
@@ -5928,7 +5945,7 @@ visit_phi (gimple *phi, bool *inserted, bool 
backedges_varying_p)
 ops, );
if (! val && vnresult && vnresult->predicated_values)
  {
-   val = vn_nary_op_get_predicated_value (vnresult, e->src);
+   val = vn_nary_op_get_predicated_value (vnresult, e);
if (val && integer_truep (val)
&& !(sameval_e && (sameval_e->flags & EDGE_DFS_BACK)))
  {
@@ -5947,7 +5964,7 @@ visit_phi (gimple *phi, bool *inserted, bool 
backedges_varying_p)
   we can change sameval to def.  */
if (EDGE_COUNT (bb->preds) == 2
&& (val = vn_nary_op_get_predicated_value
-   (vnresult, EDGE_PRED (bb, 0)->src))
+   (vnresult, EDGE_PRED (bb, 0)))
&& integer_truep (val)
&& !(e->flags & EDGE_DFS_BACK))
  {
-- 
2.35.3


Re: [pushed] wwwdocs: gcc-4.7: Adjust dwarfstd.org links

2023-03-30 Thread Mark Wielaard
On Wed, 2023-03-29 at 15:40 -0700, Andrew Pinski wrote:
> On Wed, Mar 29, 2023 at 3:08 PM Gerald Pfeifer  wrote:
> > 
> > Business as usual - 301 Moved Permanently.
> 
> Just FYI, dwarfstd is now hosted by sourceware too. So I doubt these
> URLs will change after this.

Indeed, see
https://inbox.sourceware.org/overseers/20230327222524.ga20...@gnu.wildebeest.org/


And thanks for taking care of these new redirects. Please do let us
(dwarf-disc...@lists.dwarfstd.org) know if any old URL is broken. With
the move the site was changed (twice). From php to static html and then
to being generated statically from markdown files. All old URLs should
redirect to the new setup, but we might have missed something.

Cheers,

Mark


Re: 'g++.dg/modules/modules.exp': don't leak local 'unsupported' proc [PR108899]

2023-03-30 Thread Thomas Schwinge
Hi!

On 2023-03-30T04:00:03-0300, Alexandre Oliva  wrote:
> On Mar 29, 2023, Thomas Schwinge  wrote:
>> But surely the curly braces in:
>
>> -UNSUPPORTED: g++.dg/modules/explicit-bool-1_a.H -std=c++17
>
>> +UNSUPPORTED: {g++.dg/modules/explicit-bool-1_a.H -std=c++17}
>
>> ... are not intentional?  (Alexandre?)
>
> Unintended indeed, will look, thanks for letting me know
>
>
>> But worse, the latter also "bleeds into" all other testing
>
> Eeek
>
> Yeah, that's a much bigger problem indeed.
>
>> ..., this isn't sufficient.  Instead, we should undo the 'rename' at the
>> end of 'g++.dg/modules/modules.exp'.  OK to push the attached
>> "'g++.dg/modules/modules.exp': don't leak local 'unsupported' proc 
>> [PR108899]"
>> after proper testing?
>
> Ooh, nice, I didn't know how to drop the renaming after we were done
> with it, and hoped the end of the .exp would have accomplished that by
> ending a scope.  Jakub had already pointed out this wasn't the case, but
> I didn't realize, when he did, that this would carry over onto other
> modules.
>
> If we're dropping the renaming, I suppose we could also revert Jakub's
> change.

Yes, my plan was to push a 'git revert' of Jakub's change as a follow-up
(clean-up) *after* my proposed
"'g++.dg/modules/modules.exp': don't leak local 'unsupported' proc [PR108899]",
see attached again.

My testing has completed without issues; OK to push that one?

> +# Restore the original unsupported proc, lest it will affect
> +# subsequent test runs, or even fail renaming if we run modules.exp
> +# for multiple targets/multilibs/options.
> +rename unsupported {}
> +rename modules-saved-unsupported unsupported

Should I incorporate that comment instead of my simpler one?


Grüße
 Thomas


-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955
>From b5c6fae2467cf4245f379269792559b8c00eca58 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Wed, 29 Mar 2023 21:11:19 +0200
Subject: [PATCH] 'g++.dg/modules/modules.exp': don't leak local 'unsupported'
 proc [PR108899]

Fix-up for commit 5344482c4d3ae0618fa8f5ed38f8309db43fdb82
"testsuite: Skip module_cmi_p and related unsupported module test".

	PR testsuite/108899
	gcc/testsuite/
	* g++.dg/modules/modules.exp: Don't leak local 'unsupported' proc.
---
 gcc/testsuite/g++.dg/modules/modules.exp | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/testsuite/g++.dg/modules/modules.exp b/gcc/testsuite/g++.dg/modules/modules.exp
index e66b2082f20..23c4bac2e89 100644
--- a/gcc/testsuite/g++.dg/modules/modules.exp
+++ b/gcc/testsuite/g++.dg/modules/modules.exp
@@ -408,4 +408,8 @@ foreach src [lsort [find $srcdir/$subdir {*_a.[CHX}]] {
 }
 }
 
+# Restore the saved 'unsupported' proc.
+rename unsupported {}
+rename saved-unsupported unsupported
+
 dg-finish
-- 
2.25.1



[PATCH] testsuite, analyzer: Fix up pipe-glibc.c testcase [PR107396]

2023-03-30 Thread Jakub Jelinek via Gcc-patches
Hi!

The gcc.dg/analyzer/pipe-glibc.c test FAILs when using recent glibc headers
and succeeds with older headers.
The important change is that
https://sourceware.org/git/?p=glibc.git;a=commit;h=c1760eaf3b575ad174fd88b252fd16bd525fa818
in 2021 added __attribute__ ((__malloc__ (fclose, 1))) attribute to fdopen,
so in write_to_pipe there is an excess warning:
.../gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c: In function 'write_to_pipe':
.../gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c:28:3: warning: use of 
possibly-NULL 'stream' where non-null expected [CWE-690] 
[-Wanalyzer-possible-null-argument]
.../gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c:27:12: note: (1) this call could 
return NULL
.../gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c:28:3: note: (2) argument 4 
('stream') from (1) could be NULL where non-null expected
: note: argument 4 of '__builtin_fwrite' must be non-null
Strangely, nothing is reported on the read_from_pipe function, seems
fwrite/fprintf/fputc etc. are builtins in GCC and we mark the FILE *
arguments as nonnull there on the builtin declarations, while fgetc/fread
etc. aren't builtins and glibc doesn't mark any of those using nonnull.
Shall we change that on the glibc side?

Anyway, because this differs based on glibc version and I think the
above warning is not the primary intention of the test, I think it is
best to tweak it so that this warning isn't reported.
Another option would be avoid using glibc headers and use our own
declarations, or make sure we add the malloc with fclose attribute ourselves
(but fdopen in the libc headers could be a macro, so not sure
__typeof (fdopen) fdopen __attribute__ ((__malloc__, __malloc__ (fclose, 1)));
would work).  Or use -Wno-analyzer-possible-null-arguments in
dg-additional-options?

Bootstrapped/regtested on x86_64-linux and  i686-linux, ok for trunk?

2023-03-30  Jakub Jelinek  

PR analyzer/107396
* gcc.dg/analyzer/pipe-glibc.c (read_from_pie, write_to_pipe): Exit
if fdopen returns NULL.

--- gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c.jj   2022-10-25 
10:37:28.106531709 +0200
+++ gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c  2023-03-29 19:14:48.789766475 
+0200
@@ -13,6 +13,8 @@ read_from_pipe (int file)
   FILE *stream;
   int c;
   stream = fdopen (file, "r");
+  if (stream == NULL)
+exit (EXIT_FAILURE);
   while ((c = fgetc (stream)) != EOF)
 putchar (c);
   fclose (stream);
@@ -25,6 +27,8 @@ write_to_pipe (int file)
 {
   FILE *stream;
   stream = fdopen (file, "w");
+  if (stream == NULL)
+exit (EXIT_FAILURE);
   fprintf (stream, "hello, world!\n");
   fprintf (stream, "goodbye, world!\n");
   fclose (stream);

Jakub



Re: [PATCH] c++,coroutines: Stabilize names of promoted slot vars [PR101118].

2023-03-30 Thread Iain Sandoe
Hi Jason,

> On 30 Mar 2023, at 00:53, Jason Merrill  wrote:
> 
> On 3/26/23 12:54, Iain Sandoe wrote:
>> Tested on x86_64-darwin21, x86-64-linux-gnu

>>  +/* This is used to make a stable, but unique-per-function, sequence number 
>> for
>> +   each TARGET_EXPR slot variable that we 'promote' to a frame entry.  It 
>> needs
>> +   to be stable because the frame type is visible to LTO ODR checking.  */
>> +static unsigned tmpno = 0;
> 
> How about using temps_used->elements() for the index instead of a separate 
> static counter?

That’s a good idea (the only slightly weird effect is that the count does not 
start at 0, 
because we’ve added one or more entries by the time we get to produce a name, 
but
that does not affect functionality).

re-tested on x86_64-darwin21, as below,
OK for trunk?
thanks
Iain

===

[PATCH] c++,coroutines: Stabilize names of promoted slot vars  [PR101118].

When we need to 'promote' a value (i.e. store it in the coroutine frame) it
is given a frame entry name.  This was based on the DECL_UID for slot vars.
However, when LTO is used, the names from multiple TUs become visible at the
same time, and the DECL_UIDs usually differ between units.  This leads to a
"ODR mismatch" warning for the frame type.

The fix here is to use the current promoted temporaries count to produce
the name, this is stable between TUs and computed per coroutine.

Signed-off-by: Iain Sandoe 

PR c++/101118

gcc/cp/ChangeLog:

* coroutines.cc (flatten_await_stmt): Use the current count of
promoted temporaries to build a unique name for the frame entries.
---
 gcc/cp/coroutines.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index a2189e43db8..9f546db7437 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -2889,7 +2889,7 @@ flatten_await_stmt (var_nest_node *n, hash_set 
*promoted,
  tree init = t;
  temps_used->add (init);
  tree var_type = TREE_TYPE (init);
- char *buf = xasprintf ("D.%d", DECL_UID (TREE_OPERAND (init, 0)));
+ char *buf = xasprintf ("T%03u", temps_used->elements());
  tree var = build_lang_decl (VAR_DECL, get_identifier (buf), var_type);
  DECL_ARTIFICIAL (var) = true;
  free (buf);
— 




[PATCH] c++: Fix up ICE in build_min_non_dep_op_overload [PR109319]

2023-03-30 Thread Jakub Jelinek via Gcc-patches
Hi!

The following testcase ICEs, because grok_array_decl during
processing_template_decl handling of a non-dependent subscript
emits a -Wcomma-subscript pedwarn, we decide to pass to the
single index argument the index expressions as if it was wrapped
with () around it, but then when preparing it for later instantiation
we don't actually take that into account and ICE on a mismatch of
number of index arguments (the overload expects a single index,
testcase has two index expressions in this case).
For non-dependent subscript which are builtin subscripts we also
emit the same pedwarn and don't ICE, but emit the same pedwarn
again whenever we instantiate it, which is also IMHO undesirable,
it is enough to warn once during parsing the template.

The following patch fixes it by turning even the original index expressions
(those which didn't go through make_args_non_dependent) into a single
index using comma expression(s).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2023-03-30  Jakub Jelinek  

PR c++/109319
* decl2.cc (grok_array_decl): After emitting a pedwarn for
-Wcomma-subscript, if processing_template_decl set orig_index_exp
to compound expr from orig_index_exp_list.

* g++.dg/cpp23/subscript14.C: New test.

--- gcc/cp/decl2.cc.jj  2023-03-20 20:29:34.0 +0100
+++ gcc/cp/decl2.cc 2023-03-29 15:17:14.952173134 +0200
@@ -474,11 +474,23 @@ grok_array_decl (location_t loc, tree ar
 , complain);
}
  else
-   /* If it would be valid albeit deprecated expression in C++20,
-  just pedwarn on it and treat it as if wrapped in ().  */
-   pedwarn (loc, OPT_Wcomma_subscript,
-"top-level comma expression in array subscript "
-"changed meaning in C++23");
+   {
+ /* If it would be valid albeit deprecated expression in
+C++20, just pedwarn on it and treat it as if wrapped
+in ().  */
+ pedwarn (loc, OPT_Wcomma_subscript,
+  "top-level comma expression in array subscript "
+  "changed meaning in C++23");
+ if (processing_template_decl)
+   {
+ orig_index_exp
+   = build_x_compound_expr_from_vec (orig_index_exp_list,
+ NULL, complain);
+ if (orig_index_exp == error_mark_node)
+   expr = error_mark_node;
+ release_tree_vector (orig_index_exp_list);
+   }
+   }
}
}
 }
@@ -519,6 +531,15 @@ grok_array_decl (location_t loc, tree ar
  return error_mark_node;
}
  index_exp = idx;
+ if (processing_template_decl)
+   {
+ orig_index_exp
+   = build_x_compound_expr_from_vec (orig_index_exp_list,
+ NULL, complain);
+ release_tree_vector (orig_index_exp_list);
+ if (orig_index_exp == error_mark_node)
+   return error_mark_node;
+   }
}
 
   if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE)
--- gcc/testsuite/g++.dg/cpp23/subscript14.C.jj 2023-03-29 15:29:46.037076158 
+0200
+++ gcc/testsuite/g++.dg/cpp23/subscript14.C2023-03-29 15:34:18.645051075 
+0200
@@ -0,0 +1,42 @@
+// PR c++/109319
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+struct A { static int [] (int x) { static int a[2]; return a[x]; } }; 
// { dg-warning "may be a static member function only with" "" { target 
c++20_down } }
+struct B { int [] (int x) { static int b[2]; return b[x]; } };
+int c[2];
+
+template 
+int
+foo ()
+{
+  A a;
+  ++a[0, 1];   // { dg-warning "top-level comma expression in array 
subscript changed meaning" "" { target c++23 } }
+  B b; // { dg-warning "top-level comma expression in array 
subscript is deprecated" "" { target c++20_only } .-1 }
+  ++b[0, 1];   // { dg-warning "top-level comma expression in array 
subscript changed meaning" "" { target c++23 } }
+   // { dg-warning "top-level comma expression in array 
subscript is deprecated" "" { target c++20_only } .-1 }
+  ++c[0, 1];   // { dg-warning "top-level comma expression in array 
subscript changed meaning" "" { target c++23 } }
+  T d; // { dg-warning "top-level comma expression in array 
subscript is deprecated" "" { target c++20_only } .-1 }
+  ++d[0, 1];   // { dg-warning "top-level comma expression in array 
subscript changed meaning" "" { target c++23 } }
+  U e; // { dg-warning "top-level comma expression in array 
subscript is deprecated" "" { target c++20_only } .-1 }
+  ++e[0, 1]; 

Re: 'g++.dg/modules/modules.exp': don't leak local 'unsupported' proc [PR108899]

2023-03-30 Thread Alexandre Oliva via Gcc-patches
On Mar 29, 2023, Thomas Schwinge  wrote:

> I assume that the second UNSUPPORTED:

> -UNSUPPORTED: g++.dg/modules/explicit-bool-1_b.C -std=c++17

> ... disappears is the intention of this patch?

Yup

> But surely the curly braces in:

> -UNSUPPORTED: g++.dg/modules/explicit-bool-1_a.H -std=c++17

> +UNSUPPORTED: {g++.dg/modules/explicit-bool-1_a.H -std=c++17}

> ... are not intentional?  (Alexandre?)

Unintended indeed, will look, thanks for letting me know


> But worse, the latter also "bleeds into" all other testing

Eeek

Yeah, that's a much bigger problem indeed.

> ..., this isn't sufficient.  Instead, we should undo the 'rename' at the
> end of 'g++.dg/modules/modules.exp'.  OK to push the attached
> "'g++.dg/modules/modules.exp': don't leak local 'unsupported' proc [PR108899]"
> after proper testing?

Ooh, nice, I didn't know how to drop the renaming after we were done
with it, and hoped the end of the .exp would have accomplished that by
ending a scope.  Jakub had already pointed out this wasn't the case, but
I didn't realize, when he did, that this would carry over onto other
modules.


If we're dropping the renaming, I suppose we could also revert Jakub's
change.  I suppose this patch will take care of it, pending testing...


diff --git a/gcc/testsuite/g++.dg/modules/modules.exp 
b/gcc/testsuite/g++.dg/modules/modules.exp
index 80aa392bc7f3b..6fd5050cef79b 100644
--- a/gcc/testsuite/g++.dg/modules/modules.exp
+++ b/gcc/testsuite/g++.dg/modules/modules.exp
@@ -319,15 +319,11 @@ cleanup_module_files [find $DEFAULT_REPO *.gcm]
 # so that, after an unsupported result in dg-test, we can skip rather
 # than fail subsequent related tests.
 set module_do {"compile" "P"}
-if { [info procs unsupported] != [list] \
-  && [info procs saved-unsupported] == [list] } {
-rename unsupported saved-unsupported
-
-proc unsupported { args } {
-   global module_do
-   lset module_do 1 "N"
-   return [saved-unsupported $args]
-}
+rename unsupported modules-saved-unsupported
+proc unsupported { args } {
+global module_do
+lset module_do 1 "N"
+return [eval modules-saved-unsupported $args]
 }
 
 # not grouped tests, sadly tcl doesn't have negated glob
@@ -412,4 +408,10 @@ foreach src [lsort [find $srcdir/$subdir {*_a.[CHX}]] {
 }
 }
 
+# Restore the original unsupported proc, lest it will affect
+# subsequent test runs, or even fail renaming if we run modules.exp
+# for multiple targets/multilibs/options.
+rename unsupported {}
+rename modules-saved-unsupported unsupported
+
 dg-finish


-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


Re: recomputation and PR 109154

2023-03-30 Thread Richard Biener via Gcc-patches
On Wed, Mar 29, 2023 at 7:22 PM Andrew MacLeod  wrote:
>
> The patch, or a slight variation (attached), in the PR allows us to
> generate better ranges be recomputing longer instruction sequences on
> outgoing edges.
>
> This in fact also fixes
> XPASS: gcc.dg/Walloca-13.c  (test for bogus messages, line 11)
>
> [local count: 1073741824]:
>_1 = p_5(D) - q_6(D);
>_2 = _1 /[ex] 4;
>n_7 = (long unsigned int) _2;
>_11 = (long unsigned int) _1;
>if (_11 <= 396)
>  goto ; [33.00%]
>else
>  goto ; [67.00%]
>
> [local count: 354334800]:
>_3 = __builtin_alloca (n_7);
>
> Where _2 was recomputed before, but n_7 was not.  Now it is, and we
> correctly do not issue the warning any more.  awesome.,
>
> however, as seems to be the case often, better ranges result in, I now get:
>
> FAIL: 23_containers/vector/bool/allocator/copy.cc (test for excess errors)
>
> because we now generate:
>
> /opt/notnfs/amacleod/master/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_algobase.h:437:
> warning: ‘void* __builtin_memmove(void*, const void*, long unsigned
> int)’ writing between 9 and 9223372036854775807 bytes into a region of
> size 8 overflows the destination [-Wstringop-overflow=]
>
>   I see:
> 
>   
>  _216 = operator new (8);
>
> _216 : [irange] long unsigned int * [1, +INF]
>..
>
>   [local count: 86938296]:
>  D.245552 ={v} {CLOBBER(eol)};
>  _74 = v1.D.217578._M_impl.D.217043._M_start.D.58619._M_p;
>  _638 = (long int) _74;
>  _261 = -_638;
>  _383 = (long unsigned int) _261;
>  if (_638 < -8)
>goto ; [90.00%]
>  else
>goto ; [10.00%]
>
> _261 : [irange] long int [-9223372036854775807, +INF]
> _383 : [irange] long unsigned int [0,
> 9223372036854775807][9223372036854775809, +INF]
> 8->12  (T) _74 :[irange] _Bit_type * [1, +INF]
> 8->12  (T) _261 :   [irange] long int [9, +INF] NONZERO
> 0x7fff
> 8->12  (T) _383 :   [irange] long unsigned int [9,
> 9223372036854775807] NONZERO 0x7fff
> 8->12  (T) _638 :   [irange] long int [-INF, -9]
>
> === BB 12 
> _74 [irange] _Bit_type * [9223372036854775808, 18446744073709551607]
> _383[irange] long unsigned int [9, 9223372036854775807] NONZERO
> 0x7fff
>   [local count: 78244465]:
>  __builtin_memmove (_216, _74, _383);
>
>
>
> The change is that we now recompute _383 which we didnt before. so we
> are seeing memmove being called on what is effectively:
> memmove (operator new (8), _74, [9, 9223372036854775807])
> And thus the warning.
>
> IS this one of the warnings that has been causing issues?  and now Im
> triggering it again?

Yeah, we see these kind of diagnostics on code that's supposed to be
not reachable but we don't figure that out (missed-optimization) or the
code is written in a way that doesn't make this obvious.

>
> Back at fixup_cfg3 time, it looks like:
>
>   _261 = __last$D58797$_M_p_245 - _247;
>_262 = _261 > 8;
>_263 = (long int) _262;
>_264 = __builtin_expect (_263, 1);
>if (_264 != 0)
>  goto ; [90.00%]
>else
>  goto ; [10.00%]
> ..
> [local count: 78244465]:
>_265 = (long unsigned int) _261;
>__builtin_memmove (_246, _247, _265);
>
> So the builtin expect certainly implies it is expecting to have a value > 8
>
> Early on the code looks like:
> _1 = __last_10(D) - __first_11(D);
>_Num_12 = _1 /[ex] 8;
>_2 = _Num_12 > 1;
>_3 = (long int) _2;
>_4 = __builtin_expect (_3, 1);
>if (_4 != 0)
>  goto ; [INV]
>else
>  goto ; [INV]
>
> :
>_Num.28_5 = (long unsigned int) _Num_12;
>_6 = _Num.28_5 * 8;
>__builtin_memmove (__result_14(D), __first_11(D), _6);
>
>
> SO it does still do basically the same thing.
>
> Im not sure whether this is pointing out something real or another false
> positive...
>
> Andrew


Re: [PATCH] Support vector conversion for AVX512 vcvtudq2pd/vcvttps2udq/vcvttpd2udq.

2023-03-30 Thread Uros Bizjak via Gcc-patches
On Thu, Mar 30, 2023 at 8:17 AM Uros Bizjak  wrote:
>
> On Thu, Mar 30, 2023 at 3:47 AM liuhongt  wrote:
> >
> > There's some typo for the standard pattern name for unsigned_{float,fix},
> > it should be floatunsmn2/fixuns_truncmn2, not ufloatmn2/ufix_truncmn2
> > in current trunk, the patch fix the typo.
> >
> > Also vcvttps2udq is available under AVX512VL, so it can be generated
> > directly instead of being emulated via vcvttps2dq.
> >
> > Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}
> > Ok for GCC14 stage1{or maybe for trunk)?
> >
> > gcc/ChangeLog:
> >
> > PR target/85048
> > * config/i386/sse.md (floatuns2):
> > Generate vcvtudq2ps under AVX512VL.
> > (fixuns_truncv4dfv4si2): New expander.
> > (floatuns2): New expander.
> >
> > gcc/testsuite/ChangeLog:
> >
> > * g++.target/i386/pr85048.C: New test.
> > ---
> >  gcc/config/i386/sse.md  | 18 --
> >  gcc/testsuite/g++.target/i386/pr85048.C | 33 +
> >  2 files changed, 49 insertions(+), 2 deletions(-)
> >  create mode 100644 gcc/testsuite/g++.target/i386/pr85048.C
> >
> > diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
> > index 172ec3bea4f..9c2bd468c65 100644
> > --- a/gcc/config/i386/sse.md
> > +++ b/gcc/config/i386/sse.md
> > @@ -8014,8 +8014,9 @@ (define_expand 
> > "fixuns_trunc2"
> > (match_operand:VF1 1 "register_operand")]
> >"TARGET_SSE2"
> >  {
> > -  if (mode == V16SFmode)
> > -emit_insn (gen_ufix_truncv16sfv16si2 (operands[0],
> > +  /* AVX512 support vcvttps2udq for all 128/256/512-bit vectors.  */
> > +  if (mode == V16SFmode || TARGET_AVX512VL)
> > +emit_insn (gen_ufix_trunc2 (operands[0],
> >   operands[1]));
> >else
> >  {
> > @@ -8413,6 +8414,12 @@ (define_insn "*floatv2div2sf2_mask_1"
> > (set_attr "prefix" "evex")
> > (set_attr "mode" "V4SF")])
> >
> > +(define_expand "floatuns2"
> > +  [(set (match_operand:VF2_512_256VL 0 "register_operand")
> > +   (unsigned_float:VF2_512_256VL
> > + (match_operand: 1 "nonimmediate_operand")))]
> > +   "TARGET_AVX512F")
> > +
>
> Just rename the instruction and fix all its call sites. The name of
> the insn pattern is internal to the compiler and can be renamed at
> will.

Ideally, we should standardize all the names to a standard name, so
e.g. ufix_  -> fixuns_ and ufloat -> floatuns.

Uros.

> >  (define_insn "ufloat2"
> >[(set (match_operand:VF2_512_256VL 0 "register_operand" "=v")
> > (unsigned_float:VF2_512_256VL
> > @@ -8694,6 +8701,13 @@ (define_insn "fix_truncv4dfv4si2"
> > (set_attr "prefix" "maybe_evex")
> > (set_attr "mode" "OI")])
> >
> > +
> > +/* The standard pattern name is fixuns_truncmn2.  */
> > +(define_expand "fixuns_truncv4dfv4si2"
> > +  [(set (match_operand:V4SI 0 "register_operand")
> > +   (unsigned_fix:V4SI (match_operand:V4DF 1 "nonimmediate_operand")))]
> > +  "TARGET_AVX512VL && TARGET_AVX512F")
> > +
>
> Also the above.
>
> Uros.
>
> >  (define_insn "ufix_truncv4dfv4si2"
> >[(set (match_operand:V4SI 0 "register_operand" "=v")
> > (unsigned_fix:V4SI (match_operand:V4DF 1 "nonimmediate_operand" 
> > "vm")))]
> > diff --git a/gcc/testsuite/g++.target/i386/pr85048.C 
> > b/gcc/testsuite/g++.target/i386/pr85048.C
> > new file mode 100644
> > index 000..52973c18ebd
> > --- /dev/null
> > +++ b/gcc/testsuite/g++.target/i386/pr85048.C
> > @@ -0,0 +1,33 @@
> > +/* PR target/85048 */
> > +/* { dg-do compile }  */
> > +/* { dg-options "-std=c++17 -O2 -mavx512vl -mavx512dq 
> > -mprefer-vector-width=512" } */
> > +/* { dg-final { scan-assembler-times {(?n)vcvtudq2pd[ \t]+} 2 } } */
> > +/* { dg-final { scan-assembler-times {(?n)vcvttps2udq[ \t]+} 2 } } */
> > +/* { dg-final { scan-assembler-times {(?n)vcvttpd2udqy?[ \t]+} 1 } } */
> > +
> > +#include 
> > +
> > +template 
> > +using V [[gnu::vector_size(Size)]] = T;
> > +
> > +template  V cvt4(V x) {
> > +return V{To(x[0]), To(x[1]), To(x[2]), To(x[3])};
> > +}
> > +template  V cvt8(V x) {
> > +return V{
> > +To(x[0]), To(x[1]), To(x[2]), To(x[3]),
> > +To(x[4]), To(x[5]), To(x[6]), To(x[7])
> > +};
> > +}
> > +
> > +#define _(name, from, to, size) \
> > +auto name(V x) { return cvt##size(x); }
> > +// integral -> double
> > +_(vcvtudq2pd, uint32_t, double, 4)
> > +_(vcvtudq2pd, uint32_t, double, 8)
> > +
> > +_( cvttps2udq, float, uint32_t,  4)
> > +_(vcvttps2udq, float, uint32_t,  8)
> > +
> > +// double -> integral
> > +_(vcvttpd2udq, double, uint32_t, 4)
> > --
> > 2.39.1.388.g2fc9e9ca3c
> >


Re: [PATCH] Support vector conversion for AVX512 vcvtudq2pd/vcvttps2udq/vcvttpd2udq.

2023-03-30 Thread Uros Bizjak via Gcc-patches
On Thu, Mar 30, 2023 at 3:47 AM liuhongt  wrote:
>
> There's some typo for the standard pattern name for unsigned_{float,fix},
> it should be floatunsmn2/fixuns_truncmn2, not ufloatmn2/ufix_truncmn2
> in current trunk, the patch fix the typo.
>
> Also vcvttps2udq is available under AVX512VL, so it can be generated
> directly instead of being emulated via vcvttps2dq.
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}
> Ok for GCC14 stage1{or maybe for trunk)?
>
> gcc/ChangeLog:
>
> PR target/85048
> * config/i386/sse.md (floatuns2):
> Generate vcvtudq2ps under AVX512VL.
> (fixuns_truncv4dfv4si2): New expander.
> (floatuns2): New expander.
>
> gcc/testsuite/ChangeLog:
>
> * g++.target/i386/pr85048.C: New test.
> ---
>  gcc/config/i386/sse.md  | 18 --
>  gcc/testsuite/g++.target/i386/pr85048.C | 33 +
>  2 files changed, 49 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/g++.target/i386/pr85048.C
>
> diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
> index 172ec3bea4f..9c2bd468c65 100644
> --- a/gcc/config/i386/sse.md
> +++ b/gcc/config/i386/sse.md
> @@ -8014,8 +8014,9 @@ (define_expand "fixuns_trunc2"
> (match_operand:VF1 1 "register_operand")]
>"TARGET_SSE2"
>  {
> -  if (mode == V16SFmode)
> -emit_insn (gen_ufix_truncv16sfv16si2 (operands[0],
> +  /* AVX512 support vcvttps2udq for all 128/256/512-bit vectors.  */
> +  if (mode == V16SFmode || TARGET_AVX512VL)
> +emit_insn (gen_ufix_trunc2 (operands[0],
>   operands[1]));
>else
>  {
> @@ -8413,6 +8414,12 @@ (define_insn "*floatv2div2sf2_mask_1"
> (set_attr "prefix" "evex")
> (set_attr "mode" "V4SF")])
>
> +(define_expand "floatuns2"
> +  [(set (match_operand:VF2_512_256VL 0 "register_operand")
> +   (unsigned_float:VF2_512_256VL
> + (match_operand: 1 "nonimmediate_operand")))]
> +   "TARGET_AVX512F")
> +

Just rename the instruction and fix all its call sites. The name of
the insn pattern is internal to the compiler and can be renamed at
will.

>  (define_insn "ufloat2"
>[(set (match_operand:VF2_512_256VL 0 "register_operand" "=v")
> (unsigned_float:VF2_512_256VL
> @@ -8694,6 +8701,13 @@ (define_insn "fix_truncv4dfv4si2"
> (set_attr "prefix" "maybe_evex")
> (set_attr "mode" "OI")])
>
> +
> +/* The standard pattern name is fixuns_truncmn2.  */
> +(define_expand "fixuns_truncv4dfv4si2"
> +  [(set (match_operand:V4SI 0 "register_operand")
> +   (unsigned_fix:V4SI (match_operand:V4DF 1 "nonimmediate_operand")))]
> +  "TARGET_AVX512VL && TARGET_AVX512F")
> +

Also the above.

Uros.

>  (define_insn "ufix_truncv4dfv4si2"
>[(set (match_operand:V4SI 0 "register_operand" "=v")
> (unsigned_fix:V4SI (match_operand:V4DF 1 "nonimmediate_operand" 
> "vm")))]
> diff --git a/gcc/testsuite/g++.target/i386/pr85048.C 
> b/gcc/testsuite/g++.target/i386/pr85048.C
> new file mode 100644
> index 000..52973c18ebd
> --- /dev/null
> +++ b/gcc/testsuite/g++.target/i386/pr85048.C
> @@ -0,0 +1,33 @@
> +/* PR target/85048 */
> +/* { dg-do compile }  */
> +/* { dg-options "-std=c++17 -O2 -mavx512vl -mavx512dq 
> -mprefer-vector-width=512" } */
> +/* { dg-final { scan-assembler-times {(?n)vcvtudq2pd[ \t]+} 2 } } */
> +/* { dg-final { scan-assembler-times {(?n)vcvttps2udq[ \t]+} 2 } } */
> +/* { dg-final { scan-assembler-times {(?n)vcvttpd2udqy?[ \t]+} 1 } } */
> +
> +#include 
> +
> +template 
> +using V [[gnu::vector_size(Size)]] = T;
> +
> +template  V cvt4(V x) {
> +return V{To(x[0]), To(x[1]), To(x[2]), To(x[3])};
> +}
> +template  V cvt8(V x) {
> +return V{
> +To(x[0]), To(x[1]), To(x[2]), To(x[3]),
> +To(x[4]), To(x[5]), To(x[6]), To(x[7])
> +};
> +}
> +
> +#define _(name, from, to, size) \
> +auto name(V x) { return cvt##size(x); }
> +// integral -> double
> +_(vcvtudq2pd, uint32_t, double, 4)
> +_(vcvtudq2pd, uint32_t, double, 8)
> +
> +_( cvttps2udq, float, uint32_t,  4)
> +_(vcvttps2udq, float, uint32_t,  8)
> +
> +// double -> integral
> +_(vcvttpd2udq, double, uint32_t, 4)
> --
> 2.39.1.388.g2fc9e9ca3c
>


Re: [PATCH v3] RISC-V: Add Z*inx imcompatible check in gcc

2023-03-30 Thread Kito Cheng via Gcc-patches
Thanks Jiawei, committed to trunk!

On Wed, Mar 29, 2023 at 12:55 AM Jiawei  wrote:
>
> Z*inx is conflict with float extensions, add incompatible check when
> z*inx and f extension both enabled.
>
> Since all float extension imply f extension and all z*inx extension
> imply zfinx extension, so we just need to check f with zfinx extension
> as the base case.
>
> Co-Authored by: Kito Cheng 
>
> gcc/ChangeLog:
>
> * common/config/riscv/riscv-common.cc (riscv_subset_list::parse):
> * New check.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/riscv/arch-19.c: New test.
>
> ---
>  gcc/common/config/riscv/riscv-common.cc  | 5 +
>  gcc/testsuite/gcc.target/riscv/arch-19.c | 4 
>  2 files changed, 9 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/arch-19.c
>
> diff --git a/gcc/common/config/riscv/riscv-common.cc 
> b/gcc/common/config/riscv/riscv-common.cc
> index ef221be1eb1..b3c6ec97e7a 100644
> --- a/gcc/common/config/riscv/riscv-common.cc
> +++ b/gcc/common/config/riscv/riscv-common.cc
> @@ -1153,6 +1153,11 @@ riscv_subset_list::parse (const char *arch, location_t 
> loc)
>
>subset_list->handle_combine_ext ();
>
> +  if (subset_list->lookup("zfinx") && subset_list->lookup("f"))
> +   error_at (loc,
> +   "%<-march=%s%>: z*inx is conflict with float extensions",
> +   arch);
> +
>return subset_list;
>
>  fail:
> diff --git a/gcc/testsuite/gcc.target/riscv/arch-19.c 
> b/gcc/testsuite/gcc.target/riscv/arch-19.c
> new file mode 100644
> index 000..83c6e00a755
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/arch-19.c
> @@ -0,0 +1,4 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv64if_zfinx -mabi=lp64" } */
> +int foo() {}
> +/* { dg-error "'-march=rv64if_zfinx': z\\*inx is conflict with float 
> extensions" "" { target *-*-* } 0 } */
> --
> 2.25.1
>