Message ID | 024501d9900a$682ef1c0$388cd540$@nextmovesoftware.com |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp711387vqr; Fri, 26 May 2023 12:44:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7uRNRr5f6Mug+xFYmWRToHBuojkaznF6etzx4G5ZDS87dJQ45OJp/thFbBN0GQkt6NPbtP X-Received: by 2002:a05:6402:1489:b0:510:e6db:a5ac with SMTP id e9-20020a056402148900b00510e6dba5acmr1931009edv.33.1685130272670; Fri, 26 May 2023 12:44:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685130272; cv=none; d=google.com; s=arc-20160816; b=jH6eOx1Xiz/h8MDYRTcx1cvil1/zV2Br8Xdqy/jnpJlzeiBpUv4esVyU4tQaOm0W9S RTOj4btkXjJAT5ceo27ZkDJsZi/QwmXVuuCdsc2ONGD2yh18MdrHfijRCJGGpKdQup/1 hGiDEaCclu49AJRbrXdFfYAOtWoc4Izr6XutKBcWsAfBhL+PVh6D25EQMzs189OUO97K xKjvBewDSAo54Kd6KmqYvRc0s5ccxbB07rsmwMQOsGZCXBO2kSCUMOg1sx16/Z8MiqVy jKJhIojF7pJO7hoA0tTnp8BjZKxXW07Y0y5fFyONN2S7FBuDA46hpQ2Y3TFrTSWFUC5K rqfw== 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-language:thread-index :mime-version:message-id:date:subject:to:from:dkim-signature :dmarc-filter:delivered-to; bh=qNHMDfOU9lDDcA3uG63oWeElKH0/3odzXW9tXK5pEBM=; b=d63wBAWjcnAIZQeqrKrbc+PDuT8CVhyRZHf3XCMMTGtqbQan4tnVNrlyBEvcrPZwks EP6939ndmjwrfal5INv8/lVagnGDbwTu3RndbLuOHUvOLZU/pLRGIFaSQB1eynZfByQP lKMFkDLhQJMB/MZ9dCf5hTYSaOmYGMAVKUHUpvJENf6FMP7QyqYML6ZiyJcskOBl7ygk rB53uiqdrM1CE8Ibjvcu+EE1HJWknv/Uq3Md+3DvucU81OZMsKJbL+5pv+ktuqb/LVhL wIm5JkFJ1XvQLjCwH0xwUoEjtMtXQPzkgdDoPadSouvNpNnSUPovQodN9SCpB7NoYU7R FXyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=otuULvxT; 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f11-20020a056402150b00b00504a27c35cbsi405325edw.313.2023.05.26.12.44.32 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 12:44:32 -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=fail header.i=@nextmovesoftware.com header.s=default header.b=otuULvxT; 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 D45C13856DE7 for <ouuuleilei@gmail.com>; Fri, 26 May 2023 19:44:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 186BC3858C5F for <gcc-patches@gcc.gnu.org>; Fri, 26 May 2023 19:43:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 186BC3858C5F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=qNHMDfOU9lDDcA3uG63oWeElKH0/3odzXW9tXK5pEBM=; b=otuULvxTNSvKBuNiP0FOv8Gss1 ME5bpDz1j11pCbW71GbvobqhTnoqu7CMAXMiqBqdF9h4qB+rKF9MJo5M8Ur7l3FFN1aSvL7daV4uv trsVO9LIRtTTz9N7U7d10j7XDBDMSqBZ5du1SrbJVdeNdL4nlBUp9SK1jDgd0uvknwk91dWO8/TPv tsGjeKzYdy0Qg+GqTlQVlyXQRYabTMUEzraBochVU89VrBnzP1fWvq9cGEaJz5RyCBlyXNQ6RJbl8 PNBlAt4KG/tCOw5kz6dvnTeLNJZl7nKzzMIN6hVq95yXgaM6hSgDi2zN31KpU5FaQFbNYvxVh7Uhp W80Z9lKQ==; Received: from host86-169-41-81.range86-169.btcentralplus.com ([86.169.41.81]:51065 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from <roger@nextmovesoftware.com>) id 1q2dLv-0002bX-1T for gcc-patches@gcc.gnu.org; Fri, 26 May 2023 15:43:55 -0400 From: "Roger Sayle" <roger@nextmovesoftware.com> To: <gcc-patches@gcc.gnu.org> Subject: [PATCH] PR target/107172: Avoid "unusual" MODE_CC comparisons in simplify-rtx.cc Date: Fri, 26 May 2023 20:43:54 +0100 Message-ID: <024501d9900a$682ef1c0$388cd540$@nextmovesoftware.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0246_01D99012.C9F359C0" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdmQCXTGI3wgzw+qTSWrR3ZIO/xPpw== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766987160578805308?= X-GMAIL-MSGID: =?utf-8?q?1766987160578805308?= |
Series |
PR target/107172: Avoid "unusual" MODE_CC comparisons in simplify-rtx.cc
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Roger Sayle
May 26, 2023, 7:43 p.m. UTC
I believe that a better (or supplementary) fix to PR target/107172 is to avoid producing incorrect (but valid) RTL in simplify_const_relational_operation when presented with questionable (obviously invalid) expressions, such as those produced during combine. Just as with the "first do no harm" clause with the Hippocratic Oath, simplify-rtx (probably) shouldn't unintentionally transform invalid RTL expressions, into incorrect (non-equivalent) but valid RTL that may be inappropriately recognized by recog. In this specific case, many GCC backends represent their flags register via MODE_CC, whose representation is intentionally "opaque" to the middle-end. The only use of MODE_CC comprehensible to the middle-end's RTL optimizers is relational comparisons between the result of a COMPARE rtx (op0) and zero (op1). Any other uses of MODE_CC should be left alone, and some might argue indicate representational issues in the backend. In practice, CPUs occasionally have numerous instructions that affect the flags register(s) other than comparisons [AVR's setc, powerpc's mtcrf, x86's clc, stc and cmc and x86_64's ptest that sets C and Z flags in non-obvious ways, c.f. PR target/109973]. Currently care has to be taken, wrapping these in UNSPEC, to avoid combine inappropriately merging flags setters with flags consumers (such as conditional jumps). It's safer to teach simplify_const_relational_operation not to modify expressions that it doesn't understand/recognize. This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check, both with and without --target_board=unix{-m32} with no new failures. Ok for mainline? 2023-05-26 Roger Sayle <roger@nextmovesoftware.com> gcc/ChangeLog * simplify-rtx.cc (simplify_const_relational_operation): Return early if we have a MODE_CC comparison that isn't a COMPARE against const0_rtx. Thanks in advance, Roger --
Comments
On 5/26/23 13:43, Roger Sayle wrote: > > I believe that a better (or supplementary) fix to PR target/107172 is to > avoid > producing incorrect (but valid) RTL in simplify_const_relational_operation > when > presented with questionable (obviously invalid) expressions, such as those > produced during combine. Just as with the "first do no harm" clause with > the > Hippocratic Oath, simplify-rtx (probably) shouldn't unintentionally > transform > invalid RTL expressions, into incorrect (non-equivalent) but valid RTL that > may be inappropriately recognized by recog. > > In this specific case, many GCC backends represent their flags register via > MODE_CC, whose representation is intentionally "opaque" to the middle-end. > The only use of MODE_CC comprehensible to the middle-end's RTL optimizers > is relational comparisons between the result of a COMPARE rtx (op0) and zero > (op1). Any other uses of MODE_CC should be left alone, and some might argue > indicate representational issues in the backend. > > In practice, CPUs occasionally have numerous instructions that affect the > flags register(s) other than comparisons [AVR's setc, powerpc's mtcrf, > x86's clc, stc and cmc and x86_64's ptest that sets C and Z flags in > non-obvious ways, c.f. PR target/109973]. Currently care has to be taken, > wrapping these in UNSPEC, to avoid combine inappropriately merging flags > setters with flags consumers (such as conditional jumps). It's safer to > teach simplify_const_relational_operation not to modify expressions that > it doesn't understand/recognize. > > This patch has been tested on x86_64-pc-linux-gnu with make bootstrap > and make -k check, both with and without --target_board=unix{-m32} > with no new failures. Ok for mainline? > > > 2023-05-26 Roger Sayle <roger@nextmovesoftware.com> > > gcc/ChangeLog > * simplify-rtx.cc (simplify_const_relational_operation): Return > early > if we have a MODE_CC comparison that isn't a COMPARE against > const0_rtx. OK jeff
diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc index d4aeebc..d6444b4 100644 --- a/gcc/simplify-rtx.cc +++ b/gcc/simplify-rtx.cc @@ -6120,6 +6120,12 @@ simplify_const_relational_operation (enum rtx_code code, || (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)); + /* We only handle MODE_CC comparisons that are COMPARE against zero. */ + if (GET_MODE_CLASS (mode) == MODE_CC + && (op1 != const0_rtx + || GET_CODE (op0) != COMPARE)) + return NULL_RTX; + /* If op0 is a compare, extract the comparison arguments from it. */ if (GET_CODE (op0) == COMPARE && op1 == const0_rtx) {