From patchwork Fri Jul 14 06:22:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 120258 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp2306052vqm; Thu, 13 Jul 2023 23:23:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlHDayNI80hvdKR+jZVxHkGgWGuwzw/gFVxafK4m+KMpCQAnJBwR8ue3gt45c9Sq0N9mqXNo X-Received: by 2002:aa7:dc11:0:b0:51d:d5f2:121e with SMTP id b17-20020aa7dc11000000b0051dd5f2121emr3280577edu.5.1689315830161; Thu, 13 Jul 2023 23:23:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689315830; cv=none; d=google.com; s=arc-20160816; b=mzF8suy5CB68l/oXjrnww4P3kaKTSZOmzlI0B3jqBVUxbBkBPg9IBnILpXigebTQu9 9TuI/XQoqlmOwr9BNBTd4/U33Uub1UeVrtexkLQs3EaifS098p05jHDBjyyv0qYksI4T 2wp2bDNaHljjy8n07nzES03CTlBywqWr5Llfo1zDfFac7jIhLadJ23u29Qh3JPrWdZ2J 6rdybN3o5FnXuSZLa2s+3dkmxzIQ4rOp6tXqGO1os0TylkoosyEs+TdpInSK6CZLRnNe i56W5p2E5jIKIVUsKKwe3uV8GebEKihX58v+cTag19oyWdkCZIzab7ZT8gdRz/r4hQKk 8lDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:cc:to:subject :message-id:date:mime-version:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=f0V98UmPJBwZU/HzQrhO1R1y5jd2ABo2rMqbQTpshkQ=; fh=hV/c3gch2b5PVsuN46uonbp0HmBGZyAn8XaekC6Vb9E=; b=ASfp4Lkrh9yhiRb8HmaVQCmp3avkQ9WS7f2rfF9J4JwR5aiqdDtUCXJq/6nfJZ39Ga ECHNiuGasyjLK1pHBFnZYFwsV4SL2krBOM0UwJ22CbXNx+xuGT1SFMXJrKM3vjraLjbY oEzj6XV5OBfT+rPX0nnHiTek/A289bgK3f3UXVm4+PRwvsdTMqpSGaVuShc17RL9HAcH s9L7SRE1PIErRFbprHuvXh4F1uehkiJ1HC4vIkZAbv/rc+sBD4gL40eP+D0VCgpZjLxH j2rkr8GntHmxsGhIaZRcwy6pVoNP9e0XDtKqPSilCikvzCYlmBbHvoTT+E0qvWXhbpxg 8pDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=iUP20Reu; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l25-20020a056402029900b0051e0f8b1699si1752311edv.185.2023.07.13.23.23.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 23:23:50 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=iUP20Reu; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 08CF03858418 for ; Fri, 14 Jul 2023 06:23:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 08CF03858418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689315829; bh=f0V98UmPJBwZU/HzQrhO1R1y5jd2ABo2rMqbQTpshkQ=; h=Date:Subject:To:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=iUP20ReuKLKt/fZ6MebM+NUqqV2DvWt+O7J0Ie9qn+2iAEnW0EgBfrxJPcwcCIzMe GJbjcmGuydfl0Q7jjmjuStLre72z7hvy36DoLWBc31xPYsmGCHidOP/7/VNWlKYTKq dMWgkpVe4ytZ2Sjjkqcw0eOvDGersBxLv08b4kGY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by sourceware.org (Postfix) with ESMTPS id DD6ED3858CDB for ; Fri, 14 Jul 2023 06:23:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DD6ED3858CDB Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-51e5da79223so1807249a12.1 for ; Thu, 13 Jul 2023 23:23:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689315783; x=1691907783; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=f0V98UmPJBwZU/HzQrhO1R1y5jd2ABo2rMqbQTpshkQ=; b=cXO8+9Oe8cqB+pQEAIVY08kviqa2wvqiUhPoyCy+7dTE/NlMHw16yn0jYQqHuaGZDs +qwyPrzGCnrU2HOzuEWz4JkIw3SKwLB9jUOAwKpalqKfb5let4zyvtnudXyHxucNeryV Qh9heutLhlwDuHPV8Df+beaHu1R47osPSuNV5bkt7H3kPRiIQOJuwDEaR7FGymTYY0k2 Vb846wE7yTwF9uWI4H1iQp1ciWsIzJVCq7qyo0zvnTS5lycy+NOYOM1hnl5rK5MldJUG wryTHaiJDMfqQusjs90kcPcKd8ytW6suqEkUDe8WAW25JlB6lsuKsn+muhOAGBlGiW9l bDEw== X-Gm-Message-State: ABy/qLZsPz8Nclqc13l7RI0x3JzUhTLQ5U8yqj750nHn3IiD+fox3N7R MTrYUEIajM5cOBItEbwKtbqblSsc8oynKe8EfNNdt4AT9DXWyg== X-Received: by 2002:aa7:c6cb:0:b0:515:1e50:5498 with SMTP id b11-20020aa7c6cb000000b005151e505498mr3272292eds.15.1689315782683; Thu, 13 Jul 2023 23:23:02 -0700 (PDT) MIME-Version: 1.0 Date: Fri, 14 Jul 2023 08:22:51 +0200 Message-ID: Subject: [PATCH] cprop: Do not set REG_EQUAL note when simplifying paradoxical subreg [PR110206] To: "gcc-patches@gcc.gnu.org" Cc: Richard Biener , Richard Sandiford X-Spam-Status: No, score=-8.2 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, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Uros Bizjak via Gcc-patches From: Uros Bizjak Reply-To: Uros Bizjak Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771376035582477569 X-GMAIL-MSGID: 1771376035582477569 cprop1 pass does not consider paradoxical subreg and for (insn 22) claims that it equals 8 elements of HImodeby setting REG_EQUAL note: (insn 21 19 22 4 (set (reg:V4QI 98) (mem/u/c:V4QI (symbol_ref/u:DI ("*.LC1") [flags 0x2]) [0 S4 A32])) "pr110206.c":12:42 1530 {*movv4qi_internal} (expr_list:REG_EQUAL (const_vector:V4QI [ (const_int -52 [0xffffffffffffffcc]) repeated x4 ]) (nil))) (insn 22 21 23 4 (set (reg:V8HI 100) (zero_extend:V8HI (vec_select:V8QI (subreg:V16QI (reg:V4QI 98) 0) (parallel [ (const_int 0 [0]) (const_int 1 [0x1]) (const_int 2 [0x2]) (const_int 3 [0x3]) (const_int 4 [0x4]) (const_int 5 [0x5]) (const_int 6 [0x6]) (const_int 7 [0x7]) ])))) "pr110206.c":12:42 7471 {sse4_1_zero_extendv8qiv8hi2} (expr_list:REG_EQUAL (const_vector:V8HI [ (const_int 204 [0xcc]) repeated x8 ]) (expr_list:REG_DEAD (reg:V4QI 98) (nil)))) We rely on the "undefined" vals to have a specific value (from the earlier REG_EQUAL note) but actual code generation doesn't ensure this (it doesn't need to). That said, the issue isn't the constant folding per-se but that we do not actually constant fold but register an equality that doesn't hold. PR target/110206 gcc/ChangeLog: * fwprop.cc (contains_paradoxical_subreg_p): Move to ... * rtlanal.cc (contains_paradoxical_subreg_p): ... here. * rtlanal.h (contains_paradoxical_subreg_p): Add prototype. * cprop.cc (try_replace_reg): Do not set REG_EQUAL note when the original source contains a paradoxical subreg. gcc/testsuite/ChangeLog: * gcc.dg/torture/pr110206.c: New test. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. OK for mainline and backports? Uros. diff --git a/gcc/cprop.cc b/gcc/cprop.cc index b7400c9a421..cf6facaa8c4 100644 --- a/gcc/cprop.cc +++ b/gcc/cprop.cc @@ -22,6 +22,7 @@ along with GCC; see the file COPYING3. If not see #include "coretypes.h" #include "backend.h" #include "rtl.h" +#include "rtlanal.h" #include "cfghooks.h" #include "df.h" #include "insn-config.h" @@ -795,7 +796,8 @@ try_replace_reg (rtx from, rtx to, rtx_insn *insn) /* If we've failed perform the replacement, have a single SET to a REG destination and don't yet have a note, add a REG_EQUAL note to not lose information. */ - if (!success && note == 0 && set != 0 && REG_P (SET_DEST (set))) + if (!success && note == 0 && set != 0 && REG_P (SET_DEST (set)) + && !contains_paradoxical_subreg_p (SET_SRC (set))) note = set_unique_reg_note (insn, REG_EQUAL, copy_rtx (src)); } diff --git a/gcc/fwprop.cc b/gcc/fwprop.cc index ae342f59407..0707a234726 100644 --- a/gcc/fwprop.cc +++ b/gcc/fwprop.cc @@ -25,6 +25,7 @@ along with GCC; see the file COPYING3. If not see #include "coretypes.h" #include "backend.h" #include "rtl.h" +#include "rtlanal.h" #include "df.h" #include "rtl-ssa.h" @@ -353,21 +354,6 @@ reg_single_def_p (rtx x) return REG_P (x) && crtl->ssa->single_dominating_def (REGNO (x)); } -/* Return true if X contains a paradoxical subreg. */ - -static bool -contains_paradoxical_subreg_p (rtx x) -{ - subrtx_var_iterator::array_type array; - FOR_EACH_SUBRTX_VAR (iter, array, x, NONCONST) - { - x = *iter; - if (SUBREG_P (x) && paradoxical_subreg_p (x)) - return true; - } - return false; -} - /* Try to substitute (set DEST SRC), which defines DEF, into note NOTE of USE_INSN. Return the number of substitutions on success, otherwise return -1 and leave USE_INSN unchanged. diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc index 31707f3b90a..8b48fc243a1 100644 --- a/gcc/rtlanal.cc +++ b/gcc/rtlanal.cc @@ -6970,3 +6970,18 @@ vec_series_lowpart_p (machine_mode result_mode, machine_mode op_mode, rtx sel) } return false; } + +/* Return true if X contains a paradoxical subreg. */ + +bool +contains_paradoxical_subreg_p (rtx x) +{ + subrtx_var_iterator::array_type array; + FOR_EACH_SUBRTX_VAR (iter, array, x, NONCONST) + { + x = *iter; + if (SUBREG_P (x) && paradoxical_subreg_p (x)) + return true; + } + return false; +} diff --git a/gcc/rtlanal.h b/gcc/rtlanal.h index 9013e75c04b..4f0dea8e99f 100644 --- a/gcc/rtlanal.h +++ b/gcc/rtlanal.h @@ -338,4 +338,6 @@ vec_series_highpart_p (machine_mode result_mode, machine_mode op_mode, bool vec_series_lowpart_p (machine_mode result_mode, machine_mode op_mode, rtx sel); +bool +contains_paradoxical_subreg_p (rtx x); #endif diff --git a/gcc/testsuite/gcc.dg/torture/pr110206.c b/gcc/testsuite/gcc.dg/torture/pr110206.c new file mode 100644 index 00000000000..3a4f221ef47 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr110206.c @@ -0,0 +1,30 @@ +/* PR target/110206 */ +/* { dg-do run { target x86_64-*-* i?86-*-* } } */ + +typedef unsigned char __attribute__((__vector_size__ (4))) U; +typedef unsigned char __attribute__((__vector_size__ (8))) V; +typedef unsigned short u16; + +V g; + +void +__attribute__((noinline)) +foo (U u, u16 c, V *r) +{ + if (!c) + __builtin_abort (); + V x = __builtin_shufflevector (u, (204 >> u), 7, 0, 5, 1, 3, 5, 0, 2); + V y = __builtin_shufflevector (g, (V) { }, 7, 6, 6, 7, 2, 6, 3, 5); + V z = __builtin_shufflevector (y, 204 * x, 3, 9, 8, 1, 4, 6, 14, 5); + *r = z; +} + +int +main (void) +{ + V r; + foo ((U){4}, 5, &r); + if (r[6] != 0x30) + __builtin_abort(); + return 0; +}