Re: [PATCH v1] RISC-V: Bugfix for RVV overloaded intrinsic ICE in function checker

2024-02-07 Thread juzhe.zh...@rivai.ai
Why is it 2 not 1 or other value ?



juzhe.zh...@rivai.ai
 
From: pan2.li
Date: 2024-02-07 17:27
To: gcc-patches
CC: juzhe.zhong; pan2.li; yanzhang.wang; kito.cheng
Subject: [PATCH v1] RISC-V: Bugfix for RVV overloaded intrinsic ICE in function 
checker
From: Pan Li 
 
There is another corn case when similar as below example:
 
void test (void)
{
  __riscv_vaadd ();
}
 
We report error when overloaded function with empty args.  For example:
 
test.c: In function 'foo':
test.c:8:3: error: no matching function call to '__riscv_vaadd' with empty args
8 |   __riscv_vaadd ();
  |   ^~~~
 
Unfortunately, it will meet another ICE similar to below after above
message.  The underlying build function checker will have zero args
and break some assumption of the function checker.  For example, the
count of args is not less than 2.
 
ice.c: In function ‘foo’:
ice.c:8:3: internal compiler error: in require_immediate, at
config/riscv/riscv-vector-builtins.cc:4252
8 |   __riscv_vaadd ();
  |   ^
0x20b36ac riscv_vector::function_checker::require_immediate(unsigned
int, long, long) const
.../__RISC-V_BUILD__/../gcc/config/riscv/riscv-vector-builtins.cc:4252
0x20b890c riscv_vector::alu_def::check(riscv_vector::function_checker&) const

