From patchwork Sun Jul 9 08:52:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 117488 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp4337343vqx; Sun, 9 Jul 2023 01:53:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlGcb9ILIp/ymkUEfR+Y+bS2bhfDqX/fh7heEkRtXMdOUUyHgHTNTBSkbYY8lc2yS4onHszb X-Received: by 2002:a17:906:2210:b0:993:da0b:4d00 with SMTP id s16-20020a170906221000b00993da0b4d00mr5543261ejs.18.1688892819602; Sun, 09 Jul 2023 01:53:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688892819; cv=none; d=google.com; s=arc-20160816; b=IYJO23lkIDKZ5H2J8o7YriyhamK9ZLDFqqE9an5VS79NBGKk9FAHz4qcbhCdMABFWZ 91ePB5dyWuzCcvtIJLInUSoSes7WDTjRf2GSF665tcHyXAPrfsUeYjH69aaqfZYVgYC7 axhjgMoxuCxelYRQwdaFwcyEBJhfYUI9Rlsp0p3aQ/eoJ4TIHfgFj84EYR3LnHTL9fQ7 sjSE1iGfdlzXnAqceKzjTtBcHYcA82MR8kK7RwpockSO8h83gWkloBwUC0Mf9eqN/w7U 4MvCxrEEZZnMcQctL/2l7bERr6tVWJJ2NmPHMycQYkZwpAV/r8dbTolwmghZDeFfxqo+ fXLQ== 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:to:subject :message-id:date:mime-version:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=FU3N+htApP4Pszzj0xPqUjj7d7Ri6sQxCdlre2Q6/pk=; fh=HBK5sYjCSY3abfomIo1OsC2COh3RKQ+LJ7T9VtS2mGI=; b=TfIiALEvd0Rp+z+8/WdxuebmXOxKDeWyiSoC/ncxHdYXLZFSEHSn8ebA1mON7qPiyO gtVaUbch8Kfnj6xhoqszDN7xboVSCgds8K4qdv6x0mgQvDKwOP3sRzvaFtJNU2zd6OGB K+dO7p0frhTRHi6BLznZjaFnOuAKrspEovoU7PVYsBl2KHlLXFKnss1Hv1+UsmIc8+49 0F/9F2GWddbo8q2nMsJ7ZAYiB9+Yn1aPRw4YyazaN1rPR/WluUUpPwgAeVfq9dLZAoYw 4xzUxPfiDQkGX6rctHPw5V1xKaF7bWFuF6oF9I3DTdO0N06+XJ4xzKJWfTHYETalL2pt Y1cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="hDih/qIx"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f5-20020a17090624c500b009893fe84e74si5908863ejb.484.2023.07.09.01.53.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 01:53:39 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="hDih/qIx"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 BBD6B385840C for ; Sun, 9 Jul 2023 08:53:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBD6B385840C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688892817; bh=FU3N+htApP4Pszzj0xPqUjj7d7Ri6sQxCdlre2Q6/pk=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=hDih/qIx3UA06qJMUjyRDPzinI7askZwJWtaIN0Q4jP7zEWNuU9UILaMA+chYP2LZ WGgifoGL9vwvLbrCsspJnpLfmg5pKhB2GgRmmAcCyH98ZJ4KTjT1pZJDmBaVuhLORD R6QKA6pIaHW4+VSUifUoaj5LYsIXrKlR4xdeXnSc= 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 F3F803858CD1 for ; Sun, 9 Jul 2023 08:52:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F3F803858CD1 Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-51e43473ee0so2576054a12.3 for ; Sun, 09 Jul 2023 01:52:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688892770; x=1691484770; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=FU3N+htApP4Pszzj0xPqUjj7d7Ri6sQxCdlre2Q6/pk=; b=cv6qiRnbXcCySP0VaZu5wvsF5xGu4fFHBFZExsFhmMuAGxHDoXFKTRhfQq34HisUU9 vj0Oy498UMURffz/Jjoa9jgniI4U992Vykf2XBA41w1JSdcJlaHhru4EtamP4zHV/yEp tWcXesRuisix44lQNVGy39ASW79h4VJZ0iSJGfpVeC8nPlmBsRzQP4Uc+iX+horNl+Hg fCUnpXtVtSx2QYtkRWWCigLA+QBwii596cTcjMm9urFyWwd4rLSJnDap2cki4a5o6xvr dR82kWoxjC78+A549DFRE5tj2k3ddGu95bCyk2CKcP0MbPadPb9ESQ4kLhhbVWJ3giyo Wymw== X-Gm-Message-State: ABy/qLZaWGS49MVrC+iFiwqcU6EzlOb9hkxG8k4eBKk/oEjF7JTZ34NN 5+1wDwSLpVuGP6N/XzGVpkvkY/XaL0uAqtff/6qG0+m2BuMoldlM X-Received: by 2002:aa7:dd0f:0:b0:51e:eba:55ba with SMTP id i15-20020aa7dd0f000000b0051e0eba55bamr3836429edv.32.1688892769794; Sun, 09 Jul 2023 01:52:49 -0700 (PDT) MIME-Version: 1.0 Date: Sun, 9 Jul 2023 10:52:38 +0200 Message-ID: Subject: [PATCH] simplify-rtx: Fix invalid simplification with paradoxical subregs [PR110206] To: "gcc-patches@gcc.gnu.org" 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770932477323622630?= X-GMAIL-MSGID: =?utf-8?q?1770932477323622630?= As shown in the PR, simplify_gen_subreg call in simplify_replace_fn_rtx: (gdb) list 469 if (code == SUBREG) 470 { 471 op0 = simplify_replace_fn_rtx (SUBREG_REG (x), old_rtx, fn, data); 472 if (op0 == SUBREG_REG (x)) 473 return x; 474 op0 = simplify_gen_subreg (GET_MODE (x), op0, 475 GET_MODE (SUBREG_REG (x)), 476 SUBREG_BYTE (x)); 477 return op0 ? op0 : x; 478 } simplifies with following arguments: (gdb) p debug_rtx (op0) (const_vector:V4QI [ (const_int -52 [0xffffffffffffffcc]) repeated x4 ]) (gdb) p debug_rtx (x) (subreg:V16QI (reg:V4QI 98) 0) to: (gdb) p debug_rtx (op0) (const_vector:V16QI [ (const_int -52 [0xffffffffffffffcc]) repeated x16 ]) This simplification is invalid, it is not possible to get V16QImode vector from V4QImode vector, even when all elements are duplicates. The simplification happens in simplify_context::simplify_subreg: (gdb) list 7558 if (VECTOR_MODE_P (outermode) 7559 && GET_MODE_INNER (outermode) == GET_MODE_INNER (innermode) 7560 && vec_duplicate_p (op, &elt)) 7561 return gen_vec_duplicate (outermode, elt); but the above simplification is valid only for non-paradoxical registers, where outermode <= innermode. We should not assume that elements outside the original register are valid, let alone all duplicates. PR target/110206 gcc/ChangeLog: * simplify-rtx.cc (simplify_context::simplify_subreg): Avoid returning a vector with duplicated value outside the original register. gcc/testsuite/ChangeLog: * gcc.dg/torture/pr110206.c: New test. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. OK for master and release branches? Uros. diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc index d7315d82aa3..87ca25086dc 100644 --- a/gcc/simplify-rtx.cc +++ b/gcc/simplify-rtx.cc @@ -7557,6 +7557,7 @@ simplify_context::simplify_subreg (machine_mode outermode, rtx op, if (VECTOR_MODE_P (outermode) && GET_MODE_INNER (outermode) == GET_MODE_INNER (innermode) + && !paradoxical_subreg_p (outermode, innermode) && vec_duplicate_p (op, &elt)) return gen_vec_duplicate (outermode, elt); 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; +}