]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Expand vec abs without masking.
authorRobin Dapp <rdapp@ventanamicro.com>
Fri, 9 Aug 2024 13:05:39 +0000 (15:05 +0200)
committerRobin Dapp <rdapp@ventanamicro.com>
Fri, 23 Aug 2024 09:36:04 +0000 (11:36 +0200)
Standard abs synthesis during expand is max (a, -a).  This
expansion has the advantage of avoiding masking and is thus potentially
faster than the a < 0 ? -a : a synthesis.

gcc/ChangeLog:

* config/riscv/autovec.md (abs<mode>2): Expand via max (a, -a).

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/unop/abs-rv32gcv.c: Adjust test
expectation.
* gcc.target/riscv/rvv/autovec/unop/abs-rv64gcv.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/abs-2.c: Ditto.
* gcc.target/riscv/rvv/autovec/cond/cond_unary-1.c: Ditto.
* gcc.target/riscv/rvv/autovec/cond/cond_unary-2.c: Ditto.
* gcc.target/riscv/rvv/autovec/cond/cond_unary-3.c: Ditto.
* gcc.target/riscv/rvv/autovec/cond/cond_unary-4.c: Ditto.
* gcc.target/riscv/rvv/autovec/cond/cond_unary-5.c: Ditto.
* gcc.target/riscv/rvv/autovec/cond/cond_unary-6.c: Ditto.
* gcc.target/riscv/rvv/autovec/cond/cond_unary-7.c: Ditto.
* gcc.target/riscv/rvv/autovec/cond/cond_unary-8.c: Ditto.

12 files changed:
gcc/config/riscv/autovec.md
gcc/testsuite/gcc.target/riscv/rvv/autovec/cond/cond_unary-1.c
gcc/testsuite/gcc.target/riscv/rvv/autovec/cond/cond_unary-2.c
gcc/testsuite/gcc.target/riscv/rvv/autovec/cond/cond_unary-3.c
gcc/testsuite/gcc.target/riscv/rvv/autovec/cond/cond_unary-4.c
gcc/testsuite/gcc.target/riscv/rvv/autovec/cond/cond_unary-5.c
gcc/testsuite/gcc.target/riscv/rvv/autovec/cond/cond_unary-6.c
gcc/testsuite/gcc.target/riscv/rvv/autovec/cond/cond_unary-7.c
gcc/testsuite/gcc.target/riscv/rvv/autovec/cond/cond_unary-8.c
gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/abs-rv32gcv.c
gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/abs-rv64gcv.c
gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/abs-2.c

index decfe2bf8cc800850b1c7f8d0e3fa51b4af2f16e..4decaedbd826c46fa4bbc792a60b3cf8397e5e8e 100644 (file)
 [(set_attr "type" "vialu")])
 
 ;; -------------------------------------------------------------------------------
-;; - [INT] ABS expansion to vmslt and vneg.
+;; - [INT] ABS expansion to vneg and vmax.
 ;; -------------------------------------------------------------------------------
 
-(define_insn_and_split "abs<mode>2"
+(define_expand "abs<mode>2"
   [(set (match_operand:V_VLSI 0 "register_operand")
-     (abs:V_VLSI
-       (match_operand:V_VLSI 1 "register_operand")))]
-  "TARGET_VECTOR && can_create_pseudo_p ()"
-  "#"
-  "&& 1"
-  [(const_int 0)]
+    (smax:V_VLSI
+     (match_dup 0)
+     (neg:V_VLSI
+       (match_operand:V_VLSI 1 "register_operand"))))]
+  "TARGET_VECTOR"
 {
-  rtx zero = gen_const_vec_duplicate (<MODE>mode, GEN_INT (0));
-  machine_mode mask_mode = riscv_vector::get_mask_mode (<MODE>mode);
-  rtx mask = gen_reg_rtx (mask_mode);
-  riscv_vector::expand_vec_cmp (mask, LT, operands[1], zero);
-
-  rtx ops[] = {operands[0], mask, operands[1], operands[1]};
-  riscv_vector::emit_vlmax_insn (code_for_pred (NEG, <MODE>mode),
-                                  riscv_vector::UNARY_OP_TAMU, ops);
   DONE;
-}
-[(set_attr "type" "vector")])
+})
 
 ;; -------------------------------------------------------------------------------
 ;; ---- [FP] Unary operations
index 2233c6eeecb9667012603072e50eb1d5abdc95a2..4866b221ca4a3e00e4cc149370a8fab113e5d711 100644 (file)
 
 TEST_ALL (DEF_LOOP)
 
-/* NOTE: int abs operator is converted to vmslt + vneg.v */
-/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 8 } } */
+/* NOTE: int abs operator is converted to vneg.v + vmax.vv */
+/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+} 8 } } */
+/* { dg-final { scan-assembler-times {\tvmax\.vv\tv[0-9]+,v[0-9]+,v[0-9]+} 4 } } */
+/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 4 } } */
 /* { dg-final { scan-assembler-times {\tvnot\.v\tv[0-9]+,v[0-9]+,v0\.t} 4 } } */
 /* { dg-final { scan-assembler-times {\tvfabs\.v\tv[0-9]+,v[0-9]+,v0\.t} 3 } } */
 /* { dg-final { scan-assembler-times {\tvfneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 3 } } */
