https://gcc.gnu.org/g:e61df21035e98c92d6d277e00df81d4168ffe8d1
commit r17-6624-ge61df21035e98c92d6d277e00df81d4168ffe8d1 Author: Igor Shevlyakov <[email protected]> Date: Mon Nov 23 15:29:30 2026 -0800 doc: Fix the semantics of cmls and cmls_conj [PR122601] The documentation of the cmls<mode>4 and cmls_conj<mode>4 optabs says they compute op1 * op2 - op3 (resp. op1 * conj (op2) - op3), but the vectorizer's complex_fms_pattern forms IFN_COMPLEX_FMS and IFN_COMPLEX_FMS_CONJ from c - a * b, and the aarch64 (Advanced SIMD, SVE, SVE2) and arm (Neon, MVE) expanders implement exactly that: the product is subtracted from the accumulator. A port written to the documentation miscompiles, e.g. fma180 in gcc.dg/vect/complex/vect-complex-operations-run.c. Fix the documentation to match the implementation. One in-tree port does follow the old documentation: the amdgcn cmls<mode>4 expander in gcn-valu.md computes op1 * op2 - op3 (it starts from fms<mode>4), so the vectorized loops it is used for get the wrong sign. The run test above does not catch this because vect_complex_add_double is only true for arm and aarch64. That is a code bug in the port and will be handled separately. Assisted-by: Claude Opus 5.5 PR other/122601 gcc/ChangeLog: * doc/md.texi (cmls@var{m}4, cmls_conj@var{m}4): Document that the product is subtracted from operand 3. Signed-off-by: Igor Shevlyakov <[email protected]> Diff: --- gcc/doc/md.texi | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi index bcc31a1733bc..b504ae7b6fe9 100644 --- a/gcc/doc/md.texi +++ b/gcc/doc/md.texi @@ -8434,7 +8434,8 @@ This pattern is not allowed to @code{FAIL}. @mdindex cmls@var{m}4 @item @samp{cmls@var{m}4} Perform a vector multiply and subtract that is semantically the same as -a multiply and subtract of complex numbers. +a multiply and subtract of complex numbers, where the product is subtracted +from the accumulator operand 3. @smallexample complex TYPE op0[N]; @@ -8443,7 +8444,7 @@ a multiply and subtract of complex numbers. complex TYPE op3[N]; for (int i = 0; i < N; i += 1) @{ - op0[i] = op1[i] * op2[i] - op3[i]; + op0[i] = op3[i] - op1[i] * op2[i]; @} @end smallexample @@ -8458,7 +8459,8 @@ This pattern is not allowed to @code{FAIL}. @item @samp{cmls_conj@var{m}4} Perform a vector multiply by conjugate and subtract that is semantically the same as a multiply and subtract of complex numbers where the second -multiply arguments is conjugated. +multiply arguments is conjugated and the product is subtracted from the +accumulator operand 3. @smallexample complex TYPE op0[N]; @@ -8467,7 +8469,7 @@ multiply arguments is conjugated. complex TYPE op3[N]; for (int i = 0; i < N; i += 1) @{ - op0[i] = op1[i] * conj (op2[i]) - op3[i]; + op0[i] = op3[i] - op1[i] * conj (op2[i]); @} @end smallexample
