From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id D13F039960F4 for ; Mon, 3 Jun 2024 11:37:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D13F039960F4 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D13F039960F4 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::630 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717414673; cv=none; b=CQj18m6BGWnWqa8xhyFkjD1MjWhDjWhqIsRo4GBfIOMh93MK1UqzXZpwR5kvm4IihlOLv/lnGMJQC1IF0A1bjG49cC/b7zW4sZ9SIHsji/kDuw9J3ZnhMo/4QBKN90hrDhlnhJK+hVbhNwQmu0mg822da6QCLuEh7GU8Im+zjL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717414673; c=relaxed/simple; bh=7DHuN4NHUU2X6zZfxqu3gwflHcQO1kD08vlJusRIsf8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=WxHmASRAPRIC4IOWH5ws2JxY8YWN6kFyO26CbUb/DShDuiKwoTdy/p8KJxISqfizssw/GmLm3/cMgYduo1SrCzR/jHNaoPAC0bUfFK1WT8SWDHzGc/ybfrl5i5JWgBYXkA7iYSca/2G1DoiU++V5iYhoZYSf/IgzApa3Ox8/6s8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a68f10171bdso140171166b.0 for ; Mon, 03 Jun 2024 04:37:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1717414667; x=1718019467; darn=gcc.gnu.org; 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=f3wD+4XetBwKzVT4wW2lAAWDNLxJJDohmSlYLDPiy0M=; b=YmB697u/r8lwn8OyZ9O6bzLVIeyD76OYsF7gTm/FGvecLAxqh1GQSJCjLOVFAVMeBE EnwPsgcE8r9esqMscEFwd2G1PixPHCF5KBLc94ZMQKtdNxV37zgpJFAJcHYllUroCQiO midxM+QIXTJKfN9MBLuqKhVIkzMDbcoNjFyNAwKZM45RLRnSppqENSf6PDrnasFHxyGO XMfKOaOTqj3fA7GR9Jmb1zWVAtucYqJQHt8qrQxQE7SkNfMW1ANHzTH9GRDEtDUTDroa 6XFSYio8/esgmWxztWndTQpOtzLLtLfYJczZ/wExW06jcpVU69bSARwmhe5ivH3CNE40 2SKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717414667; x=1718019467; 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=f3wD+4XetBwKzVT4wW2lAAWDNLxJJDohmSlYLDPiy0M=; b=jAg+WPUqAAhnr8BI+Gs6rptQASDZH+ZRSP/OWzqDCbYCHWFLJccqpneQsnuY8r2wE7 gduI9vmgXL8P4odfMrKTAgd3aRqMLtSHOVW8QHSoIgUO+Ae7X4tMMXS4d+otON5E2pBz TyK0huspwy42UwrqpmFPTrOE84zgt6ouFhFN4JoQUFgzrAsz63CLJ9yx42iYQ08ugzoT MeOHmxbxv8JcuVJMCaV/eeIJhaLNSWVRZoJAQtwUKF9vnuzl2qqsE9png6OaQ3ffNkry OAnYU1ukr1XJZgDs+48BzNlT6MRAvCibPk3ghhiB4O5fX1v1MqAyyv43yiE2K53+y+Xs 8zFQ== X-Gm-Message-State: AOJu0YyDO/TGotS+WfotDIsv2F3ha/fdxN6M0eA4a8eEDKkj1CfAObYY cHGooW3aqGY+FwIgKTAMV7M7VXJJVh1r6SnkAbogHCYr6ja3AgJEAatTxyXeST+ESFgdmqPgxmy VJ4Q= X-Google-Smtp-Source: AGHT+IFWV0KoLDjUX4OYXlZk6m7XDrqFpEtELTQRgcKsCV5I177hTwN4JNJY/wuSyKX1GM+lzKDRHQ== X-Received: by 2002:a17:906:4684:b0:a62:ac5f:f95d with SMTP id a640c23a62f3a-a681fc5d5f9mr729484466b.14.1717414666835; Mon, 03 Jun 2024 04:37:46 -0700 (PDT) Received: from altra2.sec.univie.ac.at (altra2.sec.univie.ac.at. [131.130.126.102]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a67ea586910sm475080766b.113.2024.06.03.04.37.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 04:37:46 -0700 (PDT) From: Manolis Tsamis To: gcc-patches@gcc.gnu.org Cc: Philipp Tomsich , Jiangning Liu , Jakub Jelinek , Robin Dapp , Richard Sandiford , =?UTF-8?q?Christoph=20M=C3=BCllner?= , Manolis Tsamis Subject: [PING] [PATCH v4 1/3] [RFC] ifcvt: handle sequences that clobber flags in noce_convert_multiple_sets Date: Mon, 3 Jun 2024 04:34:27 -0700 Message-ID: <20240603113546.3299391-2-manolis.tsamis@vrull.eu> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240603113546.3299391-1-manolis.tsamis@vrull.eu> References: <20240603113546.3299391-1-manolis.tsamis@vrull.eu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 List-Id: 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. It also makes the code that checks whether the condition is used outside of the if_then_else emitted more robust. 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. Refactor the code that sets read_comparison. Signed-off-by: Manolis Tsamis --- (no changes since v1) gcc/ifcvt.cc | 106 ++++++++++++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 47 deletions(-) diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc index 58ed42673e5..763a25f816e 100644 --- a/gcc/ifcvt.cc +++ b/gcc/ifcvt.cc @@ -3592,20 +3592,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 @@ -3731,36 +3717,67 @@ 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. */ + condition as a value. Check this. */ + + /* We cannot handle anything more complex than a reg or constant. */ + if (!REG_P (XEXP (cond, 0)) && !CONSTANT_P (XEXP (cond, 0))) + read_comparison = true; + + if (!REG_P (XEXP (cond, 1)) && !CONSTANT_P (XEXP (cond, 1))) + read_comparison = true; + rtx_insn *walk = seq2; - while (walk) + int if_then_else_count = 0; + while (walk && !read_comparison) { - rtx set = single_set (walk); + rtx exprs_to_check[2]; + unsigned int exprs_count = 0; - if (!set || !SET_SRC (set)) + rtx set = single_set (walk); + if (set && XEXP (set, 1) + && GET_CODE (XEXP (set, 1)) == IF_THEN_ELSE) { - walk = NEXT_INSN (walk); - continue; + /* We assume that this is the cmove created by the backend that + naturally uses the condition. */ + exprs_to_check[exprs_count++] = XEXP (XEXP (set, 1), 1); + exprs_to_check[exprs_count++] = XEXP (XEXP (set, 1), 2); + if_then_else_count++; } + else if (NONDEBUG_INSN_P (walk)) + exprs_to_check[exprs_count++] = PATTERN (walk); - rtx src = SET_SRC (set); + /* Bail if we get more than one if_then_else because the assumption + above may be incorrect. */ + if (if_then_else_count > 1) + { + read_comparison = true; + break; + } - if (XEXP (set, 1) && GET_CODE (XEXP (set, 1)) == IF_THEN_ELSE) - ; /* We assume that this is the cmove created by the backend that - naturally uses the condition. Therefore we ignore it. */ - else + for (unsigned int i = 0; i < exprs_count; i++) { - if (reg_mentioned_p (XEXP (cond, 0), src) - || reg_mentioned_p (XEXP (cond, 1), src)) - { - read_comparison = true; - break; - } + subrtx_iterator::array_type array; + FOR_EACH_SUBRTX (iter, array, exprs_to_check[i], NONCONST) + if (*iter != NULL_RTX + && (reg_overlap_mentioned_p (XEXP (cond, 0), *iter) + || reg_overlap_mentioned_p (XEXP (cond, 1), *iter))) + { + read_comparison = true; + break; + } } walk = NEXT_INSN (walk); @@ -3788,21 +3805,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; } } -- 2.44.0