public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "guojie at loongson dot cn" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/111403] LoongArch: Wrong code with -O -mlasx -fopenmp-simd
Date: Sun, 08 Oct 2023 08:45:46 +0000	[thread overview]
Message-ID: <bug-111403-4-tOMoUpnwVr@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-111403-4@http.gcc.gnu.org/bugzilla/>

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

Guo Jie <guojie at loongson dot cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |guojie at loongson dot cn

--- Comment #2 from Guo Jie <guojie at loongson dot cn> ---
It seems that “omp simd reduction” cannot collaborate well with “loop peeling”,
which will result in a probability error in this test case.

LoongArch tree vect pass dump:

  # “omp simd” temporary arrays.
  struct S D.3833[8];
  struct S D.3832[8];
  ...


  # prologue loop.
  <bb 20> [local count: 723433550]:
  MEM <struct S[32]> [(struct S *)&D.3832][0].s = 0;
  _44 = D.3832[0].s;
  _41 = (long unsigned int) i_1;
  _58 = _41 * 4;
  _59 = a_18(D) + _58;
  _60 = _59->s;
  _61 = _44 + _60;
  D.3832[0].s = _61;
  _64 = D.3833[0].s;
  _65 = D.3832[0].s;
  _66 = _64 + _65;
  D.3833[0].s = _66;  # Save temporary reduction results.
  MEM <struct S[32]> [(struct S *)&D.3832][0].s = _66;
  _69 = b_28(D) + _58;
  _70 = MEM <struct S[32]> [(const struct S &)&D.3832][0].s;
  _69->s = _70;
  i_72 = i_1 + 1;
  ivtmp_73 = ivtmp_2 - 1;
  ivtmp_78 = ivtmp_77 + 1;
  if (ivtmp_78 < prolog_loop_niters.42_7)
    goto <bb 21>; [85.71%]
  else
    goto <bb 18>; [14.29%]
 <bb 21> [local count: 620085901]:
  goto <bb 20>; [100.00%]


  # vector body loop.
  <bb 5> [local count: 118111599]:
  # i_48 = PHI <i_30(12), i_79(22)>
  # ivtmp_55 = PHI <ivtmp_45(12), ivtmp_81(22)>
  # vectp_a.50_126 = PHI <vectp_a.50_127(12), vectp_a.51_123(22)>
  # vectp_b.58_158 = PHI <vectp_b.58_159(12), vectp_b.59_155(22)>
  # ivtmp_161 = PHI <ivtmp_162(12), 0(22)>
  MEM <vector(8) int> [(struct S *)&D.3832] = { 0, 0, 0, 0, 0, 0, 0, 0 };
  _16 = (long unsigned int) i_48;
  _17 = _16 * 4;
  _19 = a_18(D) + _17;
  vect__20.52_128 = MEM <vector(8) int> [(int *)vectp_a.50_126];
  _20 = _19->s;
  MEM <vector(8) int> [(int *)&D.3832] = vect__20.52_128;
  vect__24.54_131 = MEM <vector(8) int> [(int *)&D.3833]; # Wrong value.
  ...
  vect__26.56_133 = vect__20.52_128 + vect__24.54_131;
  ...
  if (ivtmp_162 < bnd.44_109)
    goto <bb 12>; [0.00%]
  else
    goto <bb 25>; [100.00%]
  ...

The temporary reduction result of “prologue loop” is only stored in D.3833[0],
and all other elements of D.3833 are 0. Therefore, only the first element of
vect__26.56_133 accumulates the scalar reduction result of “prologue loop”. 

I think the reasonable solution should be to broadcast the scalar reduction
result of “prologue loop” to all elements of D.3833.

  parent reply	other threads:[~2023-10-08  8:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-13 10:46 [Bug target/111403] New: " xry111 at gcc dot gnu.org
2023-09-13 10:48 ` [Bug target/111403] " xry111 at gcc dot gnu.org
2023-10-08  8:45 ` guojie at loongson dot cn [this message]
2024-01-31 10:44 ` xry111 at gcc dot gnu.org
2024-01-31 16:45 ` xry111 at gcc dot gnu.org
2024-01-31 16:48 ` xry111 at gcc dot gnu.org
2024-01-31 17:17 ` schwab@linux-m68k.org
2024-01-31 17:23 ` xry111 at gcc dot gnu.org
2024-02-01  6:17 ` panchenghui at loongson dot cn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-111403-4-tOMoUpnwVr@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).