public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111306] New: macro-fusion makes error on conjugate complex multiplication
@ 2023-09-06 12:18 joony.wie at samsung dot com
  2023-09-08  2:18 ` [Bug target/111306] [12,13] macro-fusion makes error on conjugate complex multiplication fp16 pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: joony.wie at samsung dot com @ 2023-09-06 12:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111306

            Bug ID: 111306
           Summary: macro-fusion makes error on conjugate complex
                    multiplication
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: joony.wie at samsung dot com
  Target Milestone: ---

It seems that the operands src1 and src2 of "_mm512_fcmul_pch" are swapped for
macro-fusion with optimize option.

If the operands are swapped, the imag value of result will have incorrect sign
bit.

So, the operands should not be swapped in these conjugate complex
multiplication intrinsics.

Let me show the example and the output.

output: 
3.000000 -4.000000 // w/o optimize.
3.000000 4.000000 // w/ optimize.

https://godbolt.org/z/df9Gz18hc // but may not executable
```
#include <immintrin.h>
#include <cstdio>

__attribute__((optimize("O0")))
auto func0(_Float16 *a, _Float16 *b, int n, _Float16 *c) {
  __m512h rA = _mm512_loadu_ph(a);
  for (int i = 0; i < n; i += 32) {
    __m512h rB = _mm512_loadu_ph(b + i);
    _mm512_storeu_ph(c + i, _mm512_fcmul_pch(rB, rA));
  }
}

__attribute__((optimize("O")))
auto func1(_Float16 *a, _Float16 *b, int n, _Float16 *c) {
  __m512h rA = _mm512_loadu_ph(a);
  for (int i = 0; i < n; i += 32) {
    __m512h rB = _mm512_loadu_ph(b + i);
    _mm512_storeu_ph(c + i, _mm512_fcmul_pch(rB, rA));
  }
}

int main() {
  int n = 32;

  _Float16 a[n], b[n], c[n];
  for (int i = 1; i <= n; i++) {
    a[i - 1] = i & 1 ? -i : i;
    b[i - 1] = i;
  }

  func0(a, b, n, c);
    for (int i = 0; i < n / 32 * 2; i++) {
      printf("%f ", (float)c[i]);
    }
    printf("\n");

  func1(a, b, n, c);
    for (int i = 0; i < n / 32 * 2; i++) {
      printf("%f ", (float)c[i]);
    }
    printf("\n");

  return 0;
}
```

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/111306] [12,13] macro-fusion makes error on conjugate complex multiplication fp16
  2023-09-06 12:18 [Bug c++/111306] New: macro-fusion makes error on conjugate complex multiplication joony.wie at samsung dot com
@ 2023-09-08  2:18 ` pinskia at gcc dot gnu.org
  2023-09-08  2:19 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-08  2:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111306

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |crazylht at gmail dot com

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 111333 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/111306] [12,13] macro-fusion makes error on conjugate complex multiplication fp16
  2023-09-06 12:18 [Bug c++/111306] New: macro-fusion makes error on conjugate complex multiplication joony.wie at samsung dot com
  2023-09-08  2:18 ` [Bug target/111306] [12,13] macro-fusion makes error on conjugate complex multiplication fp16 pinskia at gcc dot gnu.org
@ 2023-09-08  2:19 ` pinskia at gcc dot gnu.org
  2023-09-08  3:24 ` crazylht at gmail dot com
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-08  2:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111306

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-09-08
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/111306] [12,13] macro-fusion makes error on conjugate complex multiplication fp16
  2023-09-06 12:18 [Bug c++/111306] New: macro-fusion makes error on conjugate complex multiplication joony.wie at samsung dot com
  2023-09-08  2:18 ` [Bug target/111306] [12,13] macro-fusion makes error on conjugate complex multiplication fp16 pinskia at gcc dot gnu.org
  2023-09-08  2:19 ` pinskia at gcc dot gnu.org
@ 2023-09-08  3:24 ` crazylht at gmail dot com
  2023-09-08  6:02 ` crazylht at gmail dot com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: crazylht at gmail dot com @ 2023-09-08  3:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111306

--- Comment #3 from Hongtao.liu <crazylht at gmail dot com> ---
A patch is posted at
https://gcc.gnu.org/pipermail/gcc-patches/2023-September/629650.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/111306] [12,13] macro-fusion makes error on conjugate complex multiplication fp16
  2023-09-06 12:18 [Bug c++/111306] New: macro-fusion makes error on conjugate complex multiplication joony.wie at samsung dot com
                   ` (2 preceding siblings ...)
  2023-09-08  3:24 ` crazylht at gmail dot com
@ 2023-09-08  6:02 ` crazylht at gmail dot com
  2023-09-11  1:17 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: crazylht at gmail dot com @ 2023-09-08  6:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111306

