public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "crazylht at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/98694] [11 Regression] GCC produces incorrect code for loops with -O3 for skylake-avx512 and icelake-server
Date: Fri, 15 Jan 2021 16:52:01 +0000	[thread overview]
Message-ID: <bug-98694-4-bHqbnACY5N@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-98694-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #3 from Hongtao.liu <crazylht at gmail dot com> ---
(In reply to Hongtao.liu from comment #1)
> cprop hardreg change
> 
> (insn 457 499 460 33 (set (reg:SI 39 r11 [orig:86 _11 ] [86])
>         (reg:SI 37 r9 [orig:86 _11 ] [86])) "test.c":29:36 75
> {*movsi_internal}
>      (expr_list:REG_DEAD (reg:SI 37 r9 [orig:86 _11 ] [86])
>         (nil)))
> 
> to
> 
> (insn 457 499 460 33 (set (reg:SI 39 r11 [orig:86 _11 ] [86])
>         (reg:SI 22 xmm2 [orig:86 _11 ] [86])) "test.c":29:36 75
> {*movsi_internal}
>      (expr_list:REG_DEAD (reg:SI 22 xmm2 [orig:86 _11 ] [86])
>         (nil)))
> 
> since it thought the lower 32bit of r9 and xmm2 is the same?
> 
> but with xmm2 defined as
> 
> 	kmovw	%k0, %edi	# 69	[c=4 l=4]  *movhi_internal/6
> 	kmovd	%k0, %edx	# 487	[c=4 l=3]  *movsi_internal/16
> 	vmovd	%edi, %xmm2	# 489
> 
> the bit16-32 is clear with kmovw(note k0 is equal to r9 with SImode, it's
> var_6 in source code)
> 
> (insn 69 68 70 12 (set (reg:HI 5 di [orig:96 _52 ] [96])
>         (reg:HI 68 k0 [orig:82 var_6.0_1 ] [82])) "test.c":21:23 76
> {*movhi_internal}
>      (nil))
> 
> (insn 489 75 78 12 (set (reg:SI 22 xmm2 [297])
>         (reg:SI 5 di [orig:96 _52 ] [96])) 75 {*movsi_internal}
>      (nil))

It seems to be be handled here.

cut from copy_value in regcprop.c:
----
  /* If SRC had been assigned a mode narrower than the copy, we can't
     link DEST into the chain, because not all of the pieces of the
     copy came from oldest_regno.  */
  else if (sn > hard_regno_nregs (sr, vd->e[sr].mode))
    return;
----

here we have %edi set as HImode, but use as SImode and be copied to %xmm2, but
the condition failed to check this beacuase both SImode and HImode has nregs as
1, since the upper part could be garbage, it can't link DEST into the chain.

        kmovw   %k0, %edi       # 69    [c=4 l=4]  *movhi_internal/6  <----HI
        kmovd   %k0, %edx       # 487   [c=4 l=3]  *movsi_internal/16 
        vmovd   %edi, %xmm2     # 489   [c=4 l=6]  *movsi_internal/13 <----SI
        sall    $16, %edx       # 73    [c=4 l=3]  *ashlsi3_1/0
        kmovw   %k0, %r8d       # 74    [c=4 l=5]  *zero_extendhisi2/1
        vpshuflw        $0, %xmm2, %xmm0        # 78    [c=4 l=5] 
*vec_dupv4hi/1
        orl     %edx, %r8d      # 75    [c=4 l=3]  *iorsi_1/0
        testw   %di, %di        # 82    [c=4 l=3]  *cmphi_ccno_1/0
        jle     .L52    # 83    [c=12 l=6]  *jcc
        kmovd   %k0, %r9d       # 85    [c=4 l=4]  *movsi_internal/16 <----SI
        testl   %r9d, %r9d      # 88    [c=4 l=3]  *cmpsi_ccno_1/0

  parent reply	other threads:[~2021-01-15 16:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-15  1:42 [Bug tree-optimization/98694] New: " vsevolod.livinskij at frtk dot ru
2021-01-15  8:11 ` [Bug tree-optimization/98694] " crazylht at gmail dot com
2021-01-15  9:43 ` [Bug target/98694] " marxin at gcc dot gnu.org
2021-01-15 10:03 ` [Bug target/98694] [11 Regression] " rguenth at gcc dot gnu.org
2021-01-15 16:52 ` crazylht at gmail dot com [this message]
2021-01-15 16:56 ` crazylht at gmail dot com
2021-01-15 17:22 ` crazylht at gmail dot com
2021-01-15 17:33 ` crazylht at gmail dot com
2021-01-18  9:41 ` crazylht at gmail dot com
2021-01-21  5:30 ` cvs-commit at gcc dot gnu.org
2021-01-21  5:33 ` crazylht at gmail dot com
2021-01-21  9:41 ` [Bug target/98694] " rguenth at gcc dot gnu.org
2021-01-21 11:12 ` crazylht at gmail dot com
2021-05-05 17:48 ` jakub at gcc dot gnu.org
2022-05-10  8:17 ` cvs-commit at gcc dot gnu.org
2022-10-28 23:30 ` pinskia at gcc dot gnu.org

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-98694-4-bHqbnACY5N@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).