From patchwork Thu Jul 13 14:09:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manolis Tsamis X-Patchwork-Id: 119917 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1851767vqm; Thu, 13 Jul 2023 07:10:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlHFcovOBDm1hQcZ1K5XdRGFfruI73FE/62u3A8zZYFVDg8kc/J37WNlcfoGxdJKrfUZNRER X-Received: by 2002:a17:906:246:b0:988:b61e:4219 with SMTP id 6-20020a170906024600b00988b61e4219mr2629772ejl.29.1689257450398; Thu, 13 Jul 2023 07:10:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689257450; cv=none; d=google.com; s=arc-20160816; b=UYwu/FFGjl8Ky7oE6bCwIF1bhUu5ZuZsdzkdAJjeCnrli5OJNiChwzgnHiNuaV2Wcl Z/ZSkc+kOFpP8Rf285kGP+PrScDK9UrMTLKAFbC2CcJi9qdz13JBvFjGiNVITag42hF4 JDAMB68pHi2f3PaGOhpYUm5hXt5luneYidDie47KoIpeH10+Nep8czlBjTpcqQtjp1XI RZ/B8yRi4IU+ERU9Tyg8TEf86Qv7t9OG88HCSR/xVaw9LD/HWmCHpp+ZdgqPgKK7IbEI ZTHw6I8qPYg0ePkc8A+EctWPwbMX3U+B2zzu0USxuaxA4Br33jip6l43HzmMGiquDhU0 h0hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:delivered-to; bh=VhckYUyuVVDE3glB/lB+PDOKLZuFHiqeALfsEidKqLo=; fh=D6Yxz1I1DGJ9hxMEwgeUclSSttrsgrGLtgCEiAZlEzc=; b=P1Iu4O6SoWhyFH0996OfF5xveFGmyGiBfGpOmqXaYQHczYOFR7E44mXazw4UBj3XV+ Hnwe7Qchv67j0SzAkoDxmYnGJzQKoD6iu997egyIJh6v+zmiB3Z/e6kJsA8cKThWbsID 5lIPHwaTlmxOBLFThKK5zWr9q5REzJ9eJja1mwD7m6mRNgHoqRXow0dqbubXEsQCMn+p QoCYunJkYh63BidmOI13akXIY8txSHiUpTiW5xJ64x6CyYvaS1TJdenPFDxoZ3IM3NCS l9x+aDMt/+hNCah+64mbM8nU9yJXF1cntcWdl12V1eZ7lzi9fCwefLQGIw90ate7aWOn JxlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vrull.eu header.s=google header.b=QzQ1BfI6; 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" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id k9-20020a1709063e0900b009875f181d5fsi7418026eji.821.2023.07.13.07.10.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 07:10: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=@vrull.eu header.s=google header.b=QzQ1BfI6; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 391D4385703F for ; Thu, 13 Jul 2023 14:10:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 0429D3858CDB for ; Thu, 13 Jul 2023 14:09:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0429D3858CDB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2b72161c6e9so25844131fa.0 for ; Thu, 13 Jul 2023 07:09:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1689257358; x=1691849358; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VhckYUyuVVDE3glB/lB+PDOKLZuFHiqeALfsEidKqLo=; b=QzQ1BfI6ze5w/Rr2wLWMy4FPXtzoNPel5P722e+dy0UNs8oO1zPhxYMouk+576P1dg eYRl8OZ7G3KD5NbvI3Zixngr0oaIRrglxlialX/4/lHPE1njEyUN6zZQ61nZbv6Cb2qM erYbOU5bFvz0xVDzHB3KpuXt+uP8HO2fuSUEvqtNqZ7ApJhnwcv9q9n4Ouha6hbWmNlZ PmnmvSdvgwJT23GDo9QxdRyDVRNVqDBtmQKgzP9O/E7rw6rOlWT0sXrBKyLEJiFuxbEV DHx7dpgZRbH5gMhvLbEU6UgFrrht/4O8g9KXAp5gKjaqUlFKFTgNEOw+TyCrDqYzfKol oDjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689257358; x=1691849358; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VhckYUyuVVDE3glB/lB+PDOKLZuFHiqeALfsEidKqLo=; b=VmNjBesEwyKYkVXQWzplhYyXvYYIJmxNUt0tB9YngKDmkW2LP9w5QpRI7AoSLDMGuU rofSR78sYqUPZ4ftNudwitc6G4M/6U+5HS6ccASxfbiytOj5KHZWTL9JSoZkJXPr9QBp Uar1Dkuw5j+SX1tNQ9DZyhIFBwcLgYE/QfWmycfBcSaX0CsOSAJxEkE5hdD8vkPyqqDg ui6E7iUgvKLJPnj/W2y0W2JALt57cc9DPxAkt6m2O/1t4+ajRb5Git+1Llei4FLS2OEi boEPX75/wxIDYfzDmdmDOF4/c7Zf9LadA9egnyBhF4xUe6l97AMu5PihlrIW+PlrSwzH Dtnw== X-Gm-Message-State: ABy/qLaMw8t+EMTmf4Q6i1Pz9vMCfNK3KlDkBB3fln29Za+xjqOmdrdM ySRvc/URPupL+f6/6C2iyigVv4TygWeFX0D4gsrQlw== X-Received: by 2002:a05:651c:49b:b0:2b6:ffa4:d6ec with SMTP id s27-20020a05651c049b00b002b6ffa4d6ecmr1987733ljc.4.1689257357755; Thu, 13 Jul 2023 07:09:17 -0700 (PDT) Received: from helsinki-03.engr ([2a01:4f9:6b:2a47::2]) by smtp.gmail.com with ESMTPSA id d9-20020a2e8909000000b002b6e3337fd5sm1528181lji.7.2023.07.13.07.09.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 07:09:17 -0700 (PDT) From: Manolis Tsamis To: gcc-patches@gcc.gnu.org Cc: Philipp Tomsich , Jakub Jelinek , Andrew Pinski , Robin Dapp , Manolis Tsamis Subject: [PATCH v2 1/2] ifcvt: handle sequences that clobber flags in noce_convert_multiple_sets Date: Thu, 13 Jul 2023 16:09:03 +0200 Message-Id: <20230713140904.3274306-2-manolis.tsamis@vrull.eu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230713140904.3274306-1-manolis.tsamis@vrull.eu> References: <20230713140904.3274306-1-manolis.tsamis@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771314820062713036 X-GMAIL-MSGID: 1771314820062713036 This is an extension of what was done in PR106590. Currently if a sequence generated in noce_convert_multiple_sets clobbers the condition rtx (cc_cmp or rev_cc_cmp) then only seq1 is used afterwards (sequences that emit the comparison itself). Since this applies only from the next iteration it assumes that the sequences generated (in particular seq2) doesn't clobber the condition rtx itself before using it in the if_then_else, which is only true in specific cases (currently only register/subregister moves are allowed). This patch changes this so it also tests if seq2 clobbers cc_cmp/rev_cc_cmp in the current iteration. This makes it possible to include arithmetic operations in noce_convert_multiple_sets. gcc/ChangeLog: * ifcvt.cc (check_for_cc_cmp_clobbers): Use modified_in_p instead. (noce_convert_multiple_sets_1): Don't use seq2 if it clobbers cc_cmp. Signed-off-by: Manolis Tsamis --- (no changes since v1) gcc/ifcvt.cc | 49 +++++++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc index a0af553b9ff..3273aeca125 100644 --- a/gcc/ifcvt.cc +++ b/gcc/ifcvt.cc @@ -3375,20 +3375,6 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) return true; } -/* Helper function for noce_convert_multiple_sets_1. If store to - DEST can affect P[0] or P[1], clear P[0]. Called via note_stores. */ - -static void -check_for_cc_cmp_clobbers (rtx dest, const_rtx, void *p0) -{ - rtx *p = (rtx *) p0; - if (p[0] == NULL_RTX) - return; - if (reg_overlap_mentioned_p (dest, p[0]) - || (p[1] && reg_overlap_mentioned_p (dest, p[1]))) - p[0] = NULL_RTX; -} - /* This goes through all relevant insns of IF_INFO->then_bb and tries to create conditional moves. In case a simple move sufficis the insn should be listed in NEED_NO_CMOV. The rewired-src cases should be @@ -3552,9 +3538,17 @@ noce_convert_multiple_sets_1 (struct noce_if_info *if_info, creating an additional compare for each. If successful, costing is easier and this sequence is usually preferred. */ if (cc_cmp) - seq2 = try_emit_cmove_seq (if_info, temp, cond, - new_val, old_val, need_cmov, - &cost2, &temp_dest2, cc_cmp, rev_cc_cmp); + { + seq2 = try_emit_cmove_seq (if_info, temp, cond, + new_val, old_val, need_cmov, + &cost2, &temp_dest2, cc_cmp, rev_cc_cmp); + + /* The if_then_else in SEQ2 may be affected when cc_cmp/rev_cc_cmp is + clobbered. We can't safely use the sequence in this case. */ + if (seq2 && (modified_in_p (cc_cmp, seq2) + || (rev_cc_cmp && modified_in_p (rev_cc_cmp, seq2)))) + seq2 = NULL; + } /* The backend might have created a sequence that uses the condition. Check this. */ @@ -3609,21 +3603,16 @@ noce_convert_multiple_sets_1 (struct noce_if_info *if_info, return false; } - if (cc_cmp) + if (cc_cmp && seq == seq1) { - /* Check if SEQ can clobber registers mentioned in - cc_cmp and/or rev_cc_cmp. If yes, we need to use - only seq1 from that point on. */ - rtx cc_cmp_pair[2] = { cc_cmp, rev_cc_cmp }; - for (walk = seq; walk; walk = NEXT_INSN (walk)) + /* Check if SEQ can clobber registers mentioned in cc_cmp/rev_cc_cmp. + If yes, we need to use only seq1 from that point on. + Only check when we use seq1 since we have already tested seq2. */ + if (modified_in_p (cc_cmp, seq) + || (rev_cc_cmp && modified_in_p (rev_cc_cmp, seq))) { - note_stores (walk, check_for_cc_cmp_clobbers, cc_cmp_pair); - if (cc_cmp_pair[0] == NULL_RTX) - { - cc_cmp = NULL_RTX; - rev_cc_cmp = NULL_RTX; - break; - } + cc_cmp = NULL_RTX; + rev_cc_cmp = NULL_RTX; } } From patchwork Thu Jul 13 14:09:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manolis Tsamis X-Patchwork-Id: 119918 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1852301vqm; Thu, 13 Jul 2023 07:11:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlFjMsgd+4lSr8b+DMrEJ4qBTCJmihkEp57xLYwWQugMwW+MGb0u7e30jFzFFJ4GNCphMtxh X-Received: by 2002:a05:6512:45a:b0:4f8:5696:6bbc with SMTP id y26-20020a056512045a00b004f856966bbcmr1105628lfk.29.1689257491689; Thu, 13 Jul 2023 07:11:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689257491; cv=none; d=google.com; s=arc-20160816; b=ghHgd+hIEosmslRJD7xaROXvoi9Yb+fSkncM0csBYb3fa52GYU8IK+mDGsGkq1ZHYJ ynkm5/sqxGuL1tVdJsXNLCa+Hi9aRrVXejw6druKJ6blnEUD8lbUQYm8t/HAfxrRKABl 9NpZLVhhE/NqtlhL1+bhSAz/3QDnSNZI/kprqPFLrt8AK7yXAmR+S7xvuX0pCBdavBjD BoBt22+WCikoUXe5qHz5Uy7ocDrBOt/TV92Z+KH//T25cuyB5oaFQmsUXdWqNVi57Rrw 42nRkUglbQ34TqABpf5i+/42o2Hwzn+2+M6xw6YPMPkZh7NAyOZNFrBuXdeY/AteXUAa L0zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:delivered-to; bh=XHPJ8O8QABVZ/BDf/KYyZDsrsMiSKm3ARHb/lc2Tv08=; fh=D6Yxz1I1DGJ9hxMEwgeUclSSttrsgrGLtgCEiAZlEzc=; b=JxfQXoSV/FJxDginG5IIz2CHSgxUSxY2+XemjxUNCiCHt10uurKdXEN3CcFopXYjHr EilsLxSjdeHJEhHrGTtgxVSzr2MvAqJ2SsPoVKMT0BC+P3NGKk1vse1WGb38rZBrGNe+ PJXUq5oF8q55hbL8fwi6074MP063zjmYNu5el843IpKs4KN6NjbshpNtZ+VSvIZmizNp R0crbkWMYMMf4FY99NlK3/KhRn6bhimp8KlfEaydeaWUrQpQEaaFCvs049d9N0VCquHI z5F3Bhs1YIjPsd7dkkyt0qE5yEBKsu523QLqsSYXncmhwURu0XZuhuZOjNCOe6sDek/H E5Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vrull.eu header.s=google header.b=DraNtYSz; 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" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id i11-20020a50fc0b000000b0051bec40640bsi7139168edr.603.2023.07.13.07.11.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 07:11:31 -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=@vrull.eu header.s=google header.b=DraNtYSz; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 646453858434 for ; Thu, 13 Jul 2023 14:10:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id A91993858C62 for ; Thu, 13 Jul 2023 14:09:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A91993858C62 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4fba86f069bso1337996e87.3 for ; Thu, 13 Jul 2023 07:09:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1689257359; x=1691849359; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XHPJ8O8QABVZ/BDf/KYyZDsrsMiSKm3ARHb/lc2Tv08=; b=DraNtYSzxOZ6rGgke88/yN0jMEIlsnMfU5Ssxfo9QClgzmidsCxipjsrdcJOxmP/pL 6RF8gZn/jHQze85m1/AHqbJdclhWWA/2h+g4FePW5tYcTqrinbpPScXe8YsoVIyIwTiV x74jl8QM0DaiXF526EFfMk+/BPjFzm5Gh5/CZGyzUDa9d1w2AjjQ+Ag3dQ0t6nQ7Rf5X hasSzxz/kvVcxI+LsMDTaWlrExhBNzMStNni6ekQFwltL6ScnBfvBBemXBn8ymPwzOIe ADBqLTUATQ8JG3rhmYBsvQkf8Wsmwvv6XDpxv0G5/GZMok5KD7WnLbUjL2yfJV0J5Ied ONZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689257359; x=1691849359; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XHPJ8O8QABVZ/BDf/KYyZDsrsMiSKm3ARHb/lc2Tv08=; b=DNwh0w6LH3dt6XTk7CgVSvr/afIpLd0hqra5WsFKqLD//BX+gBBkr2VRrrhokcObUT zOgz0f+sLTWCw55rbLRIHxcK1u2P/UeRaMtXjFAaZwcy6DRCaPAvEJ02ZEr1RCERogBh 47ARcLDrH0Sb2TL7UtxhfAapyhuukSI7HkbgXS/ij5iul6Vp3QQUR6tvUyMzceB+oaSR hmEp9TGGu7vfuOCNL6LZko0y0PirpTRiE36vD65/Wy+p0cqijnUSw4V7+h5wKhHYqrHT NYDJiS1ejxiVbTbbwe5Eqj67dbQWMYy0F72u27Wohk3UnAbmEpgf2QbR2hQ99CvEe9Zo TulQ== X-Gm-Message-State: ABy/qLYLPndbppMh0uL3Z6rC/pPIapjDIiUWSTRkCEXOu7OkhsVsepwu mw84S8VVKcrWDfE/8NkGjAcwbahfdVnufyJNeCUecA== X-Received: by 2002:a2e:8082:0:b0:2b6:d8d5:15b1 with SMTP id i2-20020a2e8082000000b002b6d8d515b1mr1238760ljg.50.1689257359446; Thu, 13 Jul 2023 07:09:19 -0700 (PDT) Received: from helsinki-03.engr ([2a01:4f9:6b:2a47::2]) by smtp.gmail.com with ESMTPSA id d9-20020a2e8909000000b002b6e3337fd5sm1528181lji.7.2023.07.13.07.09.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 07:09:18 -0700 (PDT) From: Manolis Tsamis To: gcc-patches@gcc.gnu.org Cc: Philipp Tomsich , Jakub Jelinek , Andrew Pinski , Robin Dapp , Manolis Tsamis Subject: [PATCH v2 2/2] ifcvt: Allow more operations in multiple set if conversion Date: Thu, 13 Jul 2023 16:09:04 +0200 Message-Id: <20230713140904.3274306-3-manolis.tsamis@vrull.eu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230713140904.3274306-1-manolis.tsamis@vrull.eu> References: <20230713140904.3274306-1-manolis.tsamis@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771314863669579162 X-GMAIL-MSGID: 1771314863669579162 Currently the operations allowed for if conversion of a basic block with multiple sets are few, namely REG, SUBREG and CONST_INT (as controlled by bb_ok_for_noce_convert_multiple_sets). This commit allows more operations (arithmetic, compare, etc) to participate in if conversion. The target's profitability hook and ifcvt's costing is expected to reject sequences that are unprofitable. This is especially useful for targets which provide a rich selection of conditional instructions (like aarch64 which has cinc, csneg, csinv, ccmp, ...) which are currently not used in basic blocks with more than a single set. gcc/ChangeLog: * ifcvt.cc (try_emit_cmove_seq): Modify comments. (noce_convert_multiple_sets_1): Modify comments. (bb_ok_for_noce_convert_multiple_sets): Allow more operations. gcc/testsuite/ChangeLog: * gcc.target/aarch64/ifcvt_multiple_sets_arithm.c: New test. Signed-off-by: Manolis Tsamis --- Changes in v2: - Change "conditional moves" to "conditional instructions" in bb_ok_for_noce_convert_multiple_sets's comment. gcc/ifcvt.cc | 60 +++++++++++------ .../aarch64/ifcvt_multiple_sets_arithm.c | 67 +++++++++++++++++++ 2 files changed, 108 insertions(+), 19 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/ifcvt_multiple_sets_arithm.c diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc index 3273aeca125..be29403a5b5 100644 --- a/gcc/ifcvt.cc +++ b/gcc/ifcvt.cc @@ -3215,13 +3215,13 @@ try_emit_cmove_seq (struct noce_if_info *if_info, rtx temp, /* We have something like: if (x > y) - { i = a; j = b; k = c; } + { i = EXPR_A; j = EXPR_B; k = EXPR_C; } Make it: - tmp_i = (x > y) ? a : i; - tmp_j = (x > y) ? b : j; - tmp_k = (x > y) ? c : k; + tmp_i = (x > y) ? EXPR_A : i; + tmp_j = (x > y) ? EXPR_B : j; + tmp_k = (x > y) ? EXPR_C : k; i = tmp_i; j = tmp_j; k = tmp_k; @@ -3637,11 +3637,10 @@ noce_convert_multiple_sets_1 (struct noce_if_info *if_info, -/* Return true iff basic block TEST_BB is comprised of only - (SET (REG) (REG)) insns suitable for conversion to a series - of conditional moves. Also check that we have more than one set - (other routines can handle a single set better than we would), and - fewer than PARAM_MAX_RTL_IF_CONVERSION_INSNS sets. While going +/* Return true iff basic block TEST_BB is suitable for conversion to a + series of conditional instructions. Also check that we have more than + one set (other routines can handle a single set better than we would), + and fewer than PARAM_MAX_RTL_IF_CONVERSION_INSNS sets. While going through the insns store the sum of their potential costs in COST. */ static bool @@ -3667,20 +3666,43 @@ bb_ok_for_noce_convert_multiple_sets (basic_block test_bb, unsigned *cost) rtx dest = SET_DEST (set); rtx src = SET_SRC (set); - /* We can possibly relax this, but for now only handle REG to REG - (including subreg) moves. This avoids any issues that might come - from introducing loads/stores that might violate data-race-freedom - guarantees. */ - if (!REG_P (dest)) + /* Do not handle anything involving memory loads/stores since it might + violate data-race-freedom guarantees. */ + if (!REG_P (dest) || contains_mem_rtx_p (src)) return false; - if (!((REG_P (src) || CONSTANT_P (src)) - || (GET_CODE (src) == SUBREG && REG_P (SUBREG_REG (src)) - && subreg_lowpart_p (src)))) + /* Allow a wide range of operations and let the costing function decide + if the conversion is worth it later. */ + enum rtx_code code = GET_CODE (src); + if (!(CONSTANT_P (src) + || code == REG + || code == SUBREG + || code == ZERO_EXTEND + || code == SIGN_EXTEND + || code == NOT + || code == NEG + || code == PLUS + || code == MINUS + || code == AND + || code == IOR + || code == MULT + || code == ASHIFT + || code == ASHIFTRT + || code == NE + || code == EQ + || code == GE + || code == GT + || code == LE + || code == LT + || code == GEU + || code == GTU + || code == LEU + || code == LTU + || code == COMPARE)) return false; - /* Destination must be appropriate for a conditional write. */ - if (!noce_operand_ok (dest)) + /* Destination and source must be appropriate. */ + if (!noce_operand_ok (dest) || !noce_operand_ok (src)) return false; /* We must be able to conditionally move in this mode. */ diff --git a/gcc/testsuite/gcc.target/aarch64/ifcvt_multiple_sets_arithm.c b/gcc/testsuite/gcc.target/aarch64/ifcvt_multiple_sets_arithm.c new file mode 100644 index 00000000000..f29cc72263a --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/ifcvt_multiple_sets_arithm.c @@ -0,0 +1,67 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-rtl-ce1" } */ + +void sink2(int, int); +void sink3(int, int, int); + +void cond_1(int cond, int x, int y) { + if (cond) { + x = x << 4; + y = 1; + } + + sink2(x, y); +} + +void cond_2(int cond, int x, int y) { + if (cond) { + x++; + y++; + } + + sink2(x, y); +} + +void cond_3(int cond, int x1, int x2, int x3) { + if (cond) { + x1++; + x2++; + x3++; + } + + sink3(x1, x2, x3); +} + +void cond_4(int cond, int x, int y) { + if (cond) { + x += 2; + y += 3; + } + + sink2(x, y); +} + +void cond_5(int cond, int x, int y, int r1, int r2) { + if (cond) { + x = r1 + 2; + y = r2 - 34; + } + + sink2(x, y); +} + +void cond_6(int cond, int x, int y) { + if (cond) { + x = -x; + y = ~y; + } + + sink2(x, y); +} + +/* { dg-final { scan-assembler-times "cinc\t" 5 } } */ +/* { dg-final { scan-assembler-times "csneg\t" 1 } } */ +/* { dg-final { scan-assembler-times "csinv\t" 1 } } */ +/* { dg-final { scan-assembler "csel\t" 1 } } */ + +/* { dg-final { scan-rtl-dump-times "if-conversion succeeded through noce_convert_multiple_sets" 6 "ce1" } } */ \ No newline at end of file