--- Comment #4 from Hongtao.liu <crazylht at gmail dot com> ---
A related PR111335 for fmaddcph , similar but not the same, PR111335 is due to
precision difference for complex _Float16 fma, fmaddcph a, b, c is not equal to
fmaddcph b, a, c

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/111306] [12,13] macro-fusion makes error on conjugate complex multiplication fp16
  2023-09-06 12:18 [Bug c++/111306] New: macro-fusion makes error on conjugate complex multiplication joony.wie at samsung dot com
                   ` (3 preceding siblings ...)
  2023-09-08  6:02 ` crazylht at gmail dot com
@ 2023-09-11  1:17 ` cvs-commit at gcc dot gnu.org
  2023-09-11  1:20 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-11  1:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111306

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>:

https://gcc.gnu.org/g:f197392a16ffb1327f1d12ff8ff05f9295e015cb

commit r14-3831-gf197392a16ffb1327f1d12ff8ff05f9295e015cb
Author: liuhongt <hongtao.liu@intel.com>
Date:   Fri Sep 8 09:22:43 2023 +0800

    Remove constraint modifier % for fcmaddcph/fmaddcph/fcmulcph since there're
not commutative.

    gcc/ChangeLog:

            PR target/111306
            PR target/111335
            * config/i386/sse.md (int_comm): New int_attr.
            (fma_<complexopname>_<mode><sdc_maskz_name><round_name>):
            Remove % for Complex conjugate operations since they're not
            commutative.
            (fma_<complexpairopname>_<mode>_pair): Ditto.
            (<avx512>_<complexopname>_<mode>_mask<round_name>): Ditto.
            (cmul<conj_op><mode>3): Ditto.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/pr111306.c: New test.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/111306] [12,13] macro-fusion makes error on conjugate complex multiplication fp16
  2023-09-06 12:18 [Bug c++/111306] New: macro-fusion makes error on conjugate complex multiplication joony.wie at samsung dot com
                   ` (4 preceding siblings ...)
  2023-09-11  1:17 ` cvs-commit at gcc dot gnu.org
@ 2023-09-11  1:20 ` cvs-commit at gcc dot gnu.org
  2023-09-11  1:22 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-11  1:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111306

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by hongtao Liu
<liuhongt@gcc.gnu.org>:

https://gcc.gnu.org/g:162731529e4dd10970880c369471229735dc3e9b

commit r13-7789-g162731529e4dd10970880c369471229735dc3e9b
Author: liuhongt <hongtao.liu@intel.com>
Date:   Fri Sep 8 09:22:43 2023 +0800

    Remove constraint modifier % for fcmaddcph/fmaddcph/fcmulcph since there're
