]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
amdgcn: Implement vector ABS_EXPR for integers (PR104116)
authorAndrew Stubbs <ams@baylibre.com>
Fri, 24 Oct 2025 10:41:40 +0000 (10:41 +0000)
committerAndrew Stubbs <ams@baylibre.com>
Mon, 27 Oct 2025 16:06:46 +0000 (16:06 +0000)
There's not a single vector instruction for integer absolute, but this
enables the optimization in PR104116, and is probably useful otherwise.

The pr104116-*.c testcases should now pass on amdgcn.

gcc/ChangeLog:

PR tree-optimization/104116
* config/gcn/gcn-valu.md (abs<mode>2): New define_expand for
integer vector modes.

gcc/config/gcn/gcn-valu.md

index a34d2e30c971d8651a56882cc08ddb445c58a09f..96c183d67b6ad64c58ec7037d6a277f2257853be 100644 (file)
   }
   [(set_attr "type" "mult")])
 
+(define_expand "abs<mode>2"
+  [(set (match_operand:V_INT 0 "register_operand")
+        (abs:V_INT (match_operand:V_INT 1 "register_operand")))]
+  ""
+  {
+    rtx vcc = gen_reg_rtx (DImode);
+    rtx zero = gcn_vec_constant (<MODE>mode, 0);
+    emit_insn (gen_vec_cmp<mode>di (vcc, gen_rtx_LT (VOIDmode, 0, 0),
+                                   operands[1], zero));
+    emit_insn (gen_sub<mode>3_exec (operands[0], zero, operands[1],
+                                   operands[1], vcc));
+    DONE;
+  })
+
 ;; }}}
 ;; {{{ FP binops - special cases