index 4886bff67d86cfe4573bcea43b1d564491cbcae1..651df9f864610c6a1a6d07c6d050d5c458266674 100644 (file)
 
 TEST_ALL (DEF_LOOP)
 
-/* NOTE: int abs operator is converted to vmslt + vneg.v */
-/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 8 } } */
+/* NOTE: int abs operator is converted to vneg.v + vmax.vv */
+/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+} 8 } } */
+/* { dg-final { scan-assembler-times {\tvmax\.vv\tv[0-9]+,v[0-9]+,v[0-9]+} 4 } } */
+/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 4 } } */
 /* { dg-final { scan-assembler-times {\tvnot\.v\tv[0-9]+,v[0-9]+,v0\.t} 4 } } */
 /* { dg-final { scan-assembler-times {\tvfabs\.v\tv[0-9]+,v[0-9]+,v0\.t} 3 } } */
 /* { dg-final { scan-assembler-times {\tvfneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 3 } } */
index a75bde9543a0a03ade9ca6df07184fe38a51ccb6..cc5f7883a649bb52d5da57ff07dd3019eb7943fb 100644 (file)
 
 TEST_ALL (DEF_LOOP)
 
-/* NOTE: int abs operator is converted to vmslt + vneg.v */
-/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 8 } } */
+/* NOTE: int abs operator is converted to vneg.v + vmax.vv */
+/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+} 8 } } */
+/* { dg-final { scan-assembler-times {\tvmax\.vv\tv[0-9]+,v[0-9]+,v[0-9]+} 4 } } */
+/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 4 } } */
 /* { dg-final { scan-assembler-times {\tvnot\.v\tv[0-9]+,v[0-9]+,v0\.t} 4 } } */
 /* { dg-final { scan-assembler-times {\tvfabs\.v\tv[0-9]+,v[0-9]+,v0\.t} 3 } } */
 /* { dg-final { scan-assembler-times {\tvfneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 3 } } */
index ef2784bc5d7f5af7e68025196ee50e03fea7564a..b5f83444c5c979093da3f29cb7a01f74ab042514 100644 (file)
 
 TEST_ALL (DEF_LOOP)
 
-/* NOTE: int abs operator is converted to vmslt + vneg.v */
-/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 8 } } */
+/* NOTE: int abs operator is converted to vneg.v + vmax.vv */
+/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+} 8 } } */
+/* { dg-final { scan-assembler-times {\tvmax\.vv\tv[0-9]+,v[0-9]+,v[0-9]+} 4 } } */
+/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 4 } } */
 /* { dg-final { scan-assembler-times {\tvnot\.v\tv[0-9]+,v[0-9]+,v0\.t} 4 } } */
 /* { dg-final { scan-assembler-times {\tvfabs\.v\tv[0-9]+,v[0-9]+,v0\.t} 3 } } */
 /* { dg-final { scan-assembler-times {\tvfneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 3 } } */
index 3d90f7bbd8c14f29f71a86d3a508b05da2e054f8..76089549fbaf508317d579ea62555ac136d74744 100644 (file)
 
 TEST_ALL (DEF_LOOP)
 
-/* NOTE: int abs operator is converted to vmslt + vneg.v */
-/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 12 } } */
+/* NOTE: int abs operator is converted to vneg.v + vmax.vv */
+/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+} 12 } } */
+/* { dg-final { scan-assembler-times {\tvmax\.vv\tv[0-9]+,v[0-9]+,v[0-9]+} 6 } } */
+/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 6 } } */
 /* { dg-final { scan-assembler-times {\tvnot\.v\tv[0-9]+,v[0-9]+,v0\.t} 6 } } */
 /* NOTE: int abs operator cannot combine the vmerge.  */
 /* { dg-final { scan-assembler-times {\tvf?merge\.v[vxi]m\t} 6 } } */
index da9740f536d66d8df26f717078fd89d5c5fbbc01..6dfb57e52c00f7015476d08812945c6141cc8951 100644 (file)
 
 TEST_ALL (DEF_LOOP)
 
-/* NOTE: int abs operator is converted to vmslt + vneg.v */
-/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 12 } } */
+/* NOTE: int abs operator is converted to vneg.v + vmax.vv */
+/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+} 12 } } */
+/* { dg-final { scan-assembler-times {\tvmax\.vv\tv[0-9]+,v[0-9]+,v[0-9]+} 6 } } */
+/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 6 } } */
 /* { dg-final { scan-assembler-times {\tvnot\.v\tv[0-9]+,v[0-9]+,v0\.t} 6 } } */
 /* NOTE: int abs operator cannot combine the vmerge.  */
 /* { dg-final { scan-assembler-times {\tvf?merge\.v[vxi]m\t} 6 } } */
