public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Support simplifying x/(-1) to neg for vector.
@ 2023-09-20  3:36 yanzhang.wang
  2023-09-20 13:38 ` Jeff Law
  0 siblings, 1 reply; 3+ messages in thread
From: yanzhang.wang @ 2023-09-20  3:36 UTC (permalink / raw)
  To: gcc-patches; +Cc: juzhe.zhong, kito.cheng, pan2.li, jeffreyalaw, yanzhang.wang

From: Yanzhang Wang <yanzhang.wang@intel.com>

gcc/ChangeLog:

	* simplify-rtx.cc (simplify_context::simplify_binary_operation_1):
    support simplifying vector int not only scalar int.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/base/simplify-vdiv.c: New test.

Signed-off-by: Yanzhang Wang <yanzhang.wang@intel.com>
---

Currently, the simplify works only for scalar int. I think it should also
work for vector int. So push this patch. 

Have tested with aarch64 and x86, there's no regression introduced.

 gcc/simplify-rtx.cc                            |  4 ++--
 .../gcc.target/riscv/rvv/base/simplify-vdiv.c  | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/simplify-vdiv.c

diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index eb1ac120832..170406aa28b 100644
--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -4093,7 +4093,7 @@ simplify_context::simplify_binary_operation_1 (rtx_code code,
 		}
 	    }
 	}
-      else if (SCALAR_INT_MODE_P (mode))
+      else if (SCALAR_INT_MODE_P (mode) || GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
 	{
 	  /* 0/x is 0 (or x&0 if x has side-effects).  */
 	  if (trueop0 == CONST0_RTX (mode)
@@ -4111,7 +4111,7 @@ simplify_context::simplify_binary_operation_1 (rtx_code code,
 		return tem;
 	    }
 	  /* x/-1 is -x.  */
-	  if (trueop1 == constm1_rtx)
+	  if (trueop1 == CONSTM1_RTX (mode))
 	    {
 	      rtx x = rtl_hooks.gen_lowpart_no_emit (mode, op0);
 	      if (x)
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/simplify-vdiv.c b/gcc/testsuite/gcc.target/riscv/rvv/base/simplify-vdiv.c
new file mode 100644
index 00000000000..08300061832
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/simplify-vdiv.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64 -O3 -Wno-psabi" } */
+
+#include "riscv_vector.h"
+
+#define VDIV_WITH_LMUL(LMUL, DTYPE)                        \
+  vint##DTYPE##m##LMUL##_t                                  \
+  shortcut_for_riscv_vdiv_case_##LMUL##_##DTYPE            \
+  (vint##DTYPE##m##LMUL##_t v1,                             \
+   size_t vl)                                               \
+  {                                                         \
+    return __riscv_vdiv_vx_i##DTYPE##m##LMUL (v1, -1, vl); \
+  }
+
+VDIV_WITH_LMUL (1, 16)
+VDIV_WITH_LMUL (1, 32)
+
+/* { dg-final { scan-assembler-times {vneg\.v} 2 } } */
-- 
2.42.0


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

* Re: [PATCH] RISC-V: Support simplifying x/(-1) to neg for vector.
  2023-09-20  3:36 [PATCH] RISC-V: Support simplifying x/(-1) to neg for vector yanzhang.wang
@ 2023-09-20 13:38 ` Jeff Law
  2023-09-20 13:50   ` Li, Pan2
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff Law @ 2023-09-20 13:38 UTC (permalink / raw)
  To: yanzhang.wang, gcc-patches; +Cc: juzhe.zhong, kito.cheng, pan2.li



On 9/19/23 21:36, yanzhang.wang@intel.com wrote:
> From: Yanzhang Wang <yanzhang.wang@intel.com>
> 
> gcc/ChangeLog:
> 
> 	* simplify-rtx.cc (simplify_context::simplify_binary_operation_1):
>      support simplifying vector int not only scalar int.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.target/riscv/rvv/base/simplify-vdiv.c: New test.
> 
> Signed-off-by: Yanzhang Wang <yanzhang.wang@intel.com>
OK
jeff

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

* RE: [PATCH] RISC-V: Support simplifying x/(-1) to neg for vector.
  2023-09-20 13:38 ` Jeff Law
@ 2023-09-20 13:50   ` Li, Pan2
  0 siblings, 0 replies; 3+ messages in thread
From: Li, Pan2 @ 2023-09-20 13:50 UTC (permalink / raw)
  To: Jeff Law, Wang, Yanzhang, gcc-patches; +Cc: juzhe.zhong, kito.cheng

Committed, thanks Jeff.

Pan

-----Original Message-----
From: Jeff Law <jeffreyalaw@gmail.com> 
Sent: Wednesday, September 20, 2023 9:39 PM
To: Wang, Yanzhang <yanzhang.wang@intel.com>; gcc-patches@gcc.gnu.org
Cc: juzhe.zhong@rivai.ai; kito.cheng@sifive.com; Li, Pan2 <pan2.li@intel.com>
Subject: Re: [PATCH] RISC-V: Support simplifying x/(-1) to neg for vector.



On 9/19/23 21:36, yanzhang.wang@intel.com wrote:
> From: Yanzhang Wang <yanzhang.wang@intel.com>
> 
> gcc/ChangeLog:
> 
> 	* simplify-rtx.cc (simplify_context::simplify_binary_operation_1):
>      support simplifying vector int not only scalar int.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.target/riscv/rvv/base/simplify-vdiv.c: New test.
> 
> Signed-off-by: Yanzhang Wang <yanzhang.wang@intel.com>
OK
jeff

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

end of thread, other threads:[~2023-09-20 13:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-20  3:36 [PATCH] RISC-V: Support simplifying x/(-1) to neg for vector yanzhang.wang
2023-09-20 13:38 ` Jeff Law
2023-09-20 13:50   ` Li, Pan2

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).