not commutative.

    gcc/ChangeLog:

            PR target/111306
            PR target/111335
            * config/i386/sse.md (int_comm): New int_attr.
            (fma_<complexopname>_<mode><sdc_maskz_name><round_name>):
            Remove % for Complex conjugate operations since they're not
            commutative.
            (fma_<complexpairopname>_<mode>_pair): Ditto.
            (<avx512>_<complexopname>_<mode>_mask<round_name>): Ditto.
            (cmul<conj_op><mode>3): Ditto.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/pr111306.c: New test.

    (cherry picked from commit f197392a16ffb1327f1d12ff8ff05f9295e015cb)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/111306] [12,13] macro-fusion makes error on conjugate complex multiplication fp16
  2023-09-06 12:18 [Bug c++/111306] New: macro-fusion makes error on conjugate complex multiplication joony.wie at samsung dot com
                   ` (5 preceding siblings ...)
  2023-09-11  1:20 ` cvs-commit at gcc dot gnu.org
@ 2023-09-11  1:22 ` cvs-commit at gcc dot gnu.org
  2023-09-11  1:23 ` crazylht at gmail dot com
  2023-09-12 11:09 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-11  1:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111306

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by hongtao Liu
<liuhongt@gcc.gnu.org>:

https://gcc.gnu.org/g:82c1ff396e49b706d5baa11f4c884810f6350e95

commit r12-9852-g82c1ff396e49b706d5baa11f4c884810f6350e95
Author: liuhongt <hongtao.liu@intel.com>
Date:   Fri Sep 8 09:22:43 2023 +0800

    Remove constraint modifier % for fcmaddcph/fmaddcph/fcmulcph since there're
not commutative.

    gcc/ChangeLog:

            PR target/111306
            PR target/111335
            * config/i386/sse.md (int_comm): New int_attr.
            (fma_<complexopname>_<mode><sdc_maskz_name><round_name>):
            Remove % for Complex conjugate operations since they're not
            commutative.
            (fma_<complexpairopname>_<mode>_pair): Ditto.
            (<avx512>_<complexopname>_<mode>_mask<round_name>): Ditto.
            (cmul<conj_op><mode>3): Ditto.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/pr111306.c: New test.

    (cherry picked from commit f197392a16ffb1327f1d12ff8ff05f9295e015cb)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/111306] [12,13] macro-fusion makes error on conjugate complex multiplication fp16
  2023-09-06 12:18 [Bug c++/111306] New: macro-fusion makes error on conjugate complex multiplication joony.wie at samsung dot com
                   ` (6 preceding siblings ...)
  2023-09-11  1:22 ` cvs-commit at gcc dot gnu.org
@ 2023-09-11  1:23 ` crazylht at gmail dot com
  2023-09-12 11:09 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: crazylht at gmail dot com @ 2023-09-11  1:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111306

--- Comment #8 from Hongtao.liu <crazylht at gmail dot com> ---
Fixed in GCC14.1 GCC13.3 GCC12.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/111306] [12,13] macro-fusion makes error on conjugate complex multiplication fp16
  2023-09-06 12:18 [Bug c++/111306] New: macro-fusion makes error on conjugate complex multiplication joony.wie at samsung dot com
                   ` (7 preceding siblings ...)
  2023-09-11  1:23 ` crazylht at gmail dot com
@ 2023-09-12 11:09 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-09-12 11:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111306

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-09-12 11:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-06 12:18 [Bug c++/111306] New: macro-fusion makes error on conjugate complex multiplication joony.wie at samsung dot com
2023-09-08  2:18 ` [Bug target/111306] [12,13] macro-fusion makes error on conjugate complex multiplication fp16 pinskia at gcc dot gnu.org
2023-09-08  2:19 ` pinskia at gcc dot gnu.org
2023-09-08  3:24 ` crazylht at gmail dot com
2023-09-08  6:02 ` crazylht at gmail dot com
2023-09-11  1:17 ` cvs-commit at gcc dot gnu.org
2023-09-11  1:20 ` cvs-commit at gcc dot gnu.org
2023-09-11  1:22 ` cvs-commit at gcc dot gnu.org
2023-09-11  1:23 ` crazylht at gmail dot com
2023-09-12 11:09 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).