index e0a799460f8797e0976324b5a167d8857ae1a107..ca24a332055645918c3e81fe7bc764f647066393 100644 (file)
 
 TEST_ALL (DEF_LOOP)
 
-/* NOTE: int abs operator is converted to vmslt + vneg.v */
-/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 12 } } */
+/* NOTE: int abs operator is converted to vneg.v + vmax.vv */
+/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+} 12 } } */
+/* { dg-final { scan-assembler-times {\tvmax\.vv\tv[0-9]+,v[0-9]+,v[0-9]+} 6 } } */
+/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 6 } } */
 /* { dg-final { scan-assembler-times {\tvnot\.v\tv[0-9]+,v[0-9]+,v0\.t} 6 } } */
 /* NOTE: int abs operator cannot combine the vmerge.  */
 /* { dg-final { scan-assembler-times {\tvf?merge\.v[vxi]m\t} 6 } } */
index a70a1a32bdce8daaa9e7c7f079c009031a6075f8..7be4b373a2c5091f68c34c145ed6ef9b3e3923f5 100644 (file)
 
 TEST_ALL (DEF_LOOP)
 
-/* NOTE: int abs operator is converted to vmslt + vneg.v */
-/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 12 } } */
+/* NOTE: int abs operator is converted to vneg.v + vmax.vv */
+/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+} 12 } } */
+/* { dg-final { scan-assembler-times {\tvmax\.vv\tv[0-9]+,v[0-9]+,v[0-9]+} 6 } } */
+/* { dg-final { scan-assembler-times {\tvneg\.v\tv[0-9]+,v[0-9]+,v0\.t} 6 } } */
 /* { dg-final { scan-assembler-times {\tvnot\.v\tv[0-9]+,v[0-9]+,v0\.t} 6 } } */
 /* NOTE: int abs operator cannot combine the vmerge.  */
 /* { dg-final { scan-assembler-times {\tvf?merge\.v[vxi]m\t} 6 } } */
index 85751912e3347508575967ae4345ea84febf1c40..3f62d0eafe7a89c22002805dce3fb26a4cccb3be 100644 (file)
@@ -3,7 +3,7 @@
 
 #include "abs-template.h"
 
-/* { dg-final { scan-assembler-times {\tvseti?vli\s+[a-z0-9,]+,ta,mu} 4 } } */
-/* { dg-final { scan-assembler-times {\tvmslt\.vi} 4 } } */
-/* { dg-final { scan-assembler-times {\tvneg.v\sv[0-9]+,v[0-9]+,v0\.t} 4 } } */
+/* { dg-final { scan-assembler-times {\tvseti?vli\s+[a-z0-9,]+,ta,ma} 7 } } */
+/* { dg-final { scan-assembler-times {\tvneg\.v} 4 } } */
+/* { dg-final { scan-assembler-times {\tvmax\.vv\sv[0-9]+,v[0-9]+,v[0-9]+} 4 } } */
 /* { dg-final { scan-assembler-times {\tvfabs.v} 3 } } */
index d1bd43ae9dbefcf0cc2df3c3b64192074eff5679..64302191cdac771f0fe994fceb06573196b56687 100644 (file)
@@ -3,7 +3,7 @@
 
 #include "abs-template.h"
 
-/* { dg-final { scan-assembler-times {\tvseti?vli\s+[a-z0-9,]+,ta,mu} 4 } } */
-/* { dg-final { scan-assembler-times {\tvmslt\.vi} 4 } } */
-/* { dg-final { scan-assembler-times {\tvneg.v\sv[0-9]+,v[0-9]+,v0\.t} 4 } } */
+/* { dg-final { scan-assembler-times {\tvseti?vli\s+[a-z0-9,]+,ta,ma} 7 } } */
+/* { dg-final { scan-assembler-times {\tvneg\.v} 4 } } */
+/* { dg-final { scan-assembler-times {\tvmax\.vv\sv[0-9]+,v[0-9]+,v[0-9]+} 4 } } */
 /* { dg-final { scan-assembler-times {\tvfabs.v} 3 } } */
index 5389a55a97f1a9e5e3b7b586e5301081d217e6d4..510939a0c1546049c2c888d8ec3dcf7ad921517d 100644 (file)
@@ -46,7 +46,7 @@ DEF_OP_V (neg, 256, int64_t, __builtin_abs)
 DEF_OP_V (neg, 512, int64_t, __builtin_abs)
 
 /* { dg-final { scan-assembler-times {vneg\.v} 38 } } */
-/* { dg-final { scan-assembler-times {vmslt\.vi} 38 } } */
+/* { dg-final { scan-assembler-times {vmax\.vv} 38 } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-not "1,1" "optimized" } } */
 /* { dg-final { scan-tree-dump-not "2,2" "optimized" } } */