From patchwork Tue Jun 20 09:54:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 110386 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3547210vqr; Tue, 20 Jun 2023 02:56:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4vVvEwXnQjq8Uj4/otpFw/4cb9/1S9iRm/kzCLPsMBpJkuNpAN51v2KDR/MtCQfdfz8eFY X-Received: by 2002:aa7:c544:0:b0:51a:46e9:27d3 with SMTP id s4-20020aa7c544000000b0051a46e927d3mr5952266edr.36.1687254987857; Tue, 20 Jun 2023 02:56:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687254987; cv=none; d=google.com; s=arc-20160816; b=AqoSJYSe+zukNpOFyI6tFaTlsdTFWCFT1bRVtgMzatDMRaSDB3H2hxTJ0JlQqM3Pwo PmIEjyFMPZ+xrjhD20fGkk+Vhj7CeA9vYt5RdZBEhDHl0LnPW9wSsmDSG+niywey4d09 0E86TJxlJwdEAeLx41kgQJ1DD1UIAPGc+RBm0ZlItgtLM+3sat7JISOhjPC0mv9bjOPi Xh1ER97d1K272FS//1s2ngwIJWoepy89o4Yp9Hm8mnl4uRu9T7WT2/v8e/Z9zTofryrt TbmiLISoqJfhxG4VtASpPu6NVeoqyiTL3QpnOACLU6ZfYAaiM4wkQLfvNZuj9Ppiu+HH rOSg== 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=h84alXXbf4hqaTedBfCOfV6X6BeROy3cHfIvKz2RuwQ=; b=hzWCHlaAkSPGiEldVwjE6/byFrqJrYi2P26o0W7SrRirbtbpFJk49y32fWh/nzuETJ w7gnse1+oPuaB+LVKK5RIOI3rnM0w4JNgYPoTr8gQ93qWftxJ6pbWalCGP4aYZB8jVSk +6gRkaCXVKq71KdjBhbrAG8l8LlV1U6hUXPJ7uFKU5TjOkNqCd8bVuj/Vl038D0xI340 rmTbOcK1GyDCnQ4MU/SCdnO63xz01oKyeoe9M7HjOeF+M7oOXlurxGKM3yQ9bifCW6X5 FoaXQpNHhQmwkr/jECpqYCnms9Ezluv0XwYnOnSUNH7CdbcLOwprxw5H7fJ/3NRrAy2E VxIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KaAQeAuv; 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u25-20020aa7d0d9000000b0051872677b89si1008240edo.640.2023.06.20.02.56.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 02:56:27 -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=KaAQeAuv; 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 82C653858C54 for ; Tue, 20 Jun 2023 09:56:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 82C653858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687254986; bh=h84alXXbf4hqaTedBfCOfV6X6BeROy3cHfIvKz2RuwQ=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=KaAQeAuvlyKl3V0TdEoU+b7ciE8qzj+fIL0AFq2z/8bQe3xoxbbHEWYOe1ATOskoo H5vgHUMCb9+saMro0Laj/3dhbx4jRtS+F9IonwsSOnDonx9x/+FVqGYaxypFBGtl7t 8nUwPW49g82s6rdwSwLfiMDL9W2/H5SSYvJgFzx8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 3D8EA3858D1E for ; Tue, 20 Jun 2023 09:55:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3D8EA3858D1E Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3f904dcc1e2so34507885e9.3 for ; Tue, 20 Jun 2023 02:55:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687254934; x=1689846934; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=h84alXXbf4hqaTedBfCOfV6X6BeROy3cHfIvKz2RuwQ=; b=MIuewiLyveHWjzLddEE5PJlX8ngtuHwrquOms/lMpNf2ImwHyKHM4JNzV7v/2CEUbM 7JKy0ro4tBc3Yx5ntkPTMnVDCdPONfbR7dogoLe/I4ibDlkprL/Z6G12FRb/9aH6GAsN 1GO4O8oVnEO0TrRKhjcQ/74grkucIO3QumipH2gHCT8T2hR2P13oC+pV9zOUiKWEfT9x OZASJNtObTtrfW0Zwwov3A2AsiQH2Comb7vbd0+fyQ/FNVYw/YR5bmvaPq8EKEGOoTEr CPbGyNL1H0Qw/aj2YB9SCdJRweTtl5DjuO1tjHQ3IAcX/Ruu0efcCzxoUpS+KaSppY6S 4LTA== X-Gm-Message-State: AC+VfDxaCpEcGD56sQQpDSMo6jwOKGjrhv/KuoRpiPLMLLc8jIaKrvDl i9fvHPITaeObncKBY1PzASQUu5ENl+Nw0yp1BnyIq/FGKcqLqHUQZgA= X-Received: by 2002:a5d:4149:0:b0:306:39a8:6fa2 with SMTP id c9-20020a5d4149000000b0030639a86fa2mr8907796wrq.61.1687254933787; Tue, 20 Jun 2023 02:55:33 -0700 (PDT) MIME-Version: 1.0 Date: Tue, 20 Jun 2023 15:24:58 +0530 Message-ID: Subject: [SVE][match.pd] Fix ICE observed in PR110280 To: gcc Patches , Richard Sandiford X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, WEIRD_PORT 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: Prathamesh Kulkarni via Gcc-patches From: Prathamesh Kulkarni Reply-To: Prathamesh Kulkarni 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?1769215086130226056?= X-GMAIL-MSGID: =?utf-8?q?1769215086130226056?= Hi Richard, For the following reduced test-case taken from PR: #include "arm_sve.h" svuint32_t l() { alignas(16) const unsigned int lanes[4] = {0, 0, 0, 0}; return svld1rq_u32(svptrue_b8(), lanes); } compiling with -O3 -mcpu=generic+sve results in following ICE: during GIMPLE pass: fre pr110280.c: In function 'l': pr110280.c:5:1: internal compiler error: in eliminate_stmt, at tree-ssa-sccvn.cc:6890 5 | } | ^ 0x865fb1 eliminate_dom_walker::eliminate_stmt(basic_block_def*, gimple_stmt_iterator*) ../../gcc/gcc/tree-ssa-sccvn.cc:6890 0x120bf4d eliminate_dom_walker::before_dom_children(basic_block_def*) ../../gcc/gcc/tree-ssa-sccvn.cc:7324 0x120bf4d eliminate_dom_walker::before_dom_children(basic_block_def*) ../../gcc/gcc/tree-ssa-sccvn.cc:7257 0x1aeec77 dom_walker::walk(basic_block_def*) ../../gcc/gcc/domwalk.cc:311 0x11fd924 eliminate_with_rpo_vn(bitmap_head*) ../../gcc/gcc/tree-ssa-sccvn.cc:7504 0x1214664 do_rpo_vn_1 ../../gcc/gcc/tree-ssa-sccvn.cc:8616 0x1215ba5 execute ../../gcc/gcc/tree-ssa-sccvn.cc:8702 cc1 simplifies: lanes[0] = 0; lanes[1] = 0; lanes[2] = 0; lanes[3] = 0; _1 = { -1, ... }; _7 = svld1rq_u32 (_1, &lanes); to: _9 = MEM [(unsigned int * {ref-all})&lanes]; _7 = VEC_PERM_EXPR <_9, _9, { 0, 1, 2, 3, ... }>; and then fre1 dump shows: Applying pattern match.pd:8675, generic-match-5.cc:9025 Match-and-simplified VEC_PERM_EXPR <_9, _9, { 0, 1, 2, 3, ... }> to { 0, 0, 0, 0 } RHS VEC_PERM_EXPR <_9, _9, { 0, 1, 2, 3, ... }> simplified to { 0, 0, 0, 0 } The issue seems to be with the following pattern: (simplify (vec_perm vec_same_elem_p@0 @0 @1) @0) which simplifies above VEC_PERM_EXPR to: _7 = {0, 0, 0, 0} which is incorrect since _9 and mask have different vector lengths. The attached patch amends the pattern to simplify above VEC_PERM_EXPR only if operand and mask have same number of elements, which seems to fix the issue, and we're left with the following in .optimized dump: [local count: 1073741824]: _2 = VEC_PERM_EXPR <{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 1, 2, 3, ... }>; return _2; code-gen: l: mov z0.b, #0 ret Patch is bootstrapped+tested on aarch64-linux-gnu. OK to commit ? Thanks, Prathamesh [SVE][match.pd] Fix ICE observed in PR110280. gcc/ChangeLog: PR tree-optimization/110280 * match.pd (vec_perm_expr(v, v, mask) -> v): Simplify the pattern only if operand and mask of VEC_PERM_EXPR have same number of elements. gcc/testsuite/ChangeLog: * gcc.target/aarch64/sve/pr110280.c: New test. diff --git a/gcc/match.pd b/gcc/match.pd index 2dd23826034..0eb5f8f0af6 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -8669,10 +8669,11 @@ and, @0 (if (uniform_vector_p (@0)))) - (simplify (vec_perm vec_same_elem_p@0 @0 @1) - @0) + (if (known_eq (TYPE_VECTOR_SUBPARTS (TREE_TYPE (@0)), + TYPE_VECTOR_SUBPARTS (TREE_TYPE (@1)))) + @0)) /* Push VEC_PERM earlier if that may help FMA perception (PR101895). */ (simplify diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pr110280.c b/gcc/testsuite/gcc.target/aarch64/sve/pr110280.c new file mode 100644 index 00000000000..453c9cbcf9e --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/pr110280.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O3" } */ + +#include "arm_sve.h" + +svuint32_t l() +{ + _Alignas(16) const unsigned int lanes[4] = {0, 0, 0, 0}; + return svld1rq_u32(svptrue_b8(), lanes); +}