From patchwork Fri Sep 8 17:54:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 137766 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp699697vqo; Fri, 8 Sep 2023 10:55:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFF/fq6XdjYzYttoDQBmD92WPcuIR0lRVhDYSUqQmv9i9IXlwwBvrkQfENqNaX7KP2HCiBE X-Received: by 2002:a05:6402:164a:b0:525:4471:6b53 with SMTP id s10-20020a056402164a00b0052544716b53mr2555167edx.19.1694195724875; Fri, 08 Sep 2023 10:55:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694195724; cv=none; d=google.com; s=arc-20160816; b=dmcRSem0qNLmwIdzmY1rsJ2m/pnXXh1L2GQpy0tT/H9MljeOlboqk9OAnYV41XO6S/ MTeAjh6Y6wmWErrHZzhL69bw0hHWaWqHmZT9pyZo94k1ybT4CLHNkeYtbQ+/Yrpg195m eCgakPZMlzxYhe1AxHjdPB2wbCB4I8crmRbsJ0RQHfOlvkBzr0IsbSbKSA6tGHB+AJ+M mHj39q30JaJynE3WVSUXkbC/9+mOxgL0MBUUQVyPwirWHqqYs7vF1395vRTwPn5uaLgr prRfsErK7ec3L++6VO9nGIWNNG2Rtj6YR0et2tg5Mg9XkVX82j9oAZZUJlm1fzXynehz norQ== 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 :content-transfer-encoding:subject:to:content-language:user-agent :mime-version:date:message-id:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=oAPP23jJWkwnsJjW24tl46hF7DkYRqlkq0KOX+VQksY=; fh=8G0fvw9kezX2+yjwifXgHvTII1omy92vRpR1R+rFCOA=; b=i22ILONTl+auUKcGkPwYgtsm7HQ8CQ+4+MTYi5raQgOiTrNvozROHXFy2WdZdUUMV1 FuBC8QMftI2Fc3OubOJqUCJzYXAfOO4f7OYMkynRIzaMIy/HF3hM/p1e7F1mKFwIxE0I ZQ5Oaov1+RTZd1csyKqKfWgh6GWRrAZvo8fPnlldSqE/ip3wcKiNrv8otrrexp86VpB7 cIgorbFPD4D923mNg4lcfYp1RReVBEDl7mhbBar8ICfeXawv01LiTb3CM8/59jCyeupr 6t2Vfak2/QWfviZT+7EcesPDBi8NpoQTA3qDEqM4pbRH8AT93xy7+31tC5QF0TmteZY0 sjuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pPppJ2bN; 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 b6-20020a05640202c600b005259c7c5fcasi1831688edx.62.2023.09.08.10.55.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 10:55:24 -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=pPppJ2bN; 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 8C9053858426 for ; Fri, 8 Sep 2023 17:55:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C9053858426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694195723; bh=oAPP23jJWkwnsJjW24tl46hF7DkYRqlkq0KOX+VQksY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=pPppJ2bN6a5PnXxa5vDBxwLYzrmU+bCeTRle9xioeWV2uEFaG8e3/NfNvP4r6vs+B 398e+ab9sPFQQkAQLnGPxgGo73J0Idr+gDX+okFx7x4EEjACx4Zilk0sv1GMxDqKn2 AcxDB21C10NB3d9jN5X97P0c0Hxg+gtQmbdqwmsM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id 529C33858D1E for ; Fri, 8 Sep 2023 17:54:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 529C33858D1E Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-502a4f33440so681113e87.1 for ; Fri, 08 Sep 2023 10:54:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694195677; x=1694800477; h=content-transfer-encoding:subject:from:to:content-language:cc :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=oAPP23jJWkwnsJjW24tl46hF7DkYRqlkq0KOX+VQksY=; b=GtPovnaEwKZQjOvTZKk2VG42WhoVzpj7n0OEQ5K2Eh9pJxYGzR47qNCdHgxRKHuQFJ b/9nXofwNC1PZFCVtOAEnc5qNgHlvgsF80ajJCAeIxDpZL2YXLmSPGm8LuCcP0Ci4LW8 asqsPxMn38B8gmUegXCy4r6GmSLwqbtuJG1Gg1K2R6GE8qNmott87JXywQ8WzefScw/U 0bC06CTOx9xAHigBmkpuw0g7/aZ/69enMTTnPObbiRQdTh0MmvzcwHWI5iwqgdn27qqN 9Evt79yIlyXqYEW6roiyph6Kit3mM1HmjvbJBXjjHxCLRQGZWu9+wTtYxvh91Tbz1eQC xq/Q== X-Gm-Message-State: AOJu0YxicPw+jtWfWMVqSd4UoVISiwGsMPd9bc7qA5ESnVFNGynd2lDf 6uWFE2U5Z0tTSxqNS8Z0bS0sBBA/lsHeGQ== X-Received: by 2002:a05:6512:10cc:b0:500:a396:b2e4 with SMTP id k12-20020a05651210cc00b00500a396b2e4mr2734304lfg.58.1694195677059; Fri, 08 Sep 2023 10:54:37 -0700 (PDT) Received: from [192.168.1.24] (ip-046-005-130-086.um12.pools.vodafone-ip.de. [46.5.130.86]) by smtp.gmail.com with ESMTPSA id s6-20020aa7c546000000b00521953ce6e0sm1286723edr.93.2023.09.08.10.54.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 Sep 2023 10:54:36 -0700 (PDT) Message-ID: <368038d2-e7a3-522d-18d1-6b04fa182896@gmail.com> Date: Fri, 8 Sep 2023 19:54:35 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Content-Language: en-US To: gcc-patches Subject: [PATCH] match: Don't sink comparisons into vec_cond operands. X-Spam-Status: No, score=-9.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 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Robin Dapp via Gcc-patches From: Robin Dapp Reply-To: Robin Dapp Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776492976664020994 X-GMAIL-MSGID: 1776492976664020994 Hi, on riscv gcc.dg/pr70252.cĀ ICEs at gimple-isel.cc:283. This is because we created the gimple statement mask__7.36_170 = VEC_COND_EXPR ; during vrp2. What happens is that, starting with maskdest = (vec_cond mask1 1 0) >= (vec_cond mask2 1 0) we fold to maskdest = mask1 >= (vec_cond (mask2 1 0)) and then sink the "mask1 >=" into the vec_cond so we end up with maskdest = vec_cond (mask2 ? mask1 : 0), i.e. a vec_cond with a mask "data mode". In gimple-isel, when the target does not provide a vcond_mask implementation for that (which none does) we fail the assertion that the mask mode be MODE_VECTOR_INT. To prevent this, this patch restricts the match.pd sinking pattern to non-mask types. I was also thinking about restricting the type of the operands, wondering if that would be less intrusive. Bootstrapped and regression-tested on x86 and aarch64. Regards Robin gcc/ChangeLog: PR target/111337 * match.pd: Do not sink comparisons into vec_conds when the type is a vector mask. --- gcc/match.pd | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/gcc/match.pd b/gcc/match.pd index 8c24dae71cd..db3e698f471 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4856,7 +4856,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (vec_cond @0 (view_convert! @1) (view_convert! @2)))) /* Sink binary operation to branches, but only if we can fold it. */ -(for op (tcc_comparison plus minus mult bit_and bit_ior bit_xor +(for op (plus minus mult bit_and bit_ior bit_xor lshift rshift rdiv trunc_div ceil_div floor_div round_div trunc_mod ceil_mod floor_mod round_mod min max) /* (c ? a : b) op (c ? d : e) --> c ? (a op d) : (b op e) */ @@ -4872,6 +4872,28 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (op @3 (vec_cond:s @0 @1 @2)) (vec_cond @0 (op! @3 @1) (op! @3 @2)))) +/* Comparison sinks might be folded into vector masks which could + end up as "data" operand of a vec_cond + e.g. (vec_cond @0 (mask1) (...)). + gimple-isel does not handle such cases if the target does not provide + a vcond_mask. Therefore, restrict the operands to non-mask classes. */ +(for op (tcc_comparison) +/* (c ? a : b) op (c ? d : e) --> c ? (a op d) : (b op e) */ + (simplify + (op (vec_cond:s @0 @1 @2) (vec_cond:s @0 @3 @4)) + (if (GET_MODE_CLASS (TYPE_MODE (type)) != MODE_VECTOR_BOOL) + (vec_cond @0 (op! @1 @3) (op! @2 @4)))) + +/* (c ? a : b) op d --> c ? (a op d) : (b op d) */ + (simplify + (op (vec_cond:s @0 @1 @2) @3) + (if (GET_MODE_CLASS (TYPE_MODE (type)) != MODE_VECTOR_BOOL) + (vec_cond @0 (op! @1 @3) (op! @2 @3)))) + (simplify + (op @3 (vec_cond:s @0 @1 @2)) + (if (GET_MODE_CLASS (TYPE_MODE (type)) != MODE_VECTOR_BOOL) + (vec_cond @0 (op! @3 @1) (op! @3 @2))))) + #if GIMPLE (match (nop_atomic_bit_test_and_p @0 @1 @4) (bit_and (convert?@4 (ATOMIC_FETCH_OR_XOR_N @2 INTEGER_CST@0 @3))