.../__RISC-V_BUILD__/../gcc/config/riscv/riscv-vector-builtins-shapes.cc:387
0x20b38d7 riscv_vector::function_checker::check()
.../__RISC-V_BUILD__/../gcc/config/riscv/riscv-vector-builtins.cc:4315
0x20b4876 riscv_vector::check_builtin_call(unsigned int, vec,
.../__RISC-V_BUILD__/../gcc/config/riscv/riscv-vector-builtins.cc:4605
0x2069393 riscv_check_builtin_call
.../__RISC-V_BUILD__/../gcc/config/riscv/riscv-c.cc:227
 
Below test are passed for this patch.
 
* The riscv regression tests.
 
PR target/113766
 
gcc/ChangeLog:
 
* config/riscv/riscv-vector-builtins-shapes.cc (struct alu_def): Make
sure the c.arg_num is >= 2 before checking.
(struct build_frm_base): Ditto.
(struct narrow_alu_def): Ditto.
 
gcc/testsuite/ChangeLog:
 
* gcc.target/riscv/rvv/base/pr113766-1.c: Add new cases.
 
Signed-off-by: Pan Li 
---
.../riscv/riscv-vector-builtins-shapes.cc   | 17 +
.../gcc.target/riscv/rvv/base/pr113766-1.c  | 16 
2 files changed, 29 insertions(+), 4 deletions(-)
 
diff --git a/gcc/config/riscv/riscv-vector-builtins-shapes.cc 
b/gcc/config/riscv/riscv-vector-builtins-shapes.cc
index 8e90b17a94b..c5ffcc1f2c4 100644
--- a/gcc/config/riscv/riscv-vector-builtins-shapes.cc
+++ b/gcc/config/riscv/riscv-vector-builtins-shapes.cc
@@ -383,7 +383,10 @@ struct alu_def : public build_base
 /* Check whether rounding mode argument is a valid immediate.  */
 if (c.base->has_rounding_mode_operand_p ())
   {
- if (!c.any_type_float_p ())
+ /* Some invalid overload intrinsic like below will have zero for
+c.arg_num ().  Thus, make sure arg_num is big enough here.
+__riscv_vaadd () will make c.arg_num () == 0.  */
+ if (!c.any_type_float_p () && c.arg_num () >= 2)
  return c.require_immediate (c.arg_num () - 2, VXRM_RNU, VXRM_ROD);
/* TODO: We will support floating-point intrinsic modeling
   rounding mode in the future.  */
@@ -411,8 +414,11 @@ struct build_frm_base : public build_base
   {
 gcc_assert (c.any_type_float_p ());
-/* Check whether rounding mode argument is a valid immediate.  */
-if (c.base->has_rounding_mode_operand_p ())
+/* Check whether rounding mode argument is a valid immediate.
+   Some invalid overload intrinsic like below will have zero for
+   c.arg_num ().  Thus, make sure arg_num is big enough here.
+   __riscv_vaadd () will make c.arg_num () == 0.  */
+if (c.base->has_rounding_mode_operand_p () && c.arg_num () >= 2)
   {
unsigned int frm_num = c.arg_num () - 2;
@@ -679,7 +685,10 @@ struct narrow_alu_def : public build_base
 /* Check whether rounding mode argument is a valid immediate.  */
 if (c.base->has_rounding_mode_operand_p ())
   {
- if (!c.any_type_float_p ())
+ /* Some invalid overload intrinsic like below will have zero for
+c.arg_num ().  Thus, make sure arg_num is big enough here.
+__riscv_vaadd () will make c.arg_num () == 0.  */
+ if (!c.any_type_float_p () && c.arg_num () >= 2)
  return c.require_immediate (c.arg_num () - 2, VXRM_RNU, VXRM_ROD);
/* TODO: We will support floating-point intrinsic modeling
   rounding mode in the future.  */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr113766-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/pr113766-1.c
index bd4943b0b7e..fd674a8895c 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/base/pr113766-1.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr113766-1.c
@@ -82,4 +82,20 @@ test ()
   __riscv_vfredosum (); /* { dg-error {no matching function call to 
'__riscv_vfredosum' with empty args} } */
   __riscv_vfredosum_tu ();  /* { dg-error {no matching function call to 
'__riscv_vfredosum_tu' with empty args} } */

RE: [PATCH v1] RISC-V: Bugfix for RVV overloaded intrinsic ICE in function checker

2024-02-07 Thread Li, Pan2
I think it relates to the location of frm args. For example, we use below to 
get the operand index. And then pass to function_checker.

unsigned int frm_num = c.arg_num () - 2;

Unfortunately, the function checker treat argno as unsigned, thus we need to 
ensure that c.arg_num () is not less than 2
for avoiding overflow.

Pan


From: juzhe.zh...@rivai.ai 
Sent: Wednesday, February 7, 2024 6:21 PM
To: Li, Pan2 ; gcc-patches 
Cc: Li, Pan2 ; Wang, Yanzhang ; 
kito.cheng 
Subject: Re: [PATCH v1] RISC-V: Bugfix for RVV overloaded intrinsic ICE in 
function checker

Why is it 2 not 1 or other value ?


juzhe.zh...@rivai.ai<mailto:juzhe.zh...@rivai.ai>

From: pan2.li<mailto:pan2...@intel.com>
Date: 2024-02-07 17:27
To: gcc-patches<mailto:gcc-patches@gcc.gnu.org>
CC: juzhe.zhong<mailto:juzhe.zh...@rivai.ai>; 
pan2.li<mailto:pan2...@intel.com>; 
yanzhang.wang<mailto:yanzhang.w...@intel.com>; 
kito.cheng<mailto:kito.ch...@gmail.com>
Subject: [PATCH v1] RISC-V: Bugfix for RVV overloaded intrinsic ICE in function 
checker
From: Pan Li mailto:pan2...@intel.com>>

There is another corn case when similar as below example:

void test (void)
{
  __riscv_vaadd ();
}

We report error when overloaded function with empty args.  For example:

test.c: In function 'foo':
test.c:8:3: error: no matching function call to '__riscv_vaadd' with empty args
8 |   __riscv_vaadd ();
  |   ^~~~

Unfortunately, it will meet another ICE similar to below after above
message.  The underlying build function checker will have zero args
and break some assumption of the function checker.  For example, the
count of args is not less than 2.

ice.c: In function 'foo':
ice.c:8:3: internal compiler error: in require_immediate, at
config/riscv/riscv-vector-builtins.cc:4252
8 |   __riscv_vaadd ();
  |   ^
0x20b36ac riscv_vector::function_checker::require_immediate(unsigned
int, long, long) const
.../__RISC-V_BUILD__/../gcc/config/riscv/riscv-vector-builtins.cc:4252
0x20b890c riscv_vector::alu_def::check(riscv_vector::function_checker&) const

.../__RISC-V_BUILD__/../gcc/config/riscv/riscv-vector-builtins-shapes.cc:387
0x20b38d7 riscv_vector::function_checker::check()
.../__RISC-V_BUILD__/../gcc/config/riscv/riscv-vector-builtins.cc:4315
0x20b4876 riscv_vector::check_builtin_call(unsigned int, vec,
.../__RISC-V_BUILD__/../gcc/config/riscv/riscv-vector-builtins.cc:4605
0x2069393 riscv_check_builtin_call
.../__RISC-V_BUILD__/../gcc/config/riscv/riscv-c.cc:227

Below test are passed for this patch.

* The riscv regression tests.

PR target/113766

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins-shapes.cc (struct alu_def): Make
sure the c.arg_num is >= 2 before checking.
(struct build_frm_base): Ditto.
(struct narrow_alu_def): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/pr113766-1.c: Add new cases.

Signed-off-by: Pan Li mailto:pan2...@intel.com>>
---
.../riscv/riscv-vector-builtins-shapes.cc   | 17 +
.../gcc.target/riscv/rvv/base/pr113766-1.c  | 16 
2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/gcc/config/riscv/riscv-vector-builtins-shapes.cc 
b/gcc/config/riscv/riscv-vector-builtins-shapes.cc
index 8e90b17a94b..c5ffcc1f2c4 100644
--- a/gcc/config/riscv/riscv-vector-builtins-shapes.cc
+++ b/gcc/config/riscv/riscv-vector-builtins-shapes.cc
@@ -383,7 +383,10 @@ struct alu_def : public build_base
 /* Check whether rounding mode argument is a valid immediate.  */
 if (c.base->has_rounding_mode_operand_p ())
   {
- if (!c.any_type_float_p ())
+ /* Some invalid overload intrinsic like below will have zero for
+c.arg_num ().  Thus, make sure arg_num is big enough here.
+__riscv_vaadd () will make c.arg_num () == 0.  */
+ if (!c.any_type_float_p () && c.arg_num () >= 2)
  return c.require_immediate (c.arg_num () - 2, VXRM_RNU, VXRM_ROD);
/* TODO: We will support floating-point intrinsic modeling
   rounding mode in the future.  */
@@ -411,8 +414,11 @@ struct build_frm_base : public build_base
   {
 gcc_assert (c.any_type_float_p ());
-/* Check whether rounding mode argument is a valid immediate.  */
-if (c.base->has_rounding_mode_operand_p ())
+/* Check whether rounding mode argument is a valid immediate.
+   Some invalid overload intrinsic like below will have zero for
+   c.arg_num ().  Thus, make sure arg_num is big enough here.
+   __riscv_vaadd () will make c.arg_num () == 0.  */
+if (c.base->has_rounding_mode_operand_p () && c.arg_num () >= 2)
   {
unsigned int frm_num = c.arg_num () - 2;
@@ -679,7 +685,10 @@ struct narrow_alu_def : public build_base
 /* Check whether rounding mode argument is a valid immediate.  */
 if (c.base->has_rounding_mode_operand_p ())
   {
- if (!

RE: RE: [PATCH v1] RISC-V: Bugfix for RVV overloaded intrinsic ICE in function checker

2024-02-07 Thread Li, Pan2
Committed, thanks Juzhe.

Pan

From: juzhe.zh...@rivai.ai 
Sent: Thursday, February 8, 2024 2:43 PM
To: Li, Pan2 ; gcc-patches 
Cc: Wang, Yanzhang ; kito.cheng 
Subject: Re: RE: [PATCH v1] RISC-V: Bugfix for RVV overloaded intrinsic ICE in 
function checker

LGTM


juzhe.zh...@rivai.ai<mailto:juzhe.zh...@rivai.ai>

From: Li, Pan2<mailto:pan2...@intel.com>
Date: 2024-02-08 09:41
To: juzhe.zh...@rivai.ai<mailto:juzhe.zh...@rivai.ai>; 
gcc-patches<mailto:gcc-patches@gcc.gnu.org>
CC: Wang, Yanzhang<mailto:yanzhang.w...@intel.com>; 
kito.cheng<mailto:kito.ch...@gmail.com>
Subject: RE: [PATCH v1] RISC-V: Bugfix for RVV overloaded intrinsic ICE in 
function checker
I think it relates to the location of frm args. For example, we use below to 
get the operand index. And then pass to function_checker.

unsigned int frm_num = c.arg_num () - 2;

Unfortunately, the function checker treat argno as unsigned, thus we need to 
ensure that c.arg_num () is not less than 2
for avoiding overflow.

Pan


From: juzhe.zh...@rivai.ai<mailto:juzhe.zh...@rivai.ai> 
mailto:juzhe.zh...@rivai.ai>>
Sent: Wednesday, February 7, 2024 6:21 PM
To: Li, Pan2 mailto:pan2...@intel.com>>; gcc-patches 
mailto:gcc-patches@gcc.gnu.org>>
Cc: Li, Pan2 mailto:pan2...@intel.com>>; Wang, Yanzhang 
mailto:yanzhang.w...@intel.com>>; kito.cheng 
mailto:kito.ch...@gmail.com>>
Subject: Re: [PATCH v1] RISC-V: Bugfix for RVV overloaded intrinsic ICE in 
function checker

Why is it 2 not 1 or other value ?


juzhe.zh...@rivai.ai<mailto:juzhe.zh...@rivai.ai>

From: pan2.li<mailto:pan2...@intel.com>
Date: 2024-02-07 17:27
To: gcc-patches<mailto:gcc-patches@gcc.gnu.org>
CC: juzhe.zhong<mailto:juzhe.zh...@rivai.ai>; 
pan2.li<mailto:pan2...@intel.com>; 
yanzhang.wang<mailto:yanzhang.w...@intel.com>; 
kito.cheng<mailto:kito.ch...@gmail.com>
Subject: [PATCH v1] RISC-V: Bugfix for RVV overloaded intrinsic ICE in function 
checker
From: Pan Li mailto:pan2...@intel.com>>

There is another corn case when similar as below example:

void test (void)
{
  __riscv_vaadd ();
}

We report error when overloaded function with empty args.  For example:

test.c: In function 'foo':
test.c:8:3: error: no matching function call to '__riscv_vaadd' with empty args
8 |   __riscv_vaadd ();
  |   ^~~~

Unfortunately, it will meet another ICE similar to below after above
message.  The underlying build function checker will have zero args
and break some assumption of the function checker.  For example, the
count of args is not less than 2.

ice.c: In function ‘foo’:
ice.c:8:3: internal compiler error: in require_immediate, at
config/riscv/riscv-vector-builtins.cc:4252
8 |   __riscv_vaadd ();
  |   ^
0x20b36ac riscv_vector::function_checker::require_immediate(unsigned
int, long, long) const
.../__RISC-V_BUILD__/../gcc/config/riscv/riscv-vector-builtins.cc:4252
0x20b890c riscv_vector::alu_def::check(riscv_vector::function_checker&) const

.../__RISC-V_BUILD__/../gcc/config/riscv/riscv-vector-builtins-shapes.cc:387
0x20b38d7 riscv_vector::function_checker::check()
.../__RISC-V_BUILD__/../gcc/config/riscv/riscv-vector-builtins.cc:4315
0x20b4876 riscv_vector::check_builtin_call(unsigned int, vec,
.../__RISC-V_BUILD__/../gcc/config/riscv/riscv-vector-builtins.cc:4605
0x2069393 riscv_check_builtin_call
.../__RISC-V_BUILD__/../gcc/config/riscv/riscv-c.cc:227

Below test are passed for this patch.

* The riscv regression tests.

PR target/113766

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins-shapes.cc (struct alu_def): Make
sure the c.arg_num is >= 2 before checking.
(struct build_frm_base): Ditto.
(struct narrow_alu_def): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/pr113766-1.c: Add new cases.

Signed-off-by: Pan Li mailto:pan2...@intel.com>>
---
.../riscv/riscv-vector-builtins-shapes.cc   | 17 +
.../gcc.target/riscv/rvv/base/pr113766-1.c  | 16 
2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/gcc/config/riscv/riscv-vector-builtins-shapes.cc 
b/gcc/config/riscv/riscv-vector-builtins-shapes.cc
index 8e90b17a94b..c5ffcc1f2c4 100644
--- a/gcc/config/riscv/riscv-vector-builtins-shapes.cc
+++ b/gcc/config/riscv/riscv-vector-builtins-shapes.cc
@@ -383,7 +383,10 @@ struct alu_def : public build_base
 /* Check whether rounding mode argument is a valid immediate.  */
 if (c.base->has_rounding_mode_operand_p ())
   {
- if (!c.any_type_float_p ())
+ /* Some invalid overload intrinsic like below will have zero for
+c.arg_num ().  Thus, make sure arg_num is big enough here.
+__riscv_vaadd () will make c.arg_num () == 0.  */
+ if (!c.any_type_float_p () && c.arg_num () >= 2)
  return c.require