]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: Implement V2DI,V4SI division optabs for TARGET_SVE
authorKyrylo Tkachov <kyrylo.tkachov@arm.com>
Tue, 25 Apr 2023 13:50:32 +0000 (14:50 +0100)
committerKyrylo Tkachov <kyrylo.tkachov@arm.com>
Tue, 25 Apr 2023 13:51:09 +0000 (14:51 +0100)
Similar to the mulv2di case, we can use SVE instruction to implement the V4SI and V2DI optabs
for signed and unsigned integer division.
This allows us to generate much cleaner code for the testcase than the current:
food:
        fmov    x1, d1
        fmov    x0, d0
        umov    x2, v0.d[1]
        sdiv    x0, x0, x1
        umov    x1, v1.d[1]
        sdiv    x1, x2, x1
        fmov    d0, x0
        ins     v0.d[1], x1
        ret
which now becomes:
food:
        ptrue   p0.b, all
        sdiv    z0.d, p0/m, z0.d, z1.d
        ret

Bootstrapped and tested on aarch64-none-linux-gnu.

gcc/ChangeLog:

* config/aarch64/aarch64-simd.md (<su_optab>div<mode>3): New define_expand.
* config/aarch64/iterators.md (VQDIV): New mode iterator.
(vnx2di): New mode attribute.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/sve-neon-modes_3.c: New test.

gcc/config/aarch64/aarch64-simd.md
gcc/config/aarch64/iterators.md
gcc/testsuite/gcc.target/aarch64/sve-neon-modes_3.c [new file with mode: 0644]

index cfad812658fb5411f5a7d5073cfadedff1f4884c..5e1b4b186237f904c99398e71fa393f925700e1b 100644 (file)
   [(set_attr "type" "neon_fp_div_<stype><q>")]
 )
 
+;; SVE has vector integer divisions, unlike Advanced SIMD.
+;; We can use it with Advanced SIMD modes to expose the V2DI and V4SI
+;; optabs to the midend.
+(define_expand "<su_optab>div<mode>3"
+  [(set (match_operand:VQDIV 0 "register_operand")
+       (ANY_DIV:VQDIV
+         (match_operand:VQDIV 1 "register_operand")
+         (match_operand:VQDIV 2 "register_operand")))]
+  "TARGET_SVE"
+  {
+    machine_mode sve_mode
+      = aarch64_full_sve_mode (GET_MODE_INNER (<MODE>mode)).require ();
+    rtx sve_op0 = simplify_gen_subreg (sve_mode, operands[0], <MODE>mode, 0);
+    rtx sve_op1 = simplify_gen_subreg (sve_mode, operands[1], <MODE>mode, 0);
+    rtx sve_op2 = simplify_gen_subreg (sve_mode, operands[2], <MODE>mode, 0);
+
+    emit_insn (gen_<su_optab>div<vnx>3 (sve_op0, sve_op1, sve_op2));
+    DONE;
+  }
+)
+
 (define_insn "neg<mode>2"
  [(set (match_operand:VHSDF 0 "register_operand" "=w")
        (neg:VHSDF (match_operand:VHSDF 1 "register_operand" "w")))]
index 1d0b4822102612bed51943ec83fd8da00b078495..861753f677b4dd18ec4f70dce1b72742932af4a1 100644 (file)
 ;; Copy of the above.
 (define_mode_iterator DREG2 [V8QI V4HI V4HF V2SI V2SF DF])
 
+;; Advanced SIMD modes for integer divides.
+(define_mode_iterator VQDIV [V4SI V2DI])
+
 ;; All modes suitable to store/load pair (2 elements) using STP/LDP.
 (define_mode_iterator VP_2E [V2SI V2SF V2DI V2DF])
 
                        (VNx4SI  "v4si") (VNx4SF "v4sf")
                        (VNx2DI  "v2di") (VNx2DF "v2df")])
 
+(define_mode_attr vnx [(V4SI "vnx4si") (V2DI "vnx2di")])
+
 ;; 64-bit container modes the inner or scalar source mode.
 (define_mode_attr VCOND [(HI "V4HI") (SI "V2SI")
                         (V4HI "V4HI") (V8HI "V4HI")
diff --git a/gcc/testsuite/gcc.target/aarch64/sve-neon-modes_3.c b/gcc/testsuite/gcc.target/aarch64/sve-neon-modes_3.c
new file mode 100644 (file)
index 0000000..f1e78a8
--- /dev/null
@@ -0,0 +1,61 @@
+/* { dg-do compile } */
+/* { dg-options "-O -march=armv8.2-a+sve" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+typedef long v2di  __attribute__((vector_size (16)));
+typedef unsigned long v2udi  __attribute__((vector_size (16)));
+typedef int v4si  __attribute__((vector_size (16)));
+typedef unsigned int v4usi  __attribute__((vector_size (16)));
+
+/*
+** food:
+**     ptrue   p0.b, all
+**     sdiv    z0.d, p0/m, z0.d, z1.d
+**     ret
+*/
+
+v2di
+food (v2di a, v2di b)
+{
+  return a / b;
+}
+
+/*
+** fooud:
+**     ptrue   p0.b, all
+**     udiv    z0.d, p0/m, z0.d, z1.d
+**     ret
+*/
+
+v2udi
+fooud (v2udi a, v2udi b)
+{
+  return a / b;
+}
+
+/*
+** foos:
+**     ptrue   p0.b, all
+**     sdiv    z0.s, p0/m, z0.s, z1.s
+**     ret
+*/
+
+v4si
+foos (v4si a, v4si b)
+{
+  return a / b;
+}
+
+/*
+** foous:
+**     ptrue   p0.b, all
+**     udiv    z0.s, p0/m, z0.s, z1.s
+**     ret
+*/
+
+v4usi
+foous (v4usi a, v4usi b)
+{
+  return a / b;
+}
+