From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x92f.google.com (mail-ua1-x92f.google.com [IPv6:2607:f8b0:4864:20::92f]) by sourceware.org (Postfix) with ESMTPS id 662CB3858D33; Mon, 18 Jan 2021 09:13:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 662CB3858D33 Received: by mail-ua1-x92f.google.com with SMTP id p2so5290027uac.3; Mon, 18 Jan 2021 01:13:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=Nfo275sd7mW9kIJ69RZhcnl6clei3Z7bQVzlTAiLAzo=; b=jlHSRG/29dik9ZW6zsKv275GIcMgB3zYNhANJsmyOXtgy4/4nRZJ7lA56fe0xJ64b0 /PbGn38dkM51XSMdT65iGFJKdpg5qaCeQgM/csXPd48fjBhgIF1jKAiEZUGkdsT46I4a kaJSk1c8OpaenrQR9oMU+unzQPpxGiNK54/EcYeyfyRyDmLPO0x+ZILpk2DUN8vB+TF/ l5Xd20ny5RpvXHyrkqIxEOxUF/84grVqhukPuhmfO9/Q79AbQ1GypN9W/+vz0XbA5ovD +5Bmv02xmYZwrjZhBHKKptkBokWT0RX5ib0DCKVOOj2hbzNF7efno0jENCX8NJiAY7SS S1Zg== X-Gm-Message-State: AOAM533r89PQEPIdiMQOtiqg+kQPLJJ+vrPc6uiC4zvQ79DwxkGQ98Na qkIGs+ri4agLuuCvUw/Lh/GUf3xQsoTHydKs/vjrxM+1mkYakw== X-Google-Smtp-Source: ABdhPJytXUENy1TGnQKEaWiE4gyyPnRVUbogVug3iryV5RJbT/D8a3nL3S1QHtw1MbtoGMtoZoVYi+MbQjgyAIUS1+g= X-Received: by 2002:a9f:3713:: with SMTP id z19mr16006742uad.77.1610961235755; Mon, 18 Jan 2021 01:13:55 -0800 (PST) MIME-Version: 1.0 From: Hongtao Liu Date: Mon, 18 Jan 2021 17:16:42 +0800 Message-ID: Subject: [PATCH] [PR rtl/optimization/98694] Fix incorrect optimization by cprop_hardreg. To: GCC Patches , ebotcazou@libertysurf.fr, steven@gcc.gnu.org Cc: Jakub Jelinek , Richard Biener , "H. J. Lu" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Jan 2021 09:13:57 -0000 Hi: If SRC had been assigned a mode narrower than the copy, we can't link DEST into the chain even they have same hard_regno_nregs(i.e. HImode/SImode in i386 backend). i.e kmovw %k0, %edi vmovd %edi, %xmm2 vpshuflw $0, %xmm2, %xmm0 kmovw %k0, %r8d kmovd %k0, %r9d ... - movl %r9d, %r11d + vmovd %xmm2, %r11d Bootstrap and regtested on x86_64-linux-gnu{-m32,}. Ok for trunk? gcc/ChangeLog: PR rtl-optimization/98694 * regcprop.c (copy_value): If SRC had been assigned a mode narrower than the copy, we can't link DEST into the chain even they have same hard_regno_nregs(i.e. HImode/SImode in i386 backend). gcc/testsuite/ChangeLog: PR rtl-optimization/98694 * gcc.target/i386/pr98694.c: New test. --- gcc/regcprop.c | 3 +- gcc/testsuite/gcc.target/i386/pr98694.c | 38 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr98694.c diff --git a/gcc/regcprop.c b/gcc/regcprop.c index dd62cb36013..997516eca07 100644 --- a/gcc/regcprop.c +++ b/gcc/regcprop.c @@ -355,7 +355,8 @@ copy_value (rtx dest, rtx src, struct value_data *vd) /* 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)) + else if (sn > hard_regno_nregs (sr, vd->e[sr].mode) + || partial_subreg_p (vd->e[sr].mode, GET_MODE (src))) return; /* Link DR at the end of the value chain used by SR. */ diff --git a/gcc/testsuite/gcc.target/i386/pr98694.c b/gcc/testsuite/gcc.target/i386/pr98694.c new file mode 100644 index 00000000000..611f9e77627 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr98694.c @@ -0,0 +1,38 @@ +/* PR rtl-optimization/98694 */ +/* { dg-do run { target { ! ia32 } } } */ +/* { dg-options "-O2 -mavx512bw" } */ +/* { dg-require-effective-target avx512bw } */ + +#include +typedef short v4hi __attribute__ ((vector_size (8))); +typedef int v2si __attribute__ ((vector_size (8))); +v4hi b; + +__attribute__ ((noipa)) +v2si +foo (__m512i src1, __m512i src2) +{ + __mmask64 m = _mm512_cmpeq_epu8_mask (src1, src2); + short s = (short) m; + int i = (int)m; + b = __extension__ (v4hi) {s, s, s, s}; + return __extension__ (v2si) {i, i}; +} + +int main () +{ + __m512i src1 = _mm512_setzero_si512 (); + __m512i src2 = _mm512_set_epi8 (0, 1, 0, 1, 0, 1, 0, 1, + 0, 1, 0, 1, 0, 1, 0, 1, + 0, 1, 0, 1, 0, 1, 0, 1, + 0, 1, 0, 1, 0, 1, 0, 1, + 0, 1, 0, 1, 0, 1, 0, 1, + 0, 1, 0, 1, 0, 1, 0, 1, + 0, 1, 0, 1, 0, 1, 0, 1, + 0, 1, 0, 1, 0, 1, 0, 1); + __mmask64 m = _mm512_cmpeq_epu8_mask (src1, src2); + v2si a = foo (src1, src2); + if (a[0] != (int)m) + __builtin_abort (); + return 0; +} -- -- BR, Hongtao