]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
amdgcn: Add fold_left_plus vector reductions
authorAndrew Stubbs <ams@codesourcery.com>
Mon, 10 Feb 2020 13:23:29 +0000 (13:23 +0000)
committerAndrew Stubbs <ams@codesourcery.com>
Fri, 3 Jul 2020 10:31:29 +0000 (11:31 +0100)
These aren't real in-order instructions, because the ISA can't do that
quickly, but a means to allow regular out-of-order reductions when that's
good enough, but the middle-end doesn't know so.

gcc/
* config/gcn/gcn-valu.md (fold_left_plus_<mode>): New.

(cherry picked from commit bf628a97efaf11204ab02527b30ca71d7759ca37)

gcc/ChangeLog
gcc/config/gcn/gcn-valu.md

index ad94c5140bbdef3824de1a9005967ed4e9f6ee06..bf1cd4266f635e04901167995f6c364d31b8c1dc 100644 (file)
@@ -1,3 +1,8 @@
+2020-07-03  Andrew Stubbs  <ams@codesourcery.com>
+
+       Backport from mainline:
+       * config/gcn/gcn-valu.md (fold_left_plus_<mode>): New.
+
 2020-06-17  Thomas Schwinge  <thomas@codesourcery.com>
 
        Backported from master:
index 6d7fecaa12c2037acc029df6631b03a4d3c231fa..26559ff765e24bdeefa58e485d30a2fec1fc561e 100644 (file)
     DONE;
   })
 
+;; Warning: This "-ffast-math" implementation converts in-order reductions
+;;          into associative reductions. It's also used where OpenMP or
+;;          OpenACC paralellization has already broken the in-order semantics.
+(define_expand "fold_left_plus_<mode>"
+ [(match_operand:<SCALAR_MODE> 0 "register_operand")
+  (match_operand:<SCALAR_MODE> 1 "gcn_alu_operand")
+  (match_operand:V_FP 2 "gcn_alu_operand")]
+  "can_create_pseudo_p ()
+   && (flag_openacc || flag_openmp
+       || flag_associative_math)"
+  {
+    rtx dest = operands[0];
+    rtx scalar = operands[1];
+    rtx vector = operands[2];
+    rtx tmp = gen_reg_rtx (<SCALAR_MODE>mode);
+
+    emit_insn (gen_reduc_plus_scal_<mode> (tmp, vector));
+    emit_insn (gen_add<scalar_mode>3 (dest, scalar, tmp));
+     DONE;
+   })
 
 (define_insn "*<reduc_op>_dpp_shr_<mode>"
   [(set (match_operand:V_1REG 0 "register_operand"   "=v")