From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 101693858D39 for ; Sat, 1 Jul 2023 09:42:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 101693858D39 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-x12a.google.com with SMTP id 2adb3069b0e04-4f86e6e4038so3446109e87.0 for ; Sat, 01 Jul 2023 02:42:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1688204565; x=1690796565; 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=SQ6rSKULw0GyF0IWjPCQRqLZrs4WntjBkBSglzPHmyI=; b=PSBzRcCL9j8xDTy5XoWIPCgbtsDDkAEA3yqdnpKi5JTdaBCV3Rl4mrXdKMVvxP6A59 88WOZnspaJwGeH/BlpsoGp1/fxmU3cKRJTZ1Y4HSJoCVC1FiKOFlpLexTHDtGJXK0cTL nEbKpEhAg0zuLU0CEfL/JxqHH2WrCIS4pRWWEhJpzmW/nNbnchHa4SLbFAhE6bk/PMwb gGP8VhYN4i1ZxfndFU2N7YiSGvjDKkXEEbhKTicYypGAqxCTOGhcqHs1JsLq3oRqCwM4 ACaa3kaN7O2KYGjNWikZa62gyjgvCa4awD1S2Rav7Kqbprx4TbKrkg3OTQ9ohg37FgX7 YKmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688204565; x=1690796565; 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=SQ6rSKULw0GyF0IWjPCQRqLZrs4WntjBkBSglzPHmyI=; b=hZng4hDU0td+YCPtk3q7jHds1GfE+1kFioeGMDBQZem+I+dQDmUyuUFWoGKCevJsAp zMCxcym6XlSUVBDeqBcfcQkhPBgWhYne9A+EkT+LqyJullJMt5L0x1lSdEevN/jqvF2f xar59P/wPhNdvhbFyjcyRAiD7U1fuuClWJbupC3uuOgrHmhIVE2Q5jupJVH4A9vo+5wD GRRoieJgTxMnG6034tUxGWn70/SmNugEE0cI5qMzBJTx8TpzUAjBQMUnH2EE045iiziL U6qoYFq/LqsaWy868Tw/NGzCyx+lNsgyo/l8uVxGa7z5kaSrCLWLuLcGBdhtT1eLcX9p 9pTg== X-Gm-Message-State: ABy/qLY+vDAStcR1y2V+qMcMYon/00ZbYwsIFsJcWbFHEpBxdPLd/J0C 4mMJXtmkyCtGFP71uHDFUr3OxAFLBSZ3f4th3bITew== X-Google-Smtp-Source: APBJJlEzWXjGJ9O7W8vb1Sweo18D+SgoY8NZybnTX9HhqaFn2IyS2XS+IgDD5BsFvOSg7dat3y1pHg== X-Received: by 2002:a05:6512:4013:b0:4f9:56b8:45e5 with SMTP id br19-20020a056512401300b004f956b845e5mr1947241lfb.25.1688204565422; Sat, 01 Jul 2023 02:42:45 -0700 (PDT) Received: from helsinki-03.engr ([2a01:4f9:6b:2a47::2]) by smtp.gmail.com with ESMTPSA id d27-20020ac244db000000b004f27471e0aesm3296374lfm.79.2023.07.01.02.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jul 2023 02:42:45 -0700 (PDT) From: Manolis Tsamis To: gcc-patches@gcc.gnu.org Cc: Jakub Jelinek , Philipp Tomsich , Robin Dapp , Andrew Pinski , Manolis Tsamis Subject: [PATCH 1/2] ifcvt: handle sequences that clobber flags in noce_convert_multiple_sets Date: Sat, 1 Jul 2023 11:24:12 +0200 Message-Id: <20230701092413.2488806-2-manolis.tsamis@vrull.eu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230701092413.2488806-1-manolis.tsamis@vrull.eu> References: <20230701092413.2488806-1-manolis.tsamis@vrull.eu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.4 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 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. 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 --- gcc/ifcvt.cc | 49 +++++++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc index 0b180b4568f..fd1ce8a1049 100644 --- a/gcc/ifcvt.cc +++ b/gcc/ifcvt.cc @@ -3373,20 +3373,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 @@ -3550,9 +3536,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. */ @@ -3607,21 +3601,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.34.1