]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Support simplifying x/(-1) to neg for vector.
authorYanzhang Wang <yanzhang.wang@intel.com>
Wed, 20 Sep 2023 03:36:20 +0000 (11:36 +0800)
committerPan Li <pan2.li@intel.com>
Wed, 20 Sep 2023 13:50:11 +0000 (21:50 +0800)
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>
gcc/simplify-rtx.cc
gcc/testsuite/gcc.target/riscv/rvv/base/simplify-vdiv.c [new file with mode: 0644]

index eb1ac12083206280fef2a7f373fdb701cb12f02c..170406aa28b359de6735f9e89bf4b99827f2b026 100644 (file)
@@ -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 (file)
index 0000000..0830006
--- /dev/null
@@ -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 } } */