Re: [PATCH] Machine_Mode: Extend machine_mode from 8 to 16 bits

2023-05-13 Thread Kito Cheng via Gcc-patches
Hi Pan:

Tried this patch and I ran into some issues, some variables are using
unsigned char to hold machine mode and will have problems when the
number of modes is larger than 255...

And here is the fix:


diff --git a/gcc/genmodes.cc b/gcc/genmodes.cc
index 715787b8f483..55ac2adb5596 100644
--- a/gcc/genmodes.cc
+++ b/gcc/genmodes.cc
@@ -1141,10 +1141,10 @@ inline __attribute__((__always_inline__))\n\
#else\n\
extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
#endif\n\
-unsigned char\n\
+unsigned short\n\
mode_inner_inline (machine_mode mode)\n\
{\n\
-  extern const unsigned char mode_inner[NUM_MACHINE_MODES];\n\
+  extern const unsigned short mode_inner[NUM_MACHINE_MODES];\n\
  gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
  switch (mode)\n\
{");
@@ -1529,7 +1529,7 @@ emit_mode_wider (void)
  int c;
  struct mode_data *m;

-  print_decl ("unsigned char", "mode_next", "NUM_MACHINE_MODES");
+  print_decl ("unsigned short", "mode_next", "NUM_MACHINE_MODES");

  for_all_modes (c, m)
tagged_printf ("E_%smode",
@@ -1537,7 +1537,7 @@ emit_mode_wider (void)
  m->name);

  print_closer ();
-  print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
+  print_decl ("unsigned short", "mode_wider", "NUM_MACHINE_MODES");

  for_all_modes (c, m)
{
@@ -1568,7 +1568,7 @@ emit_mode_wider (void)
}

  print_closer ();
-  print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
+  print_decl ("unsigned short", "mode_2xwider", "NUM_MACHINE_MODES");

  for_all_modes (c, m)
{
@@ -1625,7 +1625,7 @@ emit_mode_complex (void)
  int c;
  struct mode_data *m;

-  print_decl ("unsigned char", "mode_complex", "NUM_MACHINE_MODES");
+  print_decl ("unsigned short", "mode_complex", "NUM_MACHINE_MODES");

  for_all_modes (c, m)
tagged_printf ("E_%smode",
@@ -1665,7 +1665,7 @@ emit_mode_inner (void)
  int c;
  struct mode_data *m;

-  print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
+  print_decl ("unsigned short", "mode_inner", "NUM_MACHINE_MODES");

  for_all_modes (c, m)
tagged_printf ("E_%smode",
@@ -1738,7 +1738,7 @@ emit_class_narrowest_mode (void)
{
  int c;

-  print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
+  print_decl ("unsigned short", "class_narrowest_mode", "MAX_MODE_CLASS");

  for (c = 0; c < MAX_MODE_CLASS; c++)
{
diff --git a/gcc/machmode.h b/gcc/machmode.h
index f1865c1ef425..a168d6f0da2e 100644
--- a/gcc/machmode.h
+++ b/gcc/machmode.h
@@ -24,13 +24,13 @@ typedef opt_mode opt_machine_mode;

extern CONST_MODE_SIZE poly_uint16_pod mode_size[NUM_MACHINE_MODES];
extern CONST_MODE_PRECISION poly_uint16_pod mode_precision[NUM_MACHINE_MODES];
-extern const unsigned char mode_inner[NUM_MACHINE_MODES];
+extern const unsigned short mode_inner[NUM_MACHINE_MODES];
extern CONST_MODE_NUNITS poly_uint16_pod mode_nunits[NUM_MACHINE_MODES];
extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];
extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];
-extern const unsigned char mode_next[NUM_MACHINE_MODES];
-extern const unsigned char mode_wider[NUM_MACHINE_MODES];
-extern const unsigned char mode_2xwider[NUM_MACHINE_MODES];
+extern const unsigned short mode_next[NUM_MACHINE_MODES];
+extern const unsigned short mode_wider[NUM_MACHINE_MODES];
+extern const unsigned short mode_2xwider[NUM_MACHINE_MODES];

template
struct mode_traits
@@ -797,7 +797,7 @@ GET_MODE_2XWIDER_MODE (const T &m)
}

/* Get the complex mode from the component mode.  */
-extern const unsigned char mode_complex[NUM_MACHINE_MODES];
+extern const unsigned short mode_complex[NUM_MACHINE_MODES];
#define GET_MODE_COMPLEX_MODE(MODE) ((machine_mode) mode_complex[MODE])

/* Represents a machine mode that must have a fixed size.  The main
@@ -946,7 +946,7 @@ extern unsigned get_mode_alignment (machine_mode);

/* For each class, get the narrowest mode in that class.  */

-extern const unsigned char class_narrowest_mode[MAX_MODE_CLASS];
+extern const unsigned short class_narrowest_mode[MAX_MODE_CLASS];
#define GET_CLASS_NARROWEST_MODE(CLASS) \
  ((machine_mode) class_narrowest_mode[CLASS])

--
2.39.2


Re: [aarch64] Use dup and zip1 for interleaving elements in initializing vector

2023-05-13 Thread Prathamesh Kulkarni via Gcc-patches
On Fri, 12 May 2023 at 00:37, Richard Sandiford
 wrote:
>
> Prathamesh Kulkarni  writes:
> > diff --git a/gcc/testsuite/gcc.target/aarch64/vec-init-18.c 
> > b/gcc/testsuite/gcc.target/aarch64/vec-init-18.c
> > new file mode 100644
> > index 000..598a51f17c6
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/aarch64/vec-init-18.c
> > @@ -0,0 +1,20 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-O3" } */
> > +
> > +#include 
> > +
> > +int16x8_t foo(int16_t x, int y)
> > +{
> > +  int16x8_t v = (int16x8_t) {x, y, x, y, x, y, x, y};
> > +  return v;
> > +}
> > +
> > +int16x8_t foo2(int16_t x)
> > +{
> > +  int16x8_t v = (int16x8_t) {x, 1, x, 1, x, 1, x, 1};
> > +  return v;
> > +}
> > +
> > +/* { dg-final { scan-assembler-times {\tdup\tv[0-9]+\.4h, w[0-9]+} 3 } } */
> > +/* { dg-final { scan-assembler {\tmovi\tv[0-9]+\.4h, 0x1} } } */
> > +/* { dg-final { scan-assembler {\tzip1\tv[0-9]+\.8h, v[0-9]+\.8h, 
> > v[0-9]+\.8h} } } */
>
> Would be good to make this a scan-assembler-times ... 2.
>
> OK with that change.  Thanks for doing this.
Thanks, committed the patch in:
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=8b18714fbb1ca9812b33b3de75fe6ba4a57d4946
after bootstrap+test on aarch64-linux-gnu, and verifying bootstrap
passes on aarch64-linux-gnu with --enable-checking=all.

Thanks,
Prathamesh
>
> Richard


Re: [Patch] LTO: Fix writing of toplevel asm with offloading [PR109816]

2023-05-13 Thread Thomas Schwinge
Hi!

On 2023-05-12T14:46:21+0200, Tobias Burnus  wrote:
> Long standing issue but as top-level 'asm' statement were rare, it did not 
> show up.

Thanks for tracking this down, and fixing it!  Presumably latent
"forever" (here: since code offloading support was added, approximately
one decade ago).

> However, the fix for PR108969 in commit r14-321-g9a41d2cdbcd added code
>
> +#elif defined(_GLIBCXX_SYMVER_GNU)
> +  __extension__ __asm (".globl _ZSt21ios_base_library_initv");
> q
> libstdc++-v3/include/std/iostream. This was then duly written by the 
> offloading-device
> lto1 for digestion by the device-target assembler. While the llvm-mc linker 
> user by
> GCN did accept .globl, nvptx's ptxas did choke on it.
>
> Additionally, as the assembly was already written for offloading, the output 
> was
> lost on the host when using LTO for not only for offload but for real (i.e. 
> with -flto).

> Has someone an idea how to check whether the offloading-code assembler does 
> not
> contain the _ZSt21ios_base_library_initv while the host-side (before or after 
> LTO)
> should contain it, but only with _GLIBCXX_SYMVER_GNU?
> Otherwise, the testcase tests only and at least whether it breaks with nvptx
> as ptxas does not like the symbol.

We can construct test cases with their own top-level 'asm', outside of
the libstdc++ context?  I'll try to come up with something.


> The installed-build regtesting of "make check-target-libgomp" seems to be 
> currently broken
> as it does run all checking code (check_effective_target...) but does not 
> seem to find
> any actual testcase to be run, probably a side effect of the recent testsuite 
> changes.

FUD.  ;-O

We've since determined that Tobias' testing problem was due to
'//net/[...]' (double-slash) paths usage (with '/net' served by
'/etc/auto.master:/net -hosts'), which apparently confused DejaGnu/TCL
'find' (as used in 'libgomp/testsuite/libgomp.*/*.exp').

Per
:

| By the way, all changes (individually) tested in a number of different
| configurations: '--enable-languages=[...]', native vs. cross, build-tree
| vs. installed testing, etc.


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


[PATCH V2] Provide -fcf-protection=branch,return.

2023-05-13 Thread liuhongt via Gcc-patches
> I think this could be simplified if you use either EnumSet or
> EnumBitSet instead in common.opt for `-fcf-protection=`.

Use EnumSet instead of EnumBitSet since CF_FULL is not power of 2.
It is a bit tricky for sets classification, cf_branch and cf_return
should be in different sets, but they both "conflicts" cf_full,
cf_none. And current EnumSet don't handle this well.

So in the current implementation, only cf_full,cf_none are exclusive
to each other, but they can be combined with any cf_branch, cf_return,
cf_check. It's not perfect, but still an improvement than original
one.

gcc/ChangeLog:

* common.opt: (fcf-protection=): Add EnumSet attribute to
support combination of params.

gcc/testsuite/ChangeLog:

* c-c++-common/fcf-protection-10.c: New test.
* c-c++-common/fcf-protection-11.c: New test.
* c-c++-common/fcf-protection-12.c: New test.
* c-c++-common/fcf-protection-8.c: New test.
* c-c++-common/fcf-protection-9.c: New test.
* gcc.target/i386/pr89701-1.c: New test.
* gcc.target/i386/pr89701-2.c: New test.
* gcc.target/i386/pr89701-3.c: New test.
---
 gcc/common.opt | 12 ++--
 gcc/testsuite/c-c++-common/fcf-protection-10.c |  2 ++
 gcc/testsuite/c-c++-common/fcf-protection-11.c |  2 ++
 gcc/testsuite/c-c++-common/fcf-protection-12.c |  2 ++
 gcc/testsuite/c-c++-common/fcf-protection-8.c  |  2 ++
 gcc/testsuite/c-c++-common/fcf-protection-9.c  |  2 ++
 gcc/testsuite/gcc.target/i386/pr89701-1.c  |  4 
 gcc/testsuite/gcc.target/i386/pr89701-2.c  |  4 
 gcc/testsuite/gcc.target/i386/pr89701-3.c  |  4 
 9 files changed, 28 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/fcf-protection-10.c
 create mode 100644 gcc/testsuite/c-c++-common/fcf-protection-11.c
 create mode 100644 gcc/testsuite/c-c++-common/fcf-protection-12.c
 create mode 100644 gcc/testsuite/c-c++-common/fcf-protection-8.c
 create mode 100644 gcc/testsuite/c-c++-common/fcf-protection-9.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr89701-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr89701-2.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr89701-3.c

diff --git a/gcc/common.opt b/gcc/common.opt
index a28ca13385a..02f2472959a 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1886,7 +1886,7 @@ fcf-protection
 Common RejectNegative Alias(fcf-protection=,full)
 
 fcf-protection=
-Common Joined RejectNegative Enum(cf_protection_level) Var(flag_cf_protection) 
Init(CF_NONE)
+Common Joined RejectNegative Enum(cf_protection_level) EnumSet 
Var(flag_cf_protection) Init(CF_NONE)
 -fcf-protection=[full|branch|return|none|check]Instrument functions 
with checks to verify jump/call/return control-flow transfer
 instructions have valid targets.
 
@@ -1894,19 +1894,19 @@ Enum
 Name(cf_protection_level) Type(enum cf_protection_level) UnknownError(unknown 
Control-Flow Protection Level %qs)
 
 EnumValue
-Enum(cf_protection_level) String(full) Value(CF_FULL)
+Enum(cf_protection_level) String(full) Value(CF_FULL) Set(1)
 
 EnumValue
-Enum(cf_protection_level) String(branch) Value(CF_BRANCH)
+Enum(cf_protection_level) String(branch) Value(CF_BRANCH) Set(2)
 
 EnumValue
-Enum(cf_protection_level) String(return) Value(CF_RETURN)
+Enum(cf_protection_level) String(return) Value(CF_RETURN) Set(3)
 
 EnumValue
-Enum(cf_protection_level) String(check) Value(CF_CHECK)
+Enum(cf_protection_level) String(check) Value(CF_CHECK) Set(4)
 
 EnumValue
-Enum(cf_protection_level) String(none) Value(CF_NONE)
+Enum(cf_protection_level) String(none) Value(CF_NONE) Set(1)
 
 finstrument-functions
 Common Var(flag_instrument_function_entry_exit,1)
diff --git a/gcc/testsuite/c-c++-common/fcf-protection-10.c 
b/gcc/testsuite/c-c++-common/fcf-protection-10.c
new file mode 100644
index 000..b271d134e52
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/fcf-protection-10.c
@@ -0,0 +1,2 @@
+/* { dg-do compile { target { "i?86-*-* x86_64-*-*" } } } */
+/* { dg-options "-fcf-protection=branch,check" } */
diff --git a/gcc/testsuite/c-c++-common/fcf-protection-11.c 
b/gcc/testsuite/c-c++-common/fcf-protection-11.c
new file mode 100644
index 000..2e566350ccd
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/fcf-protection-11.c
@@ -0,0 +1,2 @@
+/* { dg-do compile { target { "i?86-*-* x86_64-*-*" } } } */
+/* { dg-options "-fcf-protection=branch,return" } */
diff --git a/gcc/testsuite/c-c++-common/fcf-protection-12.c 
b/gcc/testsuite/c-c++-common/fcf-protection-12.c
new file mode 100644
index 000..b39c2f8e25d
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/fcf-protection-12.c
@@ -0,0 +1,2 @@
+/* { dg-do compile { target { "i?86-*-* x86_64-*-*" } } } */
+/* { dg-options "-fcf-protection=return,branch" } */
diff --git a/gcc/testsuite/c-c++-common/fcf-protection-8.c 
b/gcc/testsuite/c-c++-common/fcf-protection-8.c
new file mode 100644
index 000..3b97095a92c
--- /dev/null

Re: [PATCH] tree: Fix up save_expr [PR52339]

2023-05-13 Thread Eric Botcazou via Gcc-patches
> I think we really need Eric (as one who e.g. introduced the
> DECL_INVARIANT_P apparently for this kind of stuff) to have a look at that
> on the Ada side.

I have been investigating this for a few days and it's no small change for Ada 
and probably for other languages with dynamic types.  SAVE_EXPRs are delicate 
to handle because 1) they are TREE_SIDE_EFFECTS (it's explained in save_expr) 
so out of TREE_READONLY && !TREE_SIDE_EFFECTS trees, you now get side effects 
which then propagate to all parent nodes 2) their placement is problematic in 
conditional expressions, for example if you replace

  cond > 0 ? A : A + 1

with

  cond > 0 ? SAVE_EXPR (A) : SAVE_EXPR (A) + 1

then gimplification will, say, create the temporary and initialize it in the 
first arm so, if at runtime you take the second arm, you'll read the temporary 
uninitialized.  That's caught for scalar values by the SSA form (if your patch 
is applied to a GCC 12 tree, you'll get ICEs in the ACATS testsuite because of 
this through finalize_type_size -> variable_size -> save_expr, it is probably 
mitigated/addressed in GCC 14 by 68e0063397ba820e71adc220b2da0581dce29ffa).
That's also why making gnat_invariant_expr return (some of) them does not look 
really safe.

In addition to this, in Ada we have bounds of unconstrained arrays which are 
both read-only and stored indirectly, i.e. you have an INDIRECT_REF in the 
tree (it is marked TREE_THIS_NOTRAP because the bounds are always present), 
and which obviously play a crucial role in loops running over the arrays.
This issue is responsible for the regressions in the gnat.dg testsuite.

I think that we can reasonably deal with the second issue in the Ada front-end 
because we know the semantics of the bounds of unconstrained arrays, and I'm 
testing a patch to that effect, but the first issue might be annoying too.

-- 
Eric Botcazou




[PATCH] RISC-V: Support TARGET_VECTORIZE_PREFERRED_VECTOR_ALIGNMENT to optimize codegen of RVV auto-vectorization

2023-05-13 Thread juzhe . zhong
From: Juzhe-Zhong 

This patch support vector alignement for RVV auto-vectorization.

Consider this following case:
void __attribute__((noinline, noclone))
f (int * __restrict dst, int * __restrict op1, int * __restrict op2, int count)
{
  for (int i = 0; i < count; ++i)
dst[i] = op1[i] + op2[i];
}

Before this patch:
ble a3,zero,.L1
srlia4,a1,2
negwa4,a4
andia5,a4,3
sext.w  a3,a3
beq a5,zero,.L3
lw  a7,0(a1)
lw  a6,0(a2)
andia4,a4,2
addwa6,a6,a7
sw  a6,0(a0)
beq a4,zero,.L3
lw  a7,4(a1)
lw  a4,4(a2)
li  a6,3
addwa4,a4,a7
sw  a4,4(a0)
bne a5,a6,.L3
lw  a6,8(a2)
lw  a4,8(a1)
addwa4,a4,a6
sw  a4,8(a0)
.L3:
subwa3,a3,a5
sllia4,a3,32
csrra6,vlenb
srlia4,a4,32
srlia6,a6,2
sllia3,a5,2
mv  a5,a4
bgtua4,a6,.L17
.L5:
csrra6,vlenb
add a1,a1,a3
add a2,a2,a3
add a0,a0,a3
srlia7,a6,2
li  a3,0
.L8:
vsetvli zero,a5,e32,m1,ta,ma
vle32.v v1,0(a1)
vle32.v v2,0(a2)
vsetvli t1,zero,e32,m1,ta,ma
add a3,a3,a7
vadd.vv v1,v1,v2
vsetvli zero,a5,e32,m1,ta,ma
vse32.v v1,0(a0)
mv  a5,a4
bleua4,a3,.L6
mv  a5,a3
.L6:
sub a5,a4,a5
bleua5,a7,.L7
mv  a5,a7
.L7:
add a1,a1,a6
add a2,a2,a6
add a0,a0,a6
bne a5,zero,.L8
.L1:
ret
.L17:
mv  a5,a6
j   .L5

After this patch:
f:
ble a3,zero,.L1
csrra4,vlenb
srlia4,a4,2
mv  a5,a3
bgtua3,a4,.L9
.L3:
csrra6,vlenb
li  a4,0
srlia7,a6,2
.L6:
vsetvli zero,a5,e32,m1,ta,ma
vle32.v v2,0(a1)
vle32.v v1,0(a2)
vsetvli t1,zero,e32,m1,ta,ma
add a4,a4,a7
vadd.vv v1,v1,v2
vsetvli zero,a5,e32,m1,ta,ma
vse32.v v1,0(a0)
mv  a5,a3
bleua3,a4,.L4
mv  a5,a4
.L4:
sub a5,a3,a5
bleua5,a7,.L5
mv  a5,a7
.L5:
add a0,a0,a6
add a2,a2,a6
add a1,a1,a6
bne a5,zero,.L6
.L1:
ret
.L9:
mv  a5,a4
j   .L3

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_vectorize_preferred_vector_alignment): 
New function.
(TARGET_VECTORIZE_PREFERRED_VECTOR_ALIGNMENT): New target hook.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/binop/shift-rv32gcv.c: Adapt testcase.
* gcc.target/riscv/rvv/autovec/align-1.c: New test.

---
 gcc/config/riscv/riscv.cc | 22 +++
 .../gcc.target/riscv/rvv/autovec/align-1.c| 12 ++
 .../riscv/rvv/autovec/binop/shift-rv32gcv.c   | 10 +
 3 files changed, 40 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/align-1.c

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index de578b5b899..a5776a550b2 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -7499,6 +7499,24 @@ riscv_preferred_simd_mode (scalar_mode mode)
   return word_mode;
 }
 
+/* Implement target hook TARGET_VECTORIZE_PREFERRED_VECTOR_ALIGNMENT.  */
+
+static poly_uint64
+riscv_vectorize_preferred_vector_alignment (const_tree type)
+{
+  if (riscv_v_ext_vector_mode_p (TYPE_MODE (type)))
+{
+  /* If the length of the vector is a fixed power of 2, try to align
+to that length, otherwise don't try to align at all.  */
+  HOST_WIDE_INT result;
+  if (!GET_MODE_BITSIZE (TYPE_MODE (type)).is_constant (&result)
+ || !pow2p_hwi (result))
+   result = TYPE_ALIGN (TREE_TYPE (type));
+  return result;
+}
+  return TYPE_ALIGN (type);
+}
+
 /* Initialize the GCC target structure.  */
 #undef TARGET_ASM_ALIGNED_HI_OP
 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
@@ -7771,6 +7789,10 @@ riscv_preferred_simd_mode (scalar_mode mode)
 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE riscv_preferred_simd_mode
 
+#undef TARGET_VECTORIZE_PREFERRED_VECTOR_ALIGNMENT
+#define TARGET_VECTORIZE_PREFERRED_VECTOR_ALIGNMENT \
+  riscv_vectorize_preferred_vector_alignment
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include "gt-riscv.h"
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/align-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/align-1.c
new file mode 100644
index 000..14201e1f7e0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/align-1.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32d -O3 --param 

RE: [PATCH] Machine_Mode: Extend machine_mode from 8 to 16 bits

2023-05-13 Thread Li, Pan2 via Gcc-patches
Oops, looks missed this part when I search all machine_mode by word. Thanks 
kito for catching this.

It seems there is no easy way to remind the developer to change (for example 16 
to 32 bits) the below part in future, how about add some comments to 
MACHINE_MODE_BITSIZE for this?

Pan

-Original Message-
From: Kito Cheng  
Sent: Saturday, May 13, 2023 4:45 PM
To: Bernhard Reutner-Fischer 
Cc: Richard Biener ; Richard Biener via Gcc-patches 
; Li, Pan2 ; juzhe.zh...@rivai.ai; 
Wang, Yanzhang ; jeffreya...@gmail.com; 
richard.sandif...@arm.com
Subject: Re: [PATCH] Machine_Mode: Extend machine_mode from 8 to 16 bits

Hi Pan:

Tried this patch and I ran into some issues, some variables are using unsigned 
char to hold machine mode and will have problems when the number of modes is 
larger than 255...

And here is the fix:


diff --git a/gcc/genmodes.cc b/gcc/genmodes.cc index 715787b8f483..55ac2adb5596 
100644
--- a/gcc/genmodes.cc
+++ b/gcc/genmodes.cc
@@ -1141,10 +1141,10 @@ inline __attribute__((__always_inline__))\n\
#else\n\
extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\ 
#endif\n\ -unsigned char\n\
+unsigned short\n\
mode_inner_inline (machine_mode mode)\n\ {\n\
-  extern const unsigned char mode_inner[NUM_MACHINE_MODES];\n\
+  extern const unsigned short mode_inner[NUM_MACHINE_MODES];\n\
  gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
  switch (mode)\n\
{");
@@ -1529,7 +1529,7 @@ emit_mode_wider (void)
  int c;
  struct mode_data *m;

-  print_decl ("unsigned char", "mode_next", "NUM_MACHINE_MODES");
+  print_decl ("unsigned short", "mode_next", "NUM_MACHINE_MODES");

  for_all_modes (c, m)
tagged_printf ("E_%smode",
@@ -1537,7 +1537,7 @@ emit_mode_wider (void)
  m->name);

  print_closer ();
-  print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
+  print_decl ("unsigned short", "mode_wider", "NUM_MACHINE_MODES");

  for_all_modes (c, m)
{
@@ -1568,7 +1568,7 @@ emit_mode_wider (void)
}

  print_closer ();
-  print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
+  print_decl ("unsigned short", "mode_2xwider", "NUM_MACHINE_MODES");

  for_all_modes (c, m)
{
@@ -1625,7 +1625,7 @@ emit_mode_complex (void)
  int c;
  struct mode_data *m;

-  print_decl ("unsigned char", "mode_complex", "NUM_MACHINE_MODES");
+  print_decl ("unsigned short", "mode_complex", "NUM_MACHINE_MODES");

  for_all_modes (c, m)
tagged_printf ("E_%smode",
@@ -1665,7 +1665,7 @@ emit_mode_inner (void)
  int c;
  struct mode_data *m;

-  print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
+  print_decl ("unsigned short", "mode_inner", "NUM_MACHINE_MODES");

  for_all_modes (c, m)
tagged_printf ("E_%smode",
@@ -1738,7 +1738,7 @@ emit_class_narrowest_mode (void) {
  int c;

-  print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
+  print_decl ("unsigned short", "class_narrowest_mode", 
+ "MAX_MODE_CLASS");

  for (c = 0; c < MAX_MODE_CLASS; c++)
{
diff --git a/gcc/machmode.h b/gcc/machmode.h index f1865c1ef425..a168d6f0da2e 
100644
--- a/gcc/machmode.h
+++ b/gcc/machmode.h
@@ -24,13 +24,13 @@ typedef opt_mode opt_machine_mode;

extern CONST_MODE_SIZE poly_uint16_pod mode_size[NUM_MACHINE_MODES]; extern 
CONST_MODE_PRECISION poly_uint16_pod mode_precision[NUM_MACHINE_MODES];
-extern const unsigned char mode_inner[NUM_MACHINE_MODES];
+extern const unsigned short mode_inner[NUM_MACHINE_MODES];
extern CONST_MODE_NUNITS poly_uint16_pod mode_nunits[NUM_MACHINE_MODES]; extern 
CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];
extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];
-extern const unsigned char mode_next[NUM_MACHINE_MODES]; -extern const 
unsigned char mode_wider[NUM_MACHINE_MODES]; -extern const unsigned char 
mode_2xwider[NUM_MACHINE_MODES];
+extern const unsigned short mode_next[NUM_MACHINE_MODES]; extern const 
+unsigned short mode_wider[NUM_MACHINE_MODES]; extern const unsigned 
+short mode_2xwider[NUM_MACHINE_MODES];

template
struct mode_traits
@@ -797,7 +797,7 @@ GET_MODE_2XWIDER_MODE (const T &m) }

/* Get the complex mode from the component mode.  */ -extern const unsigned 
char mode_complex[NUM_MACHINE_MODES];
+extern const unsigned short mode_complex[NUM_MACHINE_MODES];
#define GET_MODE_COMPLEX_MODE(MODE) ((machine_mode) mode_complex[MODE])

/* Represents a machine mode that must have a fixed size.  The main @@ -946,7 
+946,7 @@ extern unsigned get_mode_alignment (machine_mode);

/* For each class, get the narrowest mode in that class.  */

-extern const unsigned char class_narrowest_mode[MAX_MODE_CLASS];
+extern const unsigned short class_narrowest_mode[MAX_MODE_CLASS];
#define GET_CLASS_NARROWEST_MODE(CLASS) \
  ((machine_mode) class_narrowest_mode[CLASS])

--
2.39.2


[PATCH v3] Machine_Mode: Extend machine_mode from 8 to 16 bits

2023-05-13 Thread Pan Li via Gcc-patches
From: Pan Li 

We are running out of the machine_mode(8 bits) in RISC-V backend. Thus
we would like to extend the machine_mode bit size from 8 to 16 bits.
However, it is sensitive to extend the memory size in common structure
like tree or rtx. This patch would like to extend the machine_mode bits
to 16 bits by shrinking, like:

* Swap the bit size of code and machine code in rtx_def.
* Adjust the machine_mode location and spare in tree.

The memory impact of this patch for correlated structure looks like below:

+---+--+-+--+
| struct/bytes  | upstream | patched | diff |
+---+--+-+--+
| rtx_obj_reference |8 |  12 |   +4 |
| ext_modified  |2 |   4 |   +2 |
| ira_allocno   |  192 | 184 |   -8 |
| qty_table_elem|   40 |  40 |0 |
| reg_stat_type |   64 |  64 |0 |
| rtx_def   |   40 |  40 |0 |
| table_elt |   80 |  80 |0 |
| tree_decl_common  |  112 | 112 |0 |
| tree_type_common  |  128 | 128 |0 |
+---+--+-+--+

The tree and rtx related struct has no memory changes after this patch,
and the machine_mode changes to 16 bits already.

Signed-off-by: Pan Li 
Co-authored-by: Ju-Zhe Zhong 
Co-authored-by: Kito Cheng 
Co-Authored-By: Richard Biener 
Co-Authored-By: Richard Sandiford 

gcc/ChangeLog:

* combine.cc (struct reg_stat_type): Extend machine_mode to 16 bits.
* cse.cc (struct qty_table_elem): Extend machine_mode to 16 bits
(struct table_elt): Extend machine_mode to 16 bits.
(struct set): Ditto.
* genmodes.cc (emit_mode_wider): Extend type from char to short.
(emit_mode_complex): Ditto.
(emit_mode_inner): Ditto.
(emit_class_narrowest_mode): Ditto.
* genopinit.cc (main): Extend the machine_mode limit.
* ira-int.h (struct ira_allocno): Extend machine_mode to 16 bits and
re-ordered the struct fields for padding.
* machmode.h (MACHINE_MODE_BITSIZE): New macro.
(GET_MODE_2XWIDER_MODE): Extend type from char to short.
(get_mode_alignment): Extend type from char to short.
* ree.cc (struct ext_modified): Extend machine_mode to 16 bits and
removed the ATTRIBUTE_PACKED.
* rtl-ssa/accesses.h: Extend machine_mode to 16 bits.
* rtl.h (RTX_CODE_BITSIZE): New macro.
(struct rtx_def): Swap both the bit size and location between the
rtx_code and the machine_mode.
(subreg_shape::unique_id): Extend the machine_mode limit.
* rtlanal.h: Extend machine_mode to 16 bits.
* tree-core.h (struct tree_type_common): Extend machine_mode to 16
bits and re-ordered the struct fields for padding.
(struct tree_decl_common): Extend machine_mode to 16 bits.
---
 gcc/combine.cc |  4 +--
 gcc/cse.cc | 16 
 gcc/genmodes.cc| 16 ++--
 gcc/genopinit.cc   |  3 ++-
 gcc/ira-int.h  | 56 +-
 gcc/machmode.h | 27 +++-
 gcc/ree.cc |  4 +--
 gcc/rtl-ssa/accesses.h |  2 +-
 gcc/rtl.h  | 12 +
 gcc/rtlanal.h  |  2 +-
 gcc/tree-core.h|  9 ---
 11 files changed, 82 insertions(+), 69 deletions(-)

diff --git a/gcc/combine.cc b/gcc/combine.cc
index 5aa0ec5c45a..a23caeed96f 100644
--- a/gcc/combine.cc
+++ b/gcc/combine.cc
@@ -200,7 +200,7 @@ struct reg_stat_type {
 
   unsigned HOST_WIDE_INT   last_set_nonzero_bits;
   char last_set_sign_bit_copies;
-  ENUM_BITFIELD(machine_mode)  last_set_mode : 8;
+  ENUM_BITFIELD(machine_mode)  last_set_mode : MACHINE_MODE_BITSIZE;
 
   /* Set nonzero if references to register n in expressions should not be
  used.  last_set_invalid is set nonzero when this register is being
@@ -235,7 +235,7 @@ struct reg_stat_type {
  truncation if we know that value already contains a truncated
  value.  */
 
-  ENUM_BITFIELD(machine_mode)  truncated_to_mode : 8;
+  ENUM_BITFIELD(machine_mode)  truncated_to_mode : MACHINE_MODE_BITSIZE;
 };
 
 
diff --git a/gcc/cse.cc b/gcc/cse.cc
index b10c9b0c94d..86403b95938 100644
--- a/gcc/cse.cc
+++ b/gcc/cse.cc
@@ -248,10 +248,8 @@ struct qty_table_elem
   rtx comparison_const;
   int comparison_qty;
   unsigned int first_reg, last_reg;
-  /* The sizes of these fields should match the sizes of the
- code and mode fields of struct rtx_def (see rtl.h).  */
-  ENUM_BITFIELD(rtx_code) comparison_code : 16;
-  ENUM_BITFIELD(machine_mode) mode : 8;
+  ENUM_BITFIELD(machine_mode) mode : MACHINE_MODE_BITSIZE;
+  ENUM_BITFIELD(rtx_code) comparison_code : RTX_CODE_BITSIZE;
 };
 
 /* The table of all qtys, indexed by qty number.  */
@@ -404,9 +402,7 @@ struct table_elt
   struct table_elt *related_value;
   int cost;
   int regcost;
-  /* The size of this field s

Re: [PATCH] libffi: fix handling of homogeneous float128 structs [PR109447]

2023-05-13 Thread Peter Bergner via Gcc-patches
On 5/10/23 2:34 AM, Andreas Schwab wrote:
> On Mai 09 2023, Peter Bergner via Gcc-patches wrote:
>> I'm sorry to be dense, but can you point to the specific line?  In my
>> $GCC_BUILD/Makefile, the only mention of LD_LIBRARY_PATH is:
>>
>>   RPATH_ENVVAR = LD_LIBRARY_PATH
>>
>> ...so that isn't setting LD_LIBRARY_PATH, but using it.
> 
> Have you considered searching for uses of RPATH_ENVVAR?

Ah, I misread that as RPATH_ENVVAR = $LD_LIBRARY_PATH and was
expecting to see "export LD_LIBRARY_PATH=..." in the code.
Thanks for the pointer!

Peter




[PATCH 02/14] analyzer: use _P() defines from tree.h

2023-05-13 Thread Bernhard Reutner-Fischer via Gcc-patches
From: Bernhard Reutner-Fischer 

gcc/analyzer/ChangeLog:

* region-model-manager.cc (get_code_for_cast): Use _P defines from
tree.h.
(region_model_manager::get_or_create_cast): Ditto.
(region_model_manager::get_region_for_global): Ditto.
* region-model.cc (region_model::get_lvalue_1): Ditto.
* region.cc (decl_region::maybe_get_constant_value): Ditto.
---
 gcc/analyzer/region-model-manager.cc | 8 
 gcc/analyzer/region-model.cc | 2 +-
 gcc/analyzer/region.cc   | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/analyzer/region-model-manager.cc 
b/gcc/analyzer/region-model-manager.cc
index fab5bba15d5..3b95e432aba 100644
--- a/gcc/analyzer/region-model-manager.cc
+++ b/gcc/analyzer/region-model-manager.cc
@@ -507,7 +507,7 @@ get_code_for_cast (tree dst_type, tree src_type)
   if (!src_type)
 return NOP_EXPR;
 
-  if (TREE_CODE (src_type) == REAL_TYPE)
+  if (SCALAR_FLOAT_TYPE_P (src_type))
 {
   if (TREE_CODE (dst_type) == INTEGER_TYPE)
return FIX_TRUNC_EXPR;
@@ -531,9 +531,9 @@ region_model_manager::get_or_create_cast (tree type, const 
svalue *arg)
 return arg;
 
   /* Don't attempt to handle casts involving vector types for now.  */
-  if (TREE_CODE (type) == VECTOR_TYPE
+  if (VECTOR_TYPE_P (type)
   || (arg->get_type ()
- && TREE_CODE (arg->get_type ()) == VECTOR_TYPE))
+ && VECTOR_TYPE_P (arg->get_type (
 return get_or_create_unknown_svalue (type);
 
   enum tree_code op = get_code_for_cast (type, arg->get_type ());
@@ -1410,7 +1410,7 @@ region_model_manager::get_region_for_label (tree label)
 const decl_region *
 region_model_manager::get_region_for_global (tree expr)
 {
-  gcc_assert (TREE_CODE (expr) == VAR_DECL);
+  gcc_assert (VAR_P (expr));
 
   decl_region **slot = m_globals_map.get (expr);
   if (slot)
diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc
index fb81d43f91b..3bb3df2f063 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -2092,7 +2092,7 @@ region_model::get_lvalue_1 (path_var pv, 
region_model_context *ctxt) const
   {
gcc_assert (TREE_CODE (expr) == SSA_NAME
|| TREE_CODE (expr) == PARM_DECL
-   || TREE_CODE (expr) == VAR_DECL
+   || VAR_P (expr)
|| TREE_CODE (expr) == RESULT_DECL);
 
int stack_index = pv.m_stack_depth;
diff --git a/gcc/analyzer/region.cc b/gcc/analyzer/region.cc
index a18bfa50d09..8f0eb569b33 100644
--- a/gcc/analyzer/region.cc
+++ b/gcc/analyzer/region.cc
@@ -1162,7 +1162,7 @@ decl_region::get_stack_depth () const
 const svalue *
 decl_region::maybe_get_constant_value (region_model_manager *mgr) const
 {
-  if (TREE_CODE (m_decl) == VAR_DECL
+  if (VAR_P (m_decl)
   && DECL_IN_CONSTANT_POOL (m_decl)
   && DECL_INITIAL (m_decl)
   && TREE_CODE (DECL_INITIAL (m_decl)) == CONSTRUCTOR)
-- 
2.30.2



[PATCH 07/14] d: use _P() defines from tree.h

2023-05-13 Thread Bernhard Reutner-Fischer via Gcc-patches
From: Bernhard Reutner-Fischer 

gcc/d/ChangeLog:

* d-codegen.cc (underlying_complex_expr): Use _P defines from tree.h.
* d-convert.cc (convert): Ditto.
(convert_for_rvalue): Ditto.
---
 gcc/d/d-codegen.cc | 2 +-
 gcc/d/d-convert.cc | 9 -
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 5c6c300ecec..9bae06077b5 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -1599,7 +1599,7 @@ underlying_complex_expr (tree type, tree expr)
   /* Build a constructor from the real and imaginary parts.  */
   if (COMPLEX_FLOAT_TYPE_P (TREE_TYPE (expr)) &&
   (!INDIRECT_REF_P (expr)
-   || !CONVERT_EXPR_CODE_P (TREE_CODE (TREE_OPERAND (expr, 0)
+   || !CONVERT_EXPR_P (TREE_OPERAND (expr, 0
 {
   vec  *ve = NULL;
   CONSTRUCTOR_APPEND_ELT (ve, TYPE_FIELDS (type),
diff --git a/gcc/d/d-convert.cc b/gcc/d/d-convert.cc
index 9e7fcd506f8..cdbd69cf012 100644
--- a/gcc/d/d-convert.cc
+++ b/gcc/d/d-convert.cc
@@ -257,7 +257,7 @@ convert (tree type, tree expr)
 return fold_convert (type, expr);
   if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
 return error_mark_node;
-  if (TREE_CODE (TREE_TYPE (expr)) == VOID_TYPE)
+  if (VOID_TYPE_P (TREE_TYPE (expr)))
 {
   error ("void value not ignored as it ought to be");
   return error_mark_node;
@@ -270,8 +270,7 @@ convert (tree type, tree expr)
 
 case INTEGER_TYPE:
 case ENUMERAL_TYPE:
-  if (TREE_CODE (etype) == POINTER_TYPE
- || TREE_CODE (etype) == REFERENCE_TYPE)
+  if (POINTER_TYPE_P (etype))
{
  if (integer_zerop (e))
return build_int_cst (type, 0);
@@ -300,7 +299,7 @@ convert (tree type, tree expr)
   return fold (convert_to_real (type, e));
 
 case COMPLEX_TYPE:
-  if (TREE_CODE (etype) == REAL_TYPE && TYPE_IMAGINARY_FLOAT (etype))
+  if (SCALAR_FLOAT_TYPE_P (etype) && TYPE_IMAGINARY_FLOAT (etype))
return fold_build2 (COMPLEX_EXPR, type,
build_zero_cst (TREE_TYPE (type)),
convert (TREE_TYPE (type), expr));
@@ -656,7 +655,7 @@ convert_for_rvalue (tree expr, Type *etype, Type *totype)
   && ebtype->ty == TY::Tsarray
   && tbtype->nextOf ()->ty == ebtype->nextOf ()->ty
   && INDIRECT_REF_P (expr)
-  && CONVERT_EXPR_CODE_P (TREE_CODE (TREE_OPERAND (expr, 0)))
+  && CONVERT_EXPR_P (TREE_OPERAND (expr, 0))
   && TREE_CODE (TREE_OPERAND (TREE_OPERAND (expr, 0), 0)) == ADDR_EXPR)
 {
   /* If expression is a vector that was casted to an array either by
-- 
2.30.2



[PATCH 10/14] c: use _P() defines from tree.h

2023-05-13 Thread Bernhard Reutner-Fischer via Gcc-patches
From: Bernhard Reutner-Fischer 

gcc/c-family/ChangeLog:

* c-ada-spec.cc (has_static_fields): Use _P() defines from tree.h.
(dump_ada_declaration): Ditto.
(dump_ada_structure): Ditto.
* c-common.cc (unsafe_conversion_p): Ditto.
(shorten_compare): Ditto.
(pointer_int_sum): Ditto.
(c_common_truthvalue_conversion): Ditto.
(scalar_to_vector): Ditto.
* c-common.h (gnu_vector_type_p): Ditto.
* c-omp.cc (c_omp_depend_t_p): Ditto.
(c_omp_split_clauses): Ditto.
* c-ubsan.cc (ubsan_instrument_division): Ditto.
* c-warn.cc (conversion_warning): Ditto.
(warnings_for_convert_and_check): Ditto.

gcc/c/ChangeLog:

* c-convert.cc (c_convert): Ditto.
* c-decl.cc (merge_decls): Ditto.
* c-parser.cc (c_parser_omp_clause_reduction): Ditto.
(c_parser_omp_declare_reduction): Ditto.
* c-typeck.cc (build_component_ref): Ditto.
(convert_argument): Ditto.
(pointer_diff): Ditto.
(build_unary_op): Ditto.
(build_c_cast): Ditto.
(build_modify_expr): Ditto.
(store_init_value): Ditto.
(constexpr_init_fits_real_type): Ditto.
(check_constexpr_init): Ditto.
(c_finish_return): Ditto.
(handle_omp_array_sections_1): Ditto.
(c_finish_omp_clauses): Ditto.
* gimple-parser.cc (c_finish_gimple_return): Ditto.

libcc1/ChangeLog:

* libcc1plugin.cc (plugin_float_type): Ditto.
* libcp1plugin.cc (plugin_reactivate_decl): Ditto.
(plugin_get_float_type): Ditto.
---
 gcc/c-family/c-ada-spec.cc |  6 ++---
 gcc/c-family/c-common.cc   | 32 +++
 gcc/c-family/c-common.h|  2 +-
 gcc/c-family/c-omp.cc  |  5 ++--
 gcc/c-family/c-ubsan.cc|  2 +-
 gcc/c-family/c-warn.cc |  6 ++---
 gcc/c/c-convert.cc |  4 +--
 gcc/c/c-decl.cc|  6 ++---
 gcc/c/c-parser.cc  |  4 +--
 gcc/c/c-typeck.cc  | 52 +++---
 gcc/c/gimple-parser.cc |  2 +-
 libcc1/libcc1plugin.cc |  2 +-
 libcc1/libcp1plugin.cc |  4 +--
 13 files changed, 63 insertions(+), 64 deletions(-)

diff --git a/gcc/c-family/c-ada-spec.cc b/gcc/c-family/c-ada-spec.cc
index b50b3877564..050994d8416 100644
--- a/gcc/c-family/c-ada-spec.cc
+++ b/gcc/c-family/c-ada-spec.cc
@@ -1051,7 +1051,7 @@ has_static_fields (const_tree type)
 return false;
 
   for (tree fld = TYPE_FIELDS (type); fld; fld = TREE_CHAIN (fld))
-if (TREE_CODE (fld) == VAR_DECL && DECL_NAME (fld))
+if (VAR_P (fld) && DECL_NAME (fld))
   return true;
 
   return false;
@@ -3244,7 +3244,7 @@ dump_ada_declaration (pretty_printer *buffer, tree t, 
tree type, int spc)
   if (need_indent)
INDENT (spc);
 
-  if ((TREE_CODE (t) == FIELD_DECL || TREE_CODE (t) == VAR_DECL)
+  if ((TREE_CODE (t) == FIELD_DECL || VAR_P (t))
  && DECL_NAME (t))
check_type_name_conflict (buffer, t);
 
@@ -3462,7 +3462,7 @@ dump_ada_structure (pretty_printer *buffer, tree node, 
tree type, bool nested,
   /* Print the static fields of the structure, if any.  */
   for (tree tmp = TYPE_FIELDS (node); tmp; tmp = TREE_CHAIN (tmp))
 {
-  if (TREE_CODE (tmp) == VAR_DECL && DECL_NAME (tmp))
+  if (VAR_P (tmp) && DECL_NAME (tmp))
{
  if (need_semicolon)
{
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index 2b4c82facf7..9c8eed5442a 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -1483,7 +1483,7 @@ unsafe_conversion_p (tree type, tree expr, tree result, 
bool check_sign)
 
   /* Warn for real constant that is not an exact integer converted
 to integer type.  */
-  if (TREE_CODE (expr_type) == REAL_TYPE
+  if (SCALAR_FLOAT_TYPE_P (expr_type)
  && TREE_CODE (type) == INTEGER_TYPE)
{
  if (!real_isinteger (TREE_REAL_CST_PTR (expr), TYPE_MODE (expr_type)))
@@ -1508,7 +1508,7 @@ unsafe_conversion_p (tree type, tree expr, tree result, 
bool check_sign)
  else
give_warning = UNSAFE_OTHER;
}
-  else if (TREE_CODE (type) == REAL_TYPE)
+  else if (SCALAR_FLOAT_TYPE_P (type))
{
  /* Warn for an integer constant that does not fit into real type.  */
  if (TREE_CODE (expr_type) == INTEGER_TYPE)
@@ -1519,7 +1519,7 @@ unsafe_conversion_p (tree type, tree expr, tree result, 
bool check_sign)
}
  /* Warn for a real constant that does not fit into a smaller
 real type.  */
- else if (TREE_CODE (expr_type) == REAL_TYPE
+ else if (SCALAR_FLOAT_TYPE_P (expr_type)
   && TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
{
  REAL_VALUE_TYPE a = TREE_REAL_CST (expr);
@@ -1579,7 +1579,7 @@ unsafe_conversion_p (tree type, tree expr, tree result, 
bool check_sign)
   else
 {
   /* Warn for real types converted to

[PATCH 13/14] omp: use _P() defines from tree.h

2023-05-13 Thread Bernhard Reutner-Fischer via Gcc-patches
From: Bernhard Reutner-Fischer 

gcc/ChangeLog:

* omp-low.cc (scan_sharing_clauses): Use _P() defines from tree.h.
(lower_reduction_clauses): Ditto.
(lower_send_clauses): Ditto.
(lower_omp_task_reductions): Ditto.
* omp-oacc-neuter-broadcast.cc (install_var_field): Ditto.
(worker_single_copy): Ditto.
* omp-offload.cc (oacc_rewrite_var_decl): Ditto.
* omp-simd-clone.cc (plausible_type_for_simd_clone): Ditto.
---
 gcc/omp-low.cc   | 36 
 gcc/omp-oacc-neuter-broadcast.cc | 10 -
 gcc/omp-offload.cc   |  2 +-
 gcc/omp-simd-clone.cc|  2 +-
 4 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index dddf5b59d8f..9db33d2a48b 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -1267,7 +1267,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
  tree t = TREE_OPERAND (decl, 0);
  if (TREE_CODE (t) == POINTER_PLUS_EXPR)
t = TREE_OPERAND (t, 0);
- if (TREE_CODE (t) == INDIRECT_REF
+ if (INDIRECT_REF_P (t)
  || TREE_CODE (t) == ADDR_EXPR)
t = TREE_OPERAND (t, 0);
  if (is_omp_target (ctx->stmt))
@@ -1276,7 +1276,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
{
  gcc_assert (DECL_HAS_VALUE_EXPR_P (t));
  t = DECL_VALUE_EXPR (t);
- gcc_assert (TREE_CODE (t) == INDIRECT_REF);
+ gcc_assert (INDIRECT_REF_P (t));
  t = TREE_OPERAND (t, 0);
  gcc_assert (DECL_P (t));
}
@@ -1383,7 +1383,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
}
  else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
{
- if (TREE_CODE (decl) == INDIRECT_REF)
+ if (INDIRECT_REF_P (decl))
decl = TREE_OPERAND (decl, 0);
  install_var_field (decl, true, 3, ctx);
}
@@ -1457,7 +1457,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
  && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
{
  tree decl2 = DECL_VALUE_EXPR (decl);
- gcc_assert (TREE_CODE (decl2) == INDIRECT_REF);
+ gcc_assert (INDIRECT_REF_P (decl2));
  decl2 = TREE_OPERAND (decl2, 0);
  gcc_assert (DECL_P (decl2));
  install_var_local (decl2, ctx);
@@ -1467,7 +1467,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
 
case OMP_CLAUSE_HAS_DEVICE_ADDR:
  decl = OMP_CLAUSE_DECL (c);
- while (TREE_CODE (decl) == INDIRECT_REF
+ while (INDIRECT_REF_P (decl)
 || TREE_CODE (decl) == ARRAY_REF)
decl = TREE_OPERAND (decl, 0);
  goto do_private;
@@ -1635,7 +1635,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
  == GOMP_MAP_FIRSTPRIVATE_REFERENCE)))
{
  if (TREE_CODE (decl) == COMPONENT_REF
- || (TREE_CODE (decl) == INDIRECT_REF
+ || (INDIRECT_REF_P (decl)
  && TREE_CODE (TREE_OPERAND (decl, 0)) == COMPONENT_REF
  && (((TREE_CODE (TREE_TYPE (TREE_OPERAND (decl, 0)))
== REFERENCE_TYPE)
@@ -1646,7 +1646,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
  && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
{
  tree decl2 = DECL_VALUE_EXPR (decl);
- gcc_assert (TREE_CODE (decl2) == INDIRECT_REF);
+ gcc_assert (INDIRECT_REF_P (decl2));
  decl2 = TREE_OPERAND (decl2, 0);
  gcc_assert (DECL_P (decl2));
  install_var_local (decl2, ctx);
@@ -1660,7 +1660,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
  && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
{
  tree decl2 = DECL_VALUE_EXPR (decl);
- gcc_assert (TREE_CODE (decl2) == INDIRECT_REF);
+ gcc_assert (INDIRECT_REF_P (decl2));
  decl2 = TREE_OPERAND (decl2, 0);
  gcc_assert (DECL_P (decl2));
  install_var_field (decl2, true, 3, ctx);
@@ -1802,7 +1802,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
  decl = OMP_CLAUSE_DECL (c);
  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
{
- while (TREE_CODE (decl) == INDIRECT_REF
+ while (INDIRECT_REF_P (decl)
 || TREE_CODE (decl) == ARRAY_REF)
decl = TREE_OPERAND (decl, 0);
}
@@ -1815,7 +1815,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
  && is_gimple_omp_offloaded (ctx->stmt))

[PATCH 12/14] go: use _P() defines from tree.h

2023-05-13 Thread Bernhard Reutner-Fischer via Gcc-patches
From: Bernhard Reutner-Fischer 

gcc/go/ChangeLog:

* go-gcc.cc (Gcc_backend::fill_in_array): Use _P() defines from tree.h.
(Gcc_backend::named_type): Ditto.
(Gcc_backend::convert_expression): Ditto.
(operator_to_tree_code): Ditto.
(Gcc_backend::init_statement): Ditto.

gcc/ChangeLog:

* godump.cc (go_format_type): Ditto.
(go_output_typedef): Ditto.
---
 gcc/go/go-gcc.cc | 10 +-
 gcc/godump.cc|  4 ++--
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc
index 41ae9f83731..ad001a9044a 100644
--- a/gcc/go/go-gcc.cc
+++ b/gcc/go/go-gcc.cc
@@ -1168,7 +1168,7 @@ Gcc_backend::fill_in_array(Btype* fill, Btype* 
element_type,
   if (element_type_tree == error_mark_node || length_tree == error_mark_node)
 return this->error_type();
 
-  gcc_assert(TYPE_SIZE(element_type_tree) != NULL_TREE);
+  gcc_assert (COMPLETE_TYPE_P (element_type_tree));
 
   length_tree = fold_convert(sizetype, length_tree);
 
@@ -1347,7 +1347,7 @@ Gcc_backend::named_type(const std::string& name, Btype* 
btype,
   if (TYPE_NAME(type) == NULL_TREE
   && location.gcc_location() == BUILTINS_LOCATION
   && (TREE_CODE(type) == INTEGER_TYPE
- || TREE_CODE(type) == REAL_TYPE
+ || SCALAR_FLOAT_TYPE_P (type)
  || TREE_CODE(type) == COMPLEX_TYPE
  || TREE_CODE(type) == BOOLEAN_TYPE))
 {
@@ -1670,7 +1670,7 @@ Gcc_backend::convert_expression(Btype* type, Bexpression* 
expr,
 }
   else if (TREE_CODE(type_tree) == INTEGER_TYPE)
 ret = fold(convert_to_integer(type_tree, expr_tree));
-  else if (TREE_CODE(type_tree) == REAL_TYPE)
+  else if (SCALAR_FLOAT_TYPE_P (type_tree))
 ret = fold(convert_to_real(type_tree, expr_tree));
   else if (TREE_CODE(type_tree) == COMPLEX_TYPE)
 ret = fold(convert_to_complex(type_tree, expr_tree));
@@ -1880,7 +1880,7 @@ operator_to_tree_code(Operator op, tree type)
   code = MULT_EXPR;
   break;
 case OPERATOR_DIV:
-  if (TREE_CODE(type) == REAL_TYPE || TREE_CODE(type) == COMPLEX_TYPE)
+  if (SCALAR_FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
code = RDIV_EXPR;
   else
code = TRUNC_DIV_EXPR;
@@ -2223,7 +2223,7 @@ Gcc_backend::init_statement(Bfunction*, Bvariable* var, 
Bexpression* init)
   tree init_tree = init->get_tree();
   if (var_tree == error_mark_node || init_tree == error_mark_node)
 return this->error_statement();
-  gcc_assert(TREE_CODE(var_tree) == VAR_DECL);
+  gcc_assert (VAR_P (var_tree));
 
   // To avoid problems with GNU ld, we don't make zero-sized
   // externally visible variables.  That might lead us to doing an
diff --git a/gcc/godump.cc b/gcc/godump.cc
index 0893d5fbc97..1a62753af12 100644
--- a/gcc/godump.cc
+++ b/gcc/godump.cc
@@ -791,7 +791,7 @@ go_format_type (class godump_container *container, tree 
type,
tree real_type;
 
real_type = TREE_TYPE (type);
-   if (TREE_CODE (real_type) == REAL_TYPE)
+   if (SCALAR_FLOAT_TYPE_P (real_type))
  {
switch (TYPE_PRECISION (real_type))
  {
@@ -1100,7 +1100,7 @@ go_output_typedef (class godump_container *container, 
tree decl)
   if (TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE
   && TYPE_SIZE (TREE_TYPE (decl)) != 0
   && !container->decls_seen.contains (TREE_TYPE (decl))
-  && (TYPE_CANONICAL (TREE_TYPE (decl)) == NULL_TREE
+  && (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (decl))
  || !container->decls_seen.contains
(TYPE_CANONICAL (TREE_TYPE (decl)
 {
-- 
2.30.2



[PATCH 11/14] objc: use _P() defines from tree.h

2023-05-13 Thread Bernhard Reutner-Fischer via Gcc-patches
From: Bernhard Reutner-Fischer 

gcc/objc/ChangeLog:

* objc-act.cc (objc_volatilize_decl): Use _P() defines from tree.h.
(objc_is_global_reference_p): Ditto.
(objc_generate_write_barrier): Ditto.
(objc_gimplify_property_ref): Ditto.
* objc-next-runtime-abi-01.cc 
(next_runtime_abi_01_receiver_is_class_object): Ditto.
* objc-next-runtime-abi-02.cc 
(next_runtime_abi_02_receiver_is_class_object): Ditto.
(next_runtime_abi_02_build_objc_method_call): Ditto.
---
 gcc/objc/objc-act.cc | 10 +-
 gcc/objc/objc-next-runtime-abi-01.cc |  2 +-
 gcc/objc/objc-next-runtime-abi-02.cc |  4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/gcc/objc/objc-act.cc b/gcc/objc/objc-act.cc
index 08201749207..e4c49e664e1 100644
--- a/gcc/objc/objc-act.cc
+++ b/gcc/objc/objc-act.cc
@@ -2338,7 +2338,7 @@ objc_volatilize_decl (tree decl)
   /* Do not mess with variables that are 'static' or (already)
  'volatile'.  */
   if (!TREE_THIS_VOLATILE (decl) && !TREE_STATIC (decl)
-  && (TREE_CODE (decl) == VAR_DECL
+  && (VAR_P (decl)
  || TREE_CODE (decl) == PARM_DECL))
 {
   if (local_variables_to_volatilize == NULL)
@@ -3793,7 +3793,7 @@ objc_is_ivar_reference_p (tree expr)
 static int
 objc_is_global_reference_p (tree expr)
 {
-  return (TREE_CODE (expr) == INDIRECT_REF || TREE_CODE (expr) == PLUS_EXPR
+  return (INDIRECT_REF_P (expr) || TREE_CODE (expr) == PLUS_EXPR
  ? objc_is_global_reference_p (TREE_OPERAND (expr, 0))
  : DECL_P (expr)
  ? (DECL_FILE_SCOPE_P (expr) || TREE_STATIC (expr))
@@ -3812,7 +3812,7 @@ objc_generate_write_barrier (tree lhs, enum tree_code 
modifycode, tree rhs)
 
   /* See if we have any lhs casts, and strip them out.  NB: The lvalue casts
  will have been transformed to the form '*(type *)&expr'.  */
-  if (TREE_CODE (lhs) == INDIRECT_REF)
+  if (INDIRECT_REF_P (lhs))
 {
   outer = TREE_OPERAND (lhs, 0);
 
@@ -3864,7 +3864,7 @@ objc_generate_write_barrier (tree lhs, enum tree_code 
modifycode, tree rhs)
 || TREE_CODE (outer) == ARRAY_REF))
 outer = TREE_OPERAND (outer, 0);
 
-  if (TREE_CODE (outer) == INDIRECT_REF)
+  if (INDIRECT_REF_P (outer))
 {
   outer = TREE_OPERAND (outer, 0);
   indirect_p = 1;
@@ -9694,7 +9694,7 @@ objc_gimplify_property_ref (tree *expr_p)
   if (TREE_CODE (getter) == TARGET_EXPR)
 {
   gcc_assert (MAYBE_CLASS_TYPE_P (TREE_TYPE (getter)));
-  gcc_assert (TREE_CODE (TREE_OPERAND (getter, 0)) == VAR_DECL);
+  gcc_assert (VAR_P (TREE_OPERAND (getter, 0)));
   call_exp = TREE_OPERAND (getter, 1);
 }
 #endif
diff --git a/gcc/objc/objc-next-runtime-abi-01.cc 
b/gcc/objc/objc-next-runtime-abi-01.cc
index 8f68f784efe..70ab5262e17 100644
--- a/gcc/objc/objc-next-runtime-abi-01.cc
+++ b/gcc/objc/objc-next-runtime-abi-01.cc
@@ -754,7 +754,7 @@ next_runtime_abi_01_get_arg_type_list_base (vec **argtypes,
 static tree
 next_runtime_abi_01_receiver_is_class_object (tree receiver)
 {
-  if (TREE_CODE (receiver) == VAR_DECL
+  if (VAR_P (receiver)
   && IS_CLASS (TREE_TYPE (receiver)))
 {
   /* The receiver is a variable created by build_class_reference_decl.  */
diff --git a/gcc/objc/objc-next-runtime-abi-02.cc 
b/gcc/objc/objc-next-runtime-abi-02.cc
index bcfc0ce8e19..6548c0078e0 100644
--- a/gcc/objc/objc-next-runtime-abi-02.cc
+++ b/gcc/objc/objc-next-runtime-abi-02.cc
@@ -1571,7 +1571,7 @@ next_runtime_abi_02_get_category_super_ref (location_t 
loc ATTRIBUTE_UNUSED,
 static tree
 next_runtime_abi_02_receiver_is_class_object (tree receiver)
 {
-  if (TREE_CODE (receiver) == VAR_DECL
+  if (VAR_P (receiver)
   && IS_CLASS (TREE_TYPE (receiver))
   && vec_safe_length (classrefs))
 {
@@ -1824,7 +1824,7 @@ next_runtime_abi_02_build_objc_method_call (location_t 
loc,
   checked.  */
   bool check_for_nil = flag_objc_nilcheck;
   if (super
-  || (TREE_CODE (receiver) == VAR_DECL
+  || (VAR_P (receiver)
  && TREE_TYPE (receiver) == objc_class_type))
 check_for_nil = false;
 
-- 
2.30.2



[PATCH 05/14] m2: use _P() defines from tree.h

2023-05-13 Thread Bernhard Reutner-Fischer via Gcc-patches
From: Bernhard Reutner-Fischer 

gcc/m2/ChangeLog:

* gm2-gcc/m2builtins.cc (doradix): Use _P defines from tree.h.
(doplaces): Ditto.
(doexponentmin): Ditto.
(doexponentmax): Ditto.
(dolarge): Ditto.
(dosmall): Ditto.
(dogUnderflow): Ditto.
* gm2-gcc/m2convert.cc (unsafe_conversion_p): Ditto.
* gm2-gcc/m2expr.cc (m2expr_build_unary_op_check): Ditto.
(m2expr_build_binary_op_check): Ditto.
* gm2-gcc/m2tree.cc (m2tree_is_var): Ditto.
* gm2-gcc/m2treelib.cc (build_modify_expr): Ditto.
* gm2-gcc/m2type.cc (gm2_finish_decl): Ditto.
* m2pp.cc (hextree): Ditto.
(m2pp_call_expr): Ditto.
---
 gcc/m2/gm2-gcc/m2builtins.cc | 14 +++---
 gcc/m2/gm2-gcc/m2convert.cc  |  8 
 gcc/m2/gm2-gcc/m2expr.cc |  4 ++--
 gcc/m2/gm2-gcc/m2tree.cc |  2 +-
 gcc/m2/gm2-gcc/m2treelib.cc  |  2 +-
 gcc/m2/gm2-gcc/m2type.cc |  4 ++--
 gcc/m2/m2pp.cc   |  4 ++--
 7 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/gcc/m2/gm2-gcc/m2builtins.cc b/gcc/m2/gm2-gcc/m2builtins.cc
index 8d104c41a1e..3d13e2018d7 100644
--- a/gcc/m2/gm2-gcc/m2builtins.cc
+++ b/gcc/m2/gm2-gcc/m2builtins.cc
@@ -552,7 +552,7 @@ m2builtins_GetBuiltinTypeInfo (location_t location, tree 
type,
 static tree
 doradix (location_t location ATTRIBUTE_UNUSED, tree type)
 {
-  if (TREE_CODE (type) == REAL_TYPE)
+  if (SCALAR_FLOAT_TYPE_P (type))
 {
   enum machine_mode mode = TYPE_MODE (type);
   int radix = REAL_MODE_FORMAT (mode)->b;
@@ -568,7 +568,7 @@ doradix (location_t location ATTRIBUTE_UNUSED, tree type)
 static tree
 doplaces (location_t location ATTRIBUTE_UNUSED, tree type)
 {
-  if (TREE_CODE (type) == REAL_TYPE)
+  if (SCALAR_FLOAT_TYPE_P (type))
 {
   /* Taken from c-family/c-cppbuiltin.cc.  */
   /* The number of decimal digits, q, such that any floating-point
@@ -592,7 +592,7 @@ doplaces (location_t location ATTRIBUTE_UNUSED, tree type)
 static tree
 doexponentmin (location_t location ATTRIBUTE_UNUSED, tree type)
 {
-  if (TREE_CODE (type) == REAL_TYPE)
+  if (SCALAR_FLOAT_TYPE_P (type))
 {
   enum machine_mode mode = TYPE_MODE (type);
   int emin = REAL_MODE_FORMAT (mode)->emin;
@@ -607,7 +607,7 @@ doexponentmin (location_t location ATTRIBUTE_UNUSED, tree 
type)
 static tree
 doexponentmax (location_t location ATTRIBUTE_UNUSED, tree type)
 {
-  if (TREE_CODE (type) == REAL_TYPE)
+  if (SCALAR_FLOAT_TYPE_P (type))
 {
   enum machine_mode mode = TYPE_MODE (type);
   int emax = REAL_MODE_FORMAT (mode)->emax;
@@ -640,7 +640,7 @@ computeLarge (tree type)
 static tree
 dolarge (location_t location ATTRIBUTE_UNUSED, tree type)
 {
-  if (TREE_CODE (type) == REAL_TYPE)
+  if (SCALAR_FLOAT_TYPE_P (type))
 return computeLarge (type);
   return NULL_TREE;
 }
@@ -667,7 +667,7 @@ computeSmall (tree type)
 static tree
 dosmall (location_t location ATTRIBUTE_UNUSED, tree type)
 {
-  if (TREE_CODE (type) == REAL_TYPE)
+  if (SCALAR_FLOAT_TYPE_P (type))
 return computeSmall (type);
   return NULL_TREE;
 }
@@ -735,7 +735,7 @@ dorounds (location_t location ATTRIBUTE_UNUSED, tree type 
ATTRIBUTE_UNUSED)
 static tree
 dogUnderflow (location_t location ATTRIBUTE_UNUSED, tree type)
 {
-  if (TREE_CODE (type) == REAL_TYPE)
+  if (SCALAR_FLOAT_TYPE_P (type))
 {
   enum machine_mode mode = TYPE_MODE (type);
   const struct real_format *fmt = REAL_MODE_FORMAT (mode);
diff --git a/gcc/m2/gm2-gcc/m2convert.cc b/gcc/m2/gm2-gcc/m2convert.cc
index f806669dc39..5d35bcee239 100644
--- a/gcc/m2/gm2-gcc/m2convert.cc
+++ b/gcc/m2/gm2-gcc/m2convert.cc
@@ -91,7 +91,7 @@ unsafe_conversion_p (location_t loc, tree type, tree expr, 
bool produce_warns)
 
   /* Warn for real constant that is not an exact integer converted to
  integer type.  */
-  if (TREE_CODE (expr_type) == REAL_TYPE
+  if (SCALAR_FLOAT_TYPE_P (expr_type)
   && TREE_CODE (type) == INTEGER_TYPE)
 {
   if (!real_isinteger (TREE_REAL_CST_PTR (expr),
@@ -121,7 +121,7 @@ unsafe_conversion_p (location_t loc, tree type, tree expr, 
bool produce_warns)
   else
 give_warning = UNSAFE_OTHER;
 }
-  else if (TREE_CODE (type) == REAL_TYPE)
+  else if (SCALAR_FLOAT_TYPE_P (type))
 {
   /* Warn for an integer constant that does not fit into real type.  */
   if (TREE_CODE (expr_type) == INTEGER_TYPE)
@@ -133,7 +133,7 @@ unsafe_conversion_p (location_t loc, tree type, tree expr, 
bool produce_warns)
 
   /* Warn for a real constant that does not fit into a smaller real
   type.  */
-  else if (TREE_CODE (expr_type) == REAL_TYPE
+ else if (SCALAR_FLOAT_TYPE_P (expr_type)
&& TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
 {
   REAL_VALUE_TYPE a = TREE_REAL_CST (expr);
@@ -145,7 +145,7 @@ unsafe_conversion_p (location_t loc, tree type, tree 

[PATCH 08/14] fortran: use _P() defines from tree.h

2023-05-13 Thread Bernhard Reutner-Fischer via Gcc-patches
From: Bernhard Reutner-Fischer 

gcc/fortran/ChangeLog:

* trans-array.cc (is_pointer_array): Use _P() defines from tree.h.
(gfc_conv_scalarized_array_ref): Ditto.
(gfc_conv_array_ref): Ditto.
* trans-decl.cc (gfc_finish_decl): Ditto.
(gfc_get_symbol_decl): Ditto.
* trans-expr.cc (gfc_trans_pointer_assignment): Ditto.
(gfc_trans_arrayfunc_assign): Ditto.
(gfc_trans_assignment_1): Ditto.
* trans-intrinsic.cc (gfc_conv_intrinsic_minmax): Ditto.
(conv_intrinsic_ieee_value): Ditto.
* trans-io.cc (gfc_convert_array_to_string): Ditto.
* trans-openmp.cc (gfc_omp_is_optional_argument): Ditto.
(gfc_trans_omp_clauses): Ditto.
* trans-stmt.cc (gfc_conv_label_variable): Ditto.
* trans.cc (gfc_build_addr_expr): Ditto.
(get_array_span): Ditto.
---
 gcc/fortran/trans-array.cc | 10 +-
 gcc/fortran/trans-decl.cc  |  4 ++--
 gcc/fortran/trans-expr.cc  |  6 +++---
 gcc/fortran/trans-intrinsic.cc |  4 ++--
 gcc/fortran/trans-io.cc|  2 +-
 gcc/fortran/trans-openmp.cc|  7 +++
 gcc/fortran/trans-stmt.cc  |  2 +-
 gcc/fortran/trans.cc   |  4 ++--
 8 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 9f8aa09673a..15719845ca8 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -880,7 +880,7 @@ is_pointer_array (tree expr)
   || GFC_CLASS_TYPE_P (TREE_TYPE (expr)))
 return false;
 
-  if (TREE_CODE (expr) == VAR_DECL
+  if (VAR_P (expr)
   && GFC_DECL_PTR_ARRAY_P (expr))
 return true;
 
@@ -888,7 +888,7 @@ is_pointer_array (tree expr)
   && GFC_DECL_PTR_ARRAY_P (expr))
 return true;
 
-  if (TREE_CODE (expr) == INDIRECT_REF
+  if (INDIRECT_REF_P (expr)
   && GFC_DECL_PTR_ARRAY_P (TREE_OPERAND (expr, 0)))
 return true;
 
@@ -3803,7 +3803,7 @@ gfc_conv_scalarized_array_ref (gfc_se * se, gfc_array_ref 
* ar,
 {
   if (TREE_CODE (info->descriptor) == COMPONENT_REF)
decl = info->descriptor;
-  else if (TREE_CODE (info->descriptor) == INDIRECT_REF)
+  else if (INDIRECT_REF_P (info->descriptor))
decl = TREE_OPERAND (info->descriptor, 0);
 
   if (decl == NULL_TREE)
@@ -4057,7 +4057,7 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, 
gfc_expr *expr,
 {
   if (TREE_CODE (se->expr) == COMPONENT_REF)
decl = se->expr;
-  else if (TREE_CODE (se->expr) == INDIRECT_REF)
+  else if (INDIRECT_REF_P (se->expr))
decl = TREE_OPERAND (se->expr, 0);
   else
decl = se->expr;
@@ -4069,7 +4069,7 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, 
gfc_expr *expr,
   if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (se->expr)))
{
  decl = se->expr;
- if (TREE_CODE (decl) == INDIRECT_REF)
+ if (INDIRECT_REF_P (decl))
decl = TREE_OPERAND (decl, 0);
}
   else
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index cd32542eb86..7f21dc2b09f 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -558,7 +558,7 @@ gfc_finish_decl (tree decl)
 return;
 
   if (DECL_SIZE (decl) == NULL_TREE
-  && TYPE_SIZE (TREE_TYPE (decl)) != NULL_TREE)
+  && COMPLETE_TYPE_P (TREE_TYPE (decl)))
 layout_decl (decl, 0);
 
   /* A few consistency checks.  */
@@ -1889,7 +1889,7 @@ gfc_get_symbol_decl (gfc_symbol * sym)
   length = fold_convert (gfc_charlen_type_node, length);
   gfc_finish_var_decl (length, sym);
   if (!sym->attr.associate_var
- && TREE_CODE (length) == VAR_DECL
+ && VAR_P (length)
  && sym->value && sym->value->expr_type != EXPR_NULL
  && sym->value->ts.u.cl->length)
{
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index d902e8f3281..292aba76aaa 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -10246,7 +10246,7 @@ gfc_trans_pointer_assignment (gfc_expr * expr1, 
gfc_expr * expr2)
  gfc_conv_descriptor_data_set (&block, desc, data);
 
  /* Copy the span.  */
- if (TREE_CODE (rse.expr) == VAR_DECL
+ if (VAR_P (rse.expr)
  && GFC_DECL_PTR_ARRAY_P (rse.expr))
span = gfc_conv_descriptor_span_get (rse.expr);
  else
@@ -10933,7 +10933,7 @@ gfc_trans_arrayfunc_assign (gfc_expr * expr1, gfc_expr 
* expr2)
 {
   tmp = sym->backend_decl;
   lhs = sym->backend_decl;
-  if (TREE_CODE (tmp) == INDIRECT_REF)
+  if (INDIRECT_REF_P (tmp))
tmp = TREE_OPERAND (tmp, 0);
   sym->backend_decl = gfc_create_var (TREE_TYPE (tmp), "lhs");
   gfc_add_modify (&se.pre, sym->backend_decl, tmp);
@@ -11883,7 +11883,7 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * 
expr2, bool init_flag,
   if (expr2->ts.type == BT_CHARACTER && !expr1->ts.deferred
   && !(VAR_P (rse.string_length

[PATCH 03/14] gcc/config/*: use _P() defines from tree.h

2023-05-13 Thread Bernhard Reutner-Fischer via Gcc-patches
From: Bernhard Reutner-Fischer 

gcc/ChangeLog:

* config/aarch64/aarch64.cc (aarch64_short_vector_p): Use _P
defines from tree.h.
(aarch64_mangle_type): Ditto.
* config/alpha/alpha.cc (alpha_in_small_data_p): Ditto.
(alpha_gimplify_va_arg_1): Ditto.
* config/arc/arc.cc (arc_encode_section_info): Ditto.
(arc_is_aux_reg_p): Ditto.
(arc_is_uncached_mem_p): Ditto.
(arc_handle_aux_attribute): Ditto.
* config/arm/arm.cc (arm_handle_isr_attribute): Ditto.
(arm_handle_cmse_nonsecure_call): Ditto.
(arm_set_default_type_attributes): Ditto.
(arm_is_segment_info_known): Ditto.
(arm_mangle_type): Ditto.
* config/arm/unknown-elf.h (IN_NAMED_SECTION_P): Ditto.
* config/avr/avr.cc (avr_lookup_function_attribute1): Ditto.
(avr_decl_absdata_p): Ditto.
(avr_insert_attributes): Ditto.
(avr_section_type_flags): Ditto.
(avr_encode_section_info): Ditto.
* config/bfin/bfin.cc (bfin_handle_l2_attribute): Ditto.
* config/bpf/bpf.cc (bpf_core_compute): Ditto.
* config/c6x/c6x.cc (c6x_in_small_data_p): Ditto.
* config/csky/csky.cc (csky_handle_isr_attribute): Ditto.
(csky_mangle_type): Ditto.
* config/darwin-c.cc (darwin_pragma_unused): Ditto.
* config/darwin.cc (is_objc_metadata): Ditto.
* config/epiphany/epiphany.cc (epiphany_function_ok_for_sibcall): Ditto.
* config/epiphany/epiphany.h (ROUND_TYPE_ALIGN): Ditto.
* config/frv/frv.cc (frv_emit_movsi): Ditto.
* config/gcn/gcn-tree.cc (gcn_lockless_update): Ditto.
* config/gcn/gcn.cc (gcn_asm_output_symbol_ref): Ditto.
* config/h8300/h8300.cc (h8300_encode_section_info): Ditto.
* config/i386/i386-expand.cc: Ditto.
* config/i386/i386.cc (type_natural_mode): Ditto.
(ix86_function_arg): Ditto.
(ix86_data_alignment): Ditto.
(ix86_local_alignment): Ditto.
(ix86_simd_clone_compute_vecsize_and_simdlen): Ditto.
* config/i386/winnt-cxx.cc (i386_pe_type_dllimport_p): Ditto.
(i386_pe_type_dllexport_p): Ditto.
(i386_pe_adjust_class_at_definition): Ditto.
* config/i386/winnt.cc (i386_pe_determine_dllimport_p): Ditto.
(i386_pe_binds_local_p): Ditto.
(i386_pe_section_type_flags): Ditto.
* config/ia64/ia64.cc (ia64_encode_section_info): Ditto.
(ia64_gimplify_va_arg): Ditto.
(ia64_in_small_data_p): Ditto.
* config/iq2000/iq2000.cc (iq2000_function_arg): Ditto.
* config/lm32/lm32.cc (lm32_in_small_data_p): Ditto.
* config/loongarch/loongarch.cc (loongarch_handle_model_attribute): 
Ditto.
* config/m32c/m32c.cc (m32c_insert_attributes): Ditto.
* config/mcore/mcore.cc (mcore_mark_dllimport): Ditto.
(mcore_encode_section_info): Ditto.
* config/microblaze/microblaze.cc (microblaze_elf_in_small_data_p): 
Ditto.
* config/mips/mips.cc (mips_output_aligned_decl_common): Ditto.
* config/mmix/mmix.cc (mmix_encode_section_info): Ditto.
* config/nvptx/nvptx.cc (nvptx_encode_section_info): Ditto.
(pass_in_memory): Ditto.
(nvptx_generate_vector_shuffle): Ditto.
(nvptx_lockless_update): Ditto.
* config/pa/pa.cc (pa_function_arg_padding): Ditto.
(pa_function_value): Ditto.
(pa_function_arg): Ditto.
* config/pa/pa.h (IN_NAMED_SECTION_P): Ditto.
(TEXT_SPACE_P): Ditto.
* config/pa/som.h (MAKE_DECL_ONE_ONLY): Ditto.
* config/pdp11/pdp11.cc (pdp11_return_in_memory): Ditto.
* config/riscv/riscv.cc (riscv_in_small_data_p): Ditto.
(riscv_mangle_type): Ditto.
* config/rl78/rl78.cc (rl78_insert_attributes): Ditto.
(rl78_addsi3_internal): Ditto.
* config/rs6000/aix.h (ROUND_TYPE_ALIGN): Ditto.
* config/rs6000/darwin.h (ROUND_TYPE_ALIGN): Ditto.
* config/rs6000/freebsd64.h (ROUND_TYPE_ALIGN): Ditto.
* config/rs6000/linux64.h (ROUND_TYPE_ALIGN): Ditto.
* config/rs6000/rs6000-call.cc (rs6000_function_arg_boundary): Ditto.
(rs6000_function_arg_advance_1): Ditto.
(rs6000_function_arg): Ditto.
(rs6000_pass_by_reference): Ditto.
* config/rs6000/rs6000-logue.cc (rs6000_function_ok_for_sibcall): Ditto.
* config/rs6000/rs6000.cc (rs6000_data_alignment): Ditto.
(rs6000_set_default_type_attributes): Ditto.
(rs6000_elf_in_small_data_p): Ditto.
(IN_NAMED_SECTION): Ditto.
(rs6000_xcoff_encode_section_info): Ditto.
(rs6000_function_value): Ditto.
(invalid_arg_for_unprototyped_fn): Ditto.
* config/s390/s390-c.cc (s390_fn_types_compatible): Ditto.
(s390_vec_n_elem): Ditto.
* config/s390/s390.cc (s390_check_type_for_vector_abi): Ditto.
(s390_function_arg_integer): Ditto.
(s390_return_in_memory): Ditto.
(s390_e

[PATCH 04/14] c++: use _P() defines from tree.h

2023-05-13 Thread Bernhard Reutner-Fischer via Gcc-patches
From: Bernhard Reutner-Fischer 

gcc/cp/ChangeLog:

* call.cc (promoted_arithmetic_type_p): Use _P defines from tree.h.
(build_conditional_expr): Ditto.
(convert_like_internal): Ditto.
(convert_arg_to_ellipsis): Ditto.
(build_over_call): Ditto.
(compare_ics): Ditto.
* class.cc (is_empty_base_ref): Ditto.
* coroutines.cc (rewrite_param_uses): Ditto.
* cp-tree.h (DECL_DISCRIMINATOR_P): Ditto.
(ARITHMETIC_TYPE_P): Ditto.
* cvt.cc (ocp_convert): Ditto.
* cxx-pretty-print.cc (pp_cxx_template_argument_list): Ditto.
* decl.cc (layout_var_decl): Ditto.
(get_tuple_size): Ditto.
* error.cc (dump_simple_decl): Ditto.
* lambda.cc (start_lambda_scope): Ditto.
* mangle.cc (write_template_arg): Ditto.
* method.cc (spaceship_comp_cat): Ditto.
* module.cc (node_template_info): Ditto.
(trees_out::start): Ditto.
(trees_out::decl_node): Ditto.
(trees_in::read_var_def): Ditto.
(set_instantiating_module): Ditto.
* name-lookup.cc (maybe_record_mergeable_decl): Ditto.
(consider_decl): Ditto.
(maybe_add_fuzzy_decl): Ditto.
* pt.cc (convert_nontype_argument): Ditto.
* semantics.cc (handle_omp_array_sections_1): Ditto.
(finish_omp_clauses): Ditto.
(finish_omp_target_clauses_r): Ditto.
(is_this_parameter): Ditto.
* tree.cc (build_cplus_array_type): Ditto.
(is_this_expression): Ditto.
* typeck.cc (do_warn_enum_conversions): Ditto.
* typeck2.cc (store_init_value): Ditto.
(check_narrowing): Ditto.
---
 gcc/cp/call.cc | 42 +++---
 gcc/cp/class.cc|  2 +-
 gcc/cp/coroutines.cc   |  2 +-
 gcc/cp/cp-tree.h   |  4 ++--
 gcc/cp/cvt.cc  |  2 +-
 gcc/cp/cxx-pretty-print.cc |  2 +-
 gcc/cp/decl.cc |  4 ++--
 gcc/cp/error.cc|  2 +-
 gcc/cp/lambda.cc   |  2 +-
 gcc/cp/mangle.cc   |  2 +-
 gcc/cp/method.cc   |  2 +-
 gcc/cp/module.cc   | 12 +--
 gcc/cp/name-lookup.cc  |  6 +++---
 gcc/cp/pt.cc   |  2 +-
 gcc/cp/semantics.cc| 24 +++---
 gcc/cp/tree.cc |  4 ++--
 gcc/cp/typeck.cc   |  4 ++--
 gcc/cp/typeck2.cc  | 10 -
 18 files changed, 64 insertions(+), 64 deletions(-)

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 2a06520c0c1..6e13d17f6b8 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -2746,7 +2746,7 @@ promoted_arithmetic_type_p (tree type)
  integral types plus floating types.  */
   return ((CP_INTEGRAL_TYPE_P (type)
   && same_type_p (type_promotes_to (type), type))
- || TREE_CODE (type) == REAL_TYPE);
+ || SCALAR_FLOAT_TYPE_P (type));
 }
 
 /* Create any builtin operator overload candidates for the operator in
@@ -5759,10 +5759,10 @@ build_conditional_expr (const op_location_t &loc,
   if ((TREE_CODE (arg2) == EXCESS_PRECISION_EXPR
|| TREE_CODE (arg3) == EXCESS_PRECISION_EXPR)
   && (TREE_CODE (arg2_type) == INTEGER_TYPE
- || TREE_CODE (arg2_type) == REAL_TYPE
+ || SCALAR_FLOAT_TYPE_P (arg2_type)
  || TREE_CODE (arg2_type) == COMPLEX_TYPE)
   && (TREE_CODE (arg3_type) == INTEGER_TYPE
- || TREE_CODE (arg3_type) == REAL_TYPE
+ || SCALAR_FLOAT_TYPE_P (arg3_type)
  || TREE_CODE (arg3_type) == COMPLEX_TYPE))
 {
   semantic_result_type
@@ -5775,8 +5775,8 @@ build_conditional_expr (const op_location_t &loc,
t1 = TREE_TYPE (t1);
  if (TREE_CODE (t2) == COMPLEX_TYPE)
t2 = TREE_TYPE (t2);
- gcc_checking_assert (TREE_CODE (t1) == REAL_TYPE
-  && TREE_CODE (t2) == REAL_TYPE
+ gcc_checking_assert (SCALAR_FLOAT_TYPE_P (t1)
+  && SCALAR_FLOAT_TYPE_P (t2)
   && (extended_float_type_p (t1)
   || extended_float_type_p (t2))
   && cp_compare_floating_point_conversion_ranks
@@ -6127,8 +6127,8 @@ build_conditional_expr (const op_location_t &loc,
t1 = TREE_TYPE (t1);
  if (TREE_CODE (t2) == COMPLEX_TYPE)
t2 = TREE_TYPE (t2);
- gcc_checking_assert (TREE_CODE (t1) == REAL_TYPE
-  && TREE_CODE (t2) == REAL_TYPE
+ gcc_checking_assert (SCALAR_FLOAT_TYPE_P (t1)
+  && SCALAR_FLOAT_TYPE_P (t2)
   && (extended_float_type_p (t1)
   || extended_float_type_p (t2))
   && cp_compare_floating_point_conversion_ranks
@@ -6147,8 +6147,8 @@ build_conditional_expr (const op_location_t &loc,
t1 = TREE_TYPE (t1);
  if (TREE_CODE (t2) == COMPLEX_TYPE)
t2 = TREE_TYPE (t2);
- 

[PATCH 01/14] ada: use _P() defines from tree.h

2023-05-13 Thread Bernhard Reutner-Fischer via Gcc-patches
From: Bernhard Reutner-Fischer 

gcc/ada/ChangeLog:

* gcc-interface/decl.cc (gnat_to_gnu_entity): Use _P defines
from tree.h.
(constructor_address_p): Ditto.
(elaborate_expression_1): Ditto.
* gcc-interface/trans.cc (Identifier_to_gnu): Ditto.
(is_nrv_p): Ditto.
(Subprogram_Body_to_gnu): Ditto.
(gnat_to_gnu): Ditto.
(gnat_to_gnu_external): Ditto.
(add_decl_expr): Ditto.
(gnat_gimplify_expr): Ditto.
* gcc-interface/utils.cc (finish_record_type): Ditto.
(create_var_decl): Ditto.
* gcc-interface/utils2.cc (get_base_type): Ditto.
(build_binary_op): Ditto.
(build_unary_op): Ditto.
(gnat_protect_expr): Ditto.
(gnat_invariant_expr): Ditto.
---
 gcc/ada/gcc-interface/decl.cc   | 17 -
 gcc/ada/gcc-interface/trans.cc  | 20 ++--
 gcc/ada/gcc-interface/utils.cc  | 10 +-
 gcc/ada/gcc-interface/utils2.cc | 16 
 4 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index 20f43de9ea9..ec61593a65b 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -785,7 +785,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, 
bool definition)
if ((TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE
 && No (gnat_renamed_obj))
|| TYPE_IS_DUMMY_P (gnu_type)
-   || TREE_CODE (gnu_type) == VOID_TYPE)
+   || VOID_TYPE_P (gnu_type))
  {
gcc_assert (type_annotate_only);
if (this_global)
@@ -840,7 +840,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, 
bool definition)
if (TREE_CODE (gnu_expr) == COMPONENT_REF
&& TYPE_IS_PADDING_P
   (TREE_TYPE (TREE_OPERAND (gnu_expr, 0)))
-   && TREE_CODE (TREE_OPERAND (gnu_expr, 0)) == VAR_DECL
+   && VAR_P (TREE_OPERAND (gnu_expr, 0))
&& (TREE_READONLY (TREE_OPERAND (gnu_expr, 0))
|| DECL_READONLY_ONCE_ELAB
   (TREE_OPERAND (gnu_expr, 0
@@ -1077,7 +1077,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, 
bool definition)
/* We need to detect the case where a temporary is created to
   hold the return value, since we cannot safely rename it at
   top level as it lives only in the elaboration routine.  */
-   || (TREE_CODE (inner) == VAR_DECL
+   || (VAR_P (inner)
&& DECL_RETURN_VALUE_P (inner))
/* We also need to detect the case where the front-end creates
   a dangling 'reference to a function call at top level and
@@ -1093,10 +1093,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree 
gnu_expr, bool definition)
 
   We cannot safely rename the rewritten expression since the
   underlying object lives only in the elaboration routine.  */
-   || (TREE_CODE (inner) == INDIRECT_REF
+   || (INDIRECT_REF_P (inner)
&& (inner
= remove_conversions (TREE_OPERAND (inner, 0), true))
-   && TREE_CODE (inner) == VAR_DECL
+   && VAR_P (inner)
&& DECL_RETURN_VALUE_P (inner)))
  ;
 
@@ -1611,7 +1611,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, 
bool definition)
   and optimization isn't enabled, then force it in memory so that
   a register won't be allocated to it with possible subparts left
   uninitialized and reaching the register allocator.  */
-   else if (TREE_CODE (gnu_decl) == VAR_DECL
+   else if (VAR_P (gnu_decl)
 && !DECL_EXTERNAL (gnu_decl)
 && !TREE_STATIC (gnu_decl)
 && DECL_MODE (gnu_decl) != BLKmode
@@ -6717,8 +6717,7 @@ range_cannot_be_superflat (Node_Id gnat_range)
 static bool
 constructor_address_p (tree gnu_expr)
 {
-  while (TREE_CODE (gnu_expr) == NOP_EXPR
-|| TREE_CODE (gnu_expr) == CONVERT_EXPR
+  while (CONVERT_EXPR_P (gnu_expr)
 || TREE_CODE (gnu_expr) == NON_LVALUE_EXPR)
 gnu_expr = TREE_OPERAND (gnu_expr, 0);
 
@@ -7061,7 +7060,7 @@ elaborate_expression_1 (tree gnu_expr, Entity_Id 
gnat_entity, const char *s,
 
   expr_variable_p
= !(inner
-   && TREE_CODE (inner) == VAR_DECL
+   && VAR_P (inner)
&& (TREE_READONLY (inner) || DECL_READONLY_ONCE_ELAB (inner)));
 }
 
diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
index 5fc1a26fede..c26f1b6e1ac 100644
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -1241,7 +1241,7 @@ Identifier_to_gnu (Node_Id gnat_node, tree 
*gnu_result_type_p)
   /* Do the fina

[PATCH 09/14] rust: use _P() defines from tree.h

2023-05-13 Thread Bernhard Reutner-Fischer via Gcc-patches
From: Bernhard Reutner-Fischer 

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::type_cast_expression): Use
_P() defines from tree.h
* backend/rust-tree.cc (build_cplus_array_type): Ditto.
* backend/rust-tree.h (ARITHMETIC_TYPE_P): Ditto.
(gnu_vector_type_p): Ditto.
* checks/lints/rust-lint-unused-var.cc (check_decl): Ditto.
* rust-gcc.cc (Gcc_backend::fill_in_array): Ditto.
(Gcc_backend::named_type): Ditto.
(Gcc_backend::convert_expression): Ditto.
(Gcc_backend::init_statement): Ditto.
---
 gcc/rust/backend/rust-compile-expr.cc | 2 +-
 gcc/rust/backend/rust-tree.cc | 2 +-
 gcc/rust/backend/rust-tree.h  | 4 ++--
 gcc/rust/checks/lints/rust-lint-unused-var.cc | 2 +-
 gcc/rust/rust-gcc.cc  | 8 
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index d7945dbf26b..3dc34828e32 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -2267,7 +2267,7 @@ CompileExpr::type_cast_expression (tree type_to_cast_to, 
tree expr_tree,
   // FIXME check for TREE_OVERFLOW?
   return cast;
 }
-  else if (TREE_CODE (type_to_cast_to) == REAL_TYPE)
+  else if (SCALAR_FLOAT_TYPE_P (type_to_cast_to))
 {
   tree cast = convert_to_real (type_to_cast_to, expr_tree);
   // FIXME
diff --git a/gcc/rust/backend/rust-tree.cc b/gcc/rust/backend/rust-tree.cc
index 8243d4cf5c6..7e11e6584ae 100644
--- a/gcc/rust/backend/rust-tree.cc
+++ b/gcc/rust/backend/rust-tree.cc
@@ -2404,7 +2404,7 @@ build_cplus_array_type (tree elt_type, tree index_type, 
int dependent)
 }
 
   /* Avoid spurious warnings with VLAs (c++/54583).  */
-  if (TYPE_SIZE (t) && EXPR_P (TYPE_SIZE (t)))
+  if (CAN_HAVE_LOCATION_P (TYPE_SIZE (t)))
 suppress_warning (TYPE_SIZE (t), OPT_Wunused);
 
   /* Push these needs up to the ARRAY_TYPE so that initialization takes
diff --git a/gcc/rust/backend/rust-tree.h b/gcc/rust/backend/rust-tree.h
index 284fd873c1c..6d243b7f86e 100644
--- a/gcc/rust/backend/rust-tree.h
+++ b/gcc/rust/backend/rust-tree.h
@@ -54,7 +54,7 @@
 
Keep these checks in ascending code order.  */
 #define ARITHMETIC_TYPE_P(TYPE)
\
-  (RS_INTEGRAL_TYPE_P (TYPE) || TREE_CODE (TYPE) == REAL_TYPE  
\
+  (RS_INTEGRAL_TYPE_P (TYPE) || SCALAR_FLOAT_TYPE_P (TYPE)   \
|| TREE_CODE (TYPE) == COMPLEX_TYPE)
 
 /* True iff TYPE is cv decltype(nullptr).  */
@@ -3250,7 +3250,7 @@ identifier_p (tree t)
 inline bool
 gnu_vector_type_p (const_tree type)
 {
-  return TREE_CODE (type) == VECTOR_TYPE && !TYPE_INDIVISIBLE_P (type);
+  return VECTOR_TYPE_P (type) && !TYPE_INDIVISIBLE_P (type);
 }
 
 extern vec *
diff --git a/gcc/rust/checks/lints/rust-lint-unused-var.cc 
b/gcc/rust/checks/lints/rust-lint-unused-var.cc
index ba5ffb9372b..2cf5cd60f15 100644
--- a/gcc/rust/checks/lints/rust-lint-unused-var.cc
+++ b/gcc/rust/checks/lints/rust-lint-unused-var.cc
@@ -25,7 +25,7 @@ namespace Analysis {
 static void
 check_decl (tree *t)
 {
-  rust_assert (TREE_CODE (*t) == VAR_DECL || TREE_CODE (*t) == PARM_DECL
+  rust_assert (VAR_P (*t) || TREE_CODE (*t) == PARM_DECL
   || TREE_CODE (*t) == CONST_DECL);
 
   tree var_name = DECL_NAME (*t);
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index cf20b5b98e0..b1995bdb56a 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -886,7 +886,7 @@ Gcc_backend::fill_in_array (tree fill, tree element_type, 
tree length_tree)
   if (element_type == error_mark_node || length_tree == error_mark_node)
 return error_mark_node;
 
-  gcc_assert (TYPE_SIZE (element_type) != NULL_TREE);
+  gcc_assert (COMPLETE_TYPE_P (element_type));
 
   length_tree = fold_convert (sizetype, length_tree);
 
@@ -923,7 +923,7 @@ Gcc_backend::named_type (const std::string &name, tree 
type, Location location)
   // give it whatever Rust name we have at this point.
   if (TYPE_NAME (type) == NULL_TREE
   && location.gcc_location () == BUILTINS_LOCATION
-  && (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == REAL_TYPE
+  && (TREE_CODE (type) == INTEGER_TYPE || SCALAR_FLOAT_TYPE_P (type)
  || TREE_CODE (type) == COMPLEX_TYPE
  || TREE_CODE (type) == BOOLEAN_TYPE))
 {
@@ -1173,7 +1173,7 @@ Gcc_backend::convert_expression (tree type_tree, tree 
expr_tree,
 }
   else if (TREE_CODE (type_tree) == INTEGER_TYPE)
 ret = convert_to_integer (type_tree, expr_tree);
-  else if (TREE_CODE (type_tree) == REAL_TYPE)
+  else if (SCALAR_FLOAT_TYPE_P (type_tree))
 ret = convert_to_real (type_tree, expr_tree);
   else if (TREE_CODE (type_tree) == COMPLEX_TYPE)
 ret = convert_to_complex (type_tree, expr_tree);
@@ -1935,7 +1935,7 @@ Gcc_backend::init_statement (tree, Bvariable *var, tree 
init_tree)
   

[PATCH 00/14] use _P() defines from tree.h

2023-05-13 Thread Bernhard Reutner-Fischer via Gcc-patches
From: Bernhard Reutner-Fischer 

Dear maintainers

I propose the following mechanical change to use the defines in tree.h.
(Common convention is to use the defines as per tree.h, which is what we
keep telling people.)

Exceptions applied to the generator here:
 NULL_TREE # we want to retain "NULL"
 CAN_HAVE_RANGE_P # keep CAN_HAVE_LOCATION_P; Looks confused otherwise.
 No fallback declarations considered. I.e. picks TREE_CODE_CLASS true
 branch (to pick the checking variants of tree access) and skips the
 whole true arm when seeing an extension (like DECL_RTL_KNOWN_SET).
 Case enumerations ignored (CASE_FLT_FN CASE_FLT_FN_FLOATN_NX
 CASE_BUILT_IN_TM_STORE).
 Only _P() named macros without loops are considered for starters.

Bootstrapped on x86_64-unknown-linux with
 --enable-languages=c,fortran,c++,ada,d,go,lto,jit,objc,obj-c++,rust
 (hence not m2) --enable-checking=yes --enable-multilib --disable-libstdcxx-pch
 and regtested without regressions against r14-619-g2499540e9abb55 on
 --target_board=unix'{-m32,-m64}'

Ok for trunk?
PS: I refrain from Ccing about all frontend maintainers in the hopes to
apply this squashed.

Bernhard Reutner-Fischer (14):
  ada: use _P() defines from tree.h
  analyzer: use _P() defines from tree.h
  gcc/config/*: use _P() defines from tree.h
  c++: use _P() defines from tree.h
  m2: use _P() defines from tree.h
  lto: use _P() defines from tree.h
  d: use _P() defines from tree.h
  fortran: use _P() defines from tree.h
  rust: use _P() defines from tree.h
  c: use _P() defines from tree.h
  objc: use _P() defines from tree.h
  go: use _P() defines from tree.h
  omp: use _P() defines from tree.h
  gcc: use _P() defines from tree.h

 gcc/ada/gcc-interface/decl.cc | 17 +++---
 gcc/ada/gcc-interface/trans.cc| 20 +++
 gcc/ada/gcc-interface/utils.cc| 10 ++--
 gcc/ada/gcc-interface/utils2.cc   | 16 +++---
 gcc/alias.cc  |  2 +-
 gcc/analyzer/region-model-manager.cc  |  8 +--
 gcc/analyzer/region-model.cc  |  2 +-
 gcc/analyzer/region.cc|  2 +-
 gcc/attribs.cc| 11 ++--
 gcc/builtins.cc   |  8 +--
 gcc/c-family/c-ada-spec.cc|  6 +--
 gcc/c-family/c-common.cc  | 32 ++--
 gcc/c-family/c-common.h   |  2 +-
 gcc/c-family/c-omp.cc |  5 +-
 gcc/c-family/c-ubsan.cc   |  2 +-
 gcc/c-family/c-warn.cc|  6 +--
 gcc/c/c-convert.cc|  4 +-
 gcc/c/c-decl.cc   |  6 +--
 gcc/c/c-parser.cc |  4 +-
 gcc/c/c-typeck.cc | 52 +--
 gcc/c/gimple-parser.cc|  2 +-
 gcc/cfgexpand.cc  |  2 +-
 gcc/cgraph.h  |  4 +-
 gcc/config/aarch64/aarch64.cc |  4 +-
 gcc/config/alpha/alpha.cc |  6 +--
 gcc/config/arc/arc.cc |  8 +--
 gcc/config/arm/arm.cc | 16 +++---
 gcc/config/arm/unknown-elf.h  |  2 +-
 gcc/config/avr/avr.cc | 11 ++--
 gcc/config/bfin/bfin.cc   |  2 +-
 gcc/config/bpf/bpf.cc |  2 +-
 gcc/config/c6x/c6x.cc |  4 +-
 gcc/config/csky/csky.cc   |  8 ++-
 gcc/config/darwin-c.cc|  2 +-
 gcc/config/darwin.cc  |  2 +-
 gcc/config/epiphany/epiphany.cc   |  3 +-
 gcc/config/epiphany/epiphany.h|  6 +--
 gcc/config/frv/frv.cc |  4 +-
 gcc/config/gcn/gcn-tree.cc|  2 +-
 gcc/config/gcn/gcn.cc |  4 +-
 gcc/config/h8300/h8300.cc |  2 +-
 gcc/config/i386/i386-expand.cc|  2 +-
 gcc/config/i386/i386.cc   | 20 +++
 gcc/config/i386/winnt-cxx.cc  | 12 ++---
 gcc/config/i386/winnt.cc  |  6 +--
 gcc/config/ia64/ia64.cc   |  6 +--
 gcc/config/iq2000/iq2000.cc   |  8 ++-
 gcc/config/lm32/lm32.cc   |  2 +-
 gcc/config/loongarch/loongarch.cc |  2 +-
 gcc/config/m32c/m32c.cc   |  2 +-
 gcc/config/mcore/mcore.cc |  6 +--
 gcc/config/microblaze/microblaze.cc   |  2 +-
 gcc/config/mips/mips.cc   |  2 +-
 gcc/config/mmix/mmix.cc   |  4 +-
 gcc/config/nvptx/nvptx.cc |  8 +--
 gcc/config/pa/pa.cc   | 10 ++--
 gcc/config/pa/pa.h|  4 +-
 gcc/config/pa/som.h   |  2 +-
 gcc/config/pdp11/pdp11.cc 

[PATCH 14/14] gcc: use _P() defines from tree.h

2023-05-13 Thread Bernhard Reutner-Fischer via Gcc-patches
From: Bernhard Reutner-Fischer 

gcc/ChangeLog:

* alias.cc (ref_all_alias_ptr_type_p): Use _P() defines from tree.h.
* attribs.cc (diag_attr_exclusions): Ditto.
(decl_attributes): Ditto.
(build_type_attribute_qual_variant): Ditto.
* builtins.cc (fold_builtin_carg): Ditto.
(fold_builtin_next_arg): Ditto.
(do_mpc_arg2): Ditto.
* cfgexpand.cc (expand_return): Ditto.
* cgraph.h (decl_in_symtab_p): Ditto.
(symtab_node::get_create): Ditto.
* dwarf2out.cc (base_type_die): Ditto.
(implicit_ptr_descriptor): Ditto.
(gen_array_type_die): Ditto.
(gen_type_die_with_usage): Ditto.
(optimize_location_into_implicit_ptr): Ditto.
* expr.cc (do_store_flag): Ditto.
* fold-const.cc (negate_expr_p): Ditto.
(fold_negate_expr_1): Ditto.
(fold_convert_const): Ditto.
(fold_convert_loc): Ditto.
(constant_boolean_node): Ditto.
(fold_binary_op_with_conditional_arg): Ditto.
(build_fold_addr_expr_with_type_loc): Ditto.
(fold_comparison): Ditto.
(fold_checksum_tree): Ditto.
(tree_unary_nonnegative_warnv_p): Ditto.
(integer_valued_real_unary_p): Ditto.
(fold_read_from_constant_string): Ditto.
* gcc-rich-location.cc 
(maybe_range_label_for_tree_type_mismatch::get_text): Ditto.
* gimple-expr.cc (useless_type_conversion_p): Ditto.
(is_gimple_reg): Ditto.
(is_gimple_asm_val): Ditto.
(mark_addressable): Ditto.
* gimple-expr.h (is_gimple_variable): Ditto.
(virtual_operand_p): Ditto.
* gimple-ssa-warn-access.cc (pass_waccess::check_dangling_stores): 
Ditto.
* gimplify.cc (gimplify_bind_expr): Ditto.
(gimplify_return_expr): Ditto.
(gimple_add_padding_init_for_auto_var): Ditto.
(gimplify_addr_expr): Ditto.
(omp_add_variable): Ditto.
(omp_notice_variable): Ditto.
(omp_get_base_pointer): Ditto.
(omp_strip_components_and_deref): Ditto.
(omp_strip_indirections): Ditto.
(omp_accumulate_sibling_list): Ditto.
(omp_build_struct_sibling_lists): Ditto.
(gimplify_adjust_omp_clauses_1): Ditto.
(gimplify_adjust_omp_clauses): Ditto.
(gimplify_omp_for): Ditto.
(goa_lhs_expr_p): Ditto.
(gimplify_one_sizepos): Ditto.
* graphite-scop-detection.cc 
(scop_detection::graphite_can_represent_scev): Ditto.
* ipa-devirt.cc (odr_types_equivalent_p): Ditto.
* ipa-prop.cc (ipa_set_jf_constant): Ditto.
(propagate_controlled_uses): Ditto.
* ipa-sra.cc (type_prevails_p): Ditto.
(scan_expr_access): Ditto.
* optabs-tree.cc (optab_for_tree_code): Ditto.
* toplev.cc (wrapup_global_declaration_1): Ditto.
* trans-mem.cc (transaction_invariant_address_p): Ditto.
* tree-cfg.cc (verify_types_in_gimple_reference): Ditto.
(verify_gimple_comparison): Ditto.
(verify_gimple_assign_binary): Ditto.
(verify_gimple_assign_single): Ditto.
* tree-complex.cc (get_component_ssa_name): Ditto.
* tree-emutls.cc (lower_emutls_2): Ditto.
* tree-inline.cc (copy_tree_body_r): Ditto.
(estimate_move_cost): Ditto.
(copy_decl_for_dup_finish): Ditto.
* tree-nested.cc (convert_nonlocal_omp_clauses): Ditto.
(note_nonlocal_vla_type): Ditto.
(convert_local_omp_clauses): Ditto.
(remap_vla_decls): Ditto.
(fixup_vla_decls): Ditto.
* tree-parloops.cc (loop_has_vector_phi_nodes): Ditto.
* tree-pretty-print.cc (print_declaration): Ditto.
(print_call_name): Ditto.
* tree-sra.cc (compare_access_positions): Ditto.
* tree-ssa-alias.cc (compare_type_sizes): Ditto.
* tree-ssa-ccp.cc (get_default_value): Ditto.
* tree-ssa-coalesce.cc (populate_coalesce_list_for_outofssa): Ditto.
* tree-ssa-dom.cc (reduce_vector_comparison_to_scalar_comparison): 
Ditto.
* tree-ssa-forwprop.cc (can_propagate_from): Ditto.
* tree-ssa-propagate.cc (may_propagate_copy): Ditto.
* tree-ssa-sccvn.cc (fully_constant_vn_reference_p): Ditto.
* tree-ssa-sink.cc (statement_sink_location): Ditto.
* tree-ssa-structalias.cc (type_must_have_pointers): Ditto.
* tree-ssa-ter.cc (find_replaceable_in_bb): Ditto.
* tree-ssa-uninit.cc (warn_uninit): Ditto.
* tree-ssa.cc (maybe_rewrite_mem_ref_base): Ditto.
(non_rewritable_mem_ref_base): Ditto.
* tree-streamer-in.cc (lto_input_ts_type_non_common_tree_pointers): 
Ditto.
* tree-streamer-out.cc (write_ts_type_non_common_tree_pointers): Ditto.
* tree-vect-generic.cc (do_binop): Ditto.
(do_cond): Ditto.
* tree-vect-stmts.cc (vect_init_vector): Ditto.
* tree-vector-builder.h (tree_vector_builder::note_representative): 
Ditto.
* tree.cc (sign_mask

[PATCH 06/14] lto: use _P() defines from tree.h

2023-05-13 Thread Bernhard Reutner-Fischer via Gcc-patches
From: Bernhard Reutner-Fischer 

gcc/ChangeLog:

* lto-streamer-in.cc (lto_input_var_decl_ref): Use _P defines from
tree.h.
(lto_read_body_or_constructor): Ditto.
* lto-streamer-out.cc (tree_is_indexable): Ditto.
(lto_output_var_decl_ref): Ditto.
(DFS::DFS_write_tree_body): Ditto.
(wrap_refs): Ditto.
(write_symbol_extension_info): Ditto.

gcc/lto/ChangeLog:

* lto-common.cc (lto_maybe_register_decl):
* lto-symtab.cc (warn_type_compatibility_p):
(lto_symtab_resolve_replaceable_p):
(lto_symtab_merge_decls_1):
* lto-symtab.h (lto_symtab_prevailing_decl):
---
 gcc/lto-streamer-in.cc  |  4 ++--
 gcc/lto-streamer-out.cc | 11 +--
 gcc/lto/lto-common.cc   |  2 +-
 gcc/lto/lto-symtab.cc   |  8 
 gcc/lto/lto-symtab.h|  2 +-
 5 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/gcc/lto-streamer-in.cc b/gcc/lto-streamer-in.cc
index 03cb41cfa16..2cb83406db5 100644
--- a/gcc/lto-streamer-in.cc
+++ b/gcc/lto-streamer-in.cc
@@ -671,7 +671,7 @@ lto_input_var_decl_ref (lto_input_block *ib, 
lto_file_decl_data *file_data)
   unsigned int ix_u = streamer_read_uhwi (ib);
   tree result = (*file_data->current_decl_state
 ->streams[LTO_DECL_STREAM])[ix_u];
-  gcc_assert (TREE_CODE (result) == VAR_DECL);
+  gcc_assert (VAR_P (result));
   return result;
 }
 
@@ -1653,7 +1653,7 @@ lto_read_body_or_constructor (struct lto_file_decl_data 
*file_data, struct symta
 
  if (TYPE_P (t))
{
- gcc_assert (TYPE_CANONICAL (t) == NULL_TREE);
+ gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
  if (type_with_alias_set_p (t)
  && canonical_type_used_p (t))
TYPE_CANONICAL (t) = TYPE_MAIN_VARIANT (t);
diff --git a/gcc/lto-streamer-out.cc b/gcc/lto-streamer-out.cc
index 0bca530313c..5ab2eb4301e 100644
--- a/gcc/lto-streamer-out.cc
+++ b/gcc/lto-streamer-out.cc
@@ -178,7 +178,7 @@ tree_is_indexable (tree t)
   && lto_variably_modified_type_p (DECL_CONTEXT (t)))
 return false;
   else
-return (TYPE_P (t) || DECL_P (t) || TREE_CODE (t) == SSA_NAME);
+return (IS_TYPE_OR_DECL_P (t) || TREE_CODE (t) == SSA_NAME);
 }
 
 
@@ -346,7 +346,7 @@ void
 lto_output_var_decl_ref (struct lto_out_decl_state *decl_state,
 struct lto_output_stream * obs, tree decl)
 {
-  gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
+  gcc_checking_assert (VAR_P (decl));
   streamer_write_uhwi_stream
  (obs, lto_get_index (&decl_state->streams[LTO_DECL_STREAM],
  decl));
@@ -1078,8 +1078,7 @@ DFS::DFS_write_tree_body (struct output_block *ob,
   else if (RECORD_OR_UNION_TYPE_P (expr))
for (tree t = TYPE_FIELDS (expr); t; t = TREE_CHAIN (t))
  DFS_follow_tree_edge (t);
-  else if (TREE_CODE (expr) == FUNCTION_TYPE
-  || TREE_CODE (expr) == METHOD_TYPE)
+  else if (FUNC_OR_METHOD_TYPE_P (expr))
DFS_follow_tree_edge (TYPE_ARG_TYPES (expr));
 
   if (!POINTER_TYPE_P (expr))
@@ -2626,7 +2625,7 @@ wrap_refs (tree *tp, int *ws, void *)
 {
   tree t = *tp;
   if (handled_component_p (t)
-  && TREE_CODE (TREE_OPERAND (t, 0)) == VAR_DECL
+  && VAR_P (TREE_OPERAND (t, 0))
   && TREE_PUBLIC (TREE_OPERAND (t, 0)))
 {
   tree decl = TREE_OPERAND (t, 0);
@@ -3064,7 +3063,7 @@ write_symbol_extension_info (tree t)
? GCCST_VARIABLE : GCCST_FUNCTION);
   lto_write_data (&c, 1);
   unsigned char section_kind = 0;
-  if (TREE_CODE (t) == VAR_DECL)
+  if (VAR_P (t))
 {
   section *s = get_variable_section (t, false);
   if (s->common.flags & SECTION_BSS)
diff --git a/gcc/lto/lto-common.cc b/gcc/lto/lto-common.cc
index 882dd8971a4..537570204b3 100644
--- a/gcc/lto/lto-common.cc
+++ b/gcc/lto/lto-common.cc
@@ -958,7 +958,7 @@ lto_register_function_decl_in_symtab (class data_in 
*data_in, tree decl,
 static void
 lto_maybe_register_decl (class data_in *data_in, tree t, unsigned ix)
 {
-  if (TREE_CODE (t) == VAR_DECL)
+  if (VAR_P (t))
 lto_register_var_decl_in_symtab (data_in, t, ix);
   else if (TREE_CODE (t) == FUNCTION_DECL
   && !fndecl_built_in_p (t))
diff --git a/gcc/lto/lto-symtab.cc b/gcc/lto/lto-symtab.cc
index 2b57d0d5371..79ba8ddde20 100644
--- a/gcc/lto/lto-symtab.cc
+++ b/gcc/lto/lto-symtab.cc
@@ -214,7 +214,7 @@ warn_type_compatibility_p (tree prevailing_type, tree type,
 
   /* Function types needs special care, because types_compatible_p never
  thinks prototype is compatible to non-prototype.  */
-  if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
+  if (FUNC_OR_METHOD_TYPE_P (type))
 {
   if (TREE_CODE (type) != TREE_CODE (prevailing_type))
lev |= 1;
@@ -401,7 +401,7 @@ lto_symtab_resolve_replaceable_p (symtab_node *e)
   || DECL_WEAK (e->decl))
 return true;
 
-  if (TREE_CODE (e->decl) == VAR_DECL)

Re: [PATCH 05/14] m2: use _P() defines from tree.h

2023-05-13 Thread Gaius Mulley via Gcc-patches
Bernhard Reutner-Fischer via Gcc-patches 
writes:

> From: Bernhard Reutner-Fischer 
>
> gcc/m2/ChangeLog:
>
>   * gm2-gcc/m2builtins.cc (doradix): Use _P defines from tree.h.
>   (doplaces): Ditto.
>   (doexponentmin): Ditto.
>   (doexponentmax): Ditto.
>   (dolarge): Ditto.
>   (dosmall): Ditto.
>   (dogUnderflow): Ditto.
>   * gm2-gcc/m2convert.cc (unsafe_conversion_p): Ditto.
>   * gm2-gcc/m2expr.cc (m2expr_build_unary_op_check): Ditto.
>   (m2expr_build_binary_op_check): Ditto.
>   * gm2-gcc/m2tree.cc (m2tree_is_var): Ditto.
>   * gm2-gcc/m2treelib.cc (build_modify_expr): Ditto.
>   * gm2-gcc/m2type.cc (gm2_finish_decl): Ditto.
>   * m2pp.cc (hextree): Ditto.
>   (m2pp_call_expr): Ditto.

Hi Bernhard,

from the m2 perspective - all looks good to me - thanks for the patch,

regards,
Gaius


Re: [PATCH 05/14] m2: use _P() defines from tree.h

2023-05-13 Thread Gaius Mulley via Gcc-patches
Bernhard Reutner-Fischer via Gcc-patches 
writes:

> From: Bernhard Reutner-Fischer 
>
> gcc/m2/ChangeLog:
>
>   * gm2-gcc/m2builtins.cc (doradix): Use _P defines from tree.h.
>   (doplaces): Ditto.
>   (doexponentmin): Ditto.
>   (doexponentmax): Ditto.
>   (dolarge): Ditto.
>   (dosmall): Ditto.
>   (dogUnderflow): Ditto.
>   * gm2-gcc/m2convert.cc (unsafe_conversion_p): Ditto.
>   * gm2-gcc/m2expr.cc (m2expr_build_unary_op_check): Ditto.
>   (m2expr_build_binary_op_check): Ditto.
>   * gm2-gcc/m2tree.cc (m2tree_is_var): Ditto.
>   * gm2-gcc/m2treelib.cc (build_modify_expr): Ditto.
>   * gm2-gcc/m2type.cc (gm2_finish_decl): Ditto.
>   * m2pp.cc (hextree): Ditto.
>   (m2pp_call_expr): Ditto.
> ---
>  gcc/m2/gm2-gcc/m2builtins.cc | 14 +++---
>  gcc/m2/gm2-gcc/m2convert.cc  |  8 
>  gcc/m2/gm2-gcc/m2expr.cc |  4 ++--
>  gcc/m2/gm2-gcc/m2tree.cc |  2 +-
>  gcc/m2/gm2-gcc/m2treelib.cc  |  2 +-
>  gcc/m2/gm2-gcc/m2type.cc |  4 ++--
>  gcc/m2/m2pp.cc   |  4 ++--
>  7 files changed, 19 insertions(+), 19 deletions(-)

Hi Bernhard,

from the m2 perspective - lgtm - thanks for the patch!

regards,
Gaius


[PATCH] MATCH: Add pattern for `signbit(x) ? x : -x` into abs (and swapped)

2023-05-13 Thread Andrew Pinski via Gcc-patches
This adds a simple pattern to match.pd for `signbit(x) ? x : -x`
into abs. This can be done for all types even ones that honor
signed zeros and NaNs because both signbit and - are considered
only looking at/touching the sign bit of those types and does
not trap either.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

PR tree-optimization/109829

gcc/ChangeLog:

* match.pd: Add pattern for `signbit(x) !=/== 0 ? x : -x`.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/abs-3.c: New test.
* gcc.dg/tree-ssa/abs-4.c: New test.
---
 gcc/match.pd  | 10 ++
 gcc/testsuite/gcc.dg/tree-ssa/abs-3.c | 13 +
 gcc/testsuite/gcc.dg/tree-ssa/abs-4.c | 13 +
 3 files changed, 36 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/abs-3.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/abs-4.c

diff --git a/gcc/match.pd b/gcc/match.pd
index 26395880047..b025fb8facf 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -7439,6 +7439,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& TREE_CODE (@0) != INTEGER_CST)
(op @0 (ext @1 @2)
 
+/* signbit(x) != 0 ? -x : x -> abs(x)
+   signbit(x) == 0 ? -x : x -> -abs(x) */
+(for sign (SIGNBIT)
+ (for neeq (ne eq)
+  (simplify
+   (cond (neeq (sign @0) integer_zerop) (negate @0) @0)
+(if (neeq == NE_EXPR)
+ (abs @0)
+ (negate (abs @0))
+
 (simplify
  /* signbit(x) -> 0 if x is nonnegative.  */
  (SIGNBIT tree_expr_nonnegative_p@0)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/abs-3.c 
b/gcc/testsuite/gcc.dg/tree-ssa/abs-3.c
new file mode 100644
index 000..d2638e8f4c5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/abs-3.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+/* PR tree-optimization/109829 */
+
+float abs_f(float x) { return __builtin_signbit(x) ? -x : x; }
+double abs_d(double x) { return __builtin_signbit(x) ? -x : x; }
+long double abs_ld(long double x) { return __builtin_signbit(x) ? -x : x; }
+
+
+/* __builtin_signbit(x) ? -x : x. Should be convert into ABS_EXP */
+/* { dg-final { scan-tree-dump-not "signbit" "optimized"} } */
+/* { dg-final { scan-tree-dump-not "= -" "optimized"} } */
+/* { dg-final { scan-tree-dump-times "= ABS_EXPR" 3 "optimized"} } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/abs-4.c 
b/gcc/testsuite/gcc.dg/tree-ssa/abs-4.c
new file mode 100644
index 000..6197519faf7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/abs-4.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+/* PR tree-optimization/109829 */
+
+float abs_f(float x) { return __builtin_signbit(x) ? x : -x; }
+double abs_d(double x) { return __builtin_signbit(x) ? x : -x; }
+long double abs_ld(long double x) { return __builtin_signbit(x) ? x : -x; }
+
+
+/* __builtin_signbit(x) ? x : -x. Should be convert into - ABS_EXP */
+/* { dg-final { scan-tree-dump-not "signbit" "optimized"} } */
+/* { dg-final { scan-tree-dump-times "= ABS_EXPR" 3 "optimized"} } */
+/* { dg-final { scan-tree-dump-times "= -" 3 "optimized"} } */
-- 
2.31.1