From patchwork Sun Sep 3 16:18:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 137429 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp661028vqo; Sun, 3 Sep 2023 09:19:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHDOefz7gPXojtZMNn2etQGygYd8xYHC+xBOCSxvPBO/Bx1r8rYWIhbdQCMKbAKv+wXVjMv X-Received: by 2002:a17:906:3057:b0:9a5:b874:93d5 with SMTP id d23-20020a170906305700b009a5b87493d5mr5458198ejd.76.1693757962373; Sun, 03 Sep 2023 09:19:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693757962; cv=none; d=google.com; s=arc-20160816; b=APModiDovu6gBxCxWqAugyYb+XpD9Xz2FvlU9Zxhj8mHicYL5GCjYnX70Bv/qO7kA2 B/fFhyzdx5nlMt6o5+dxARhVrqJt16MZURNEoWjvwLnAMle6+9YSbEKDWxoIqZFDpxhP Qrx5NR9fpsD+5AiLDY6s8jJ0ZlmzgFCniNvnoCGW1uDn13OO1QXi50kHbhrqxFmJuTyF v+k56+LR75Tvnd0IyBF/RtQxfM9CVJLnRrIWmEN/tA/Ey8Ap9QbgFi8CsNPIms/Z8k3W hFmlxI7LUZJA5APTyJeQOE61kt/GGVAyFTPmidKBv6257DfQ9hfWSe/ZrcirY1+GB/NP e0VQ== 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:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=6mfVHBWlE37d6S0Tgy7kna+rR/ffzjnz4/WmTZKWlrw=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=Q/ktjM6bsk3KESIpk/Y3wrQxmxJnF6Og5lunpmEj/CBDwo9w0mc1dULjCDNLD8SGEB m5aU79cf0lPoEoFf7vGb05+e8feoseBTVyUw2TKdGhugorVFfRpNePZ2IHutobkwVKF8 LICQqyOqnOknmhyspfWJm1eNUy/76TG9XptL3uCzUhok1Qk0MJ9Q2hJaWSZ/rpp7KBec 0fRwwr1hmtRQVR+xPCbJ8Gplj7pZkWf/9C8Gh+IC5nMInGqRiu8YaigmBf/LwwF7DwfA SisrE+LMsUnPG+fGjL49t7bfuhWy6EEOXRVHs2BkkCLmpUwtgY4dREYHCbyfXtbSA71x aVtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ES5HQGJH; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 h14-20020a17090634ce00b0099ca6e1b1f1si5009081ejb.1055.2023.09.03.09.19.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Sep 2023 09:19:22 -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=@gcc.gnu.org header.s=default header.b=ES5HQGJH; 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"; 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 1D4EF38582A3 for ; Sun, 3 Sep 2023 16:19:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D4EF38582A3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693757961; bh=6mfVHBWlE37d6S0Tgy7kna+rR/ffzjnz4/WmTZKWlrw=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=ES5HQGJHk9n5FVdA7nIjPXxbmOo7xzyBImwV9tpahoq/4FXW2Kcfk28LylycPS29U 33LL228Vhc14AfnnuurPXIpryIAQCuRsf7A3W9MQuHUMImyTZOc4mseX9MAPrG8Wro 3DJsWXM9cmeMG8fz6mi4SDKrp6YhthI43p3saTuk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 85A403858D33 for ; Sun, 3 Sep 2023 16:18:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 85A403858D33 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 383GHbIL025320 for ; Sun, 3 Sep 2023 09:18:35 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3sv2dp32qr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 03 Sep 2023 09:18:35 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sun, 3 Sep 2023 09:18:33 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Sun, 3 Sep 2023 09:18:33 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 1080C3F7070; Sun, 3 Sep 2023 09:18:32 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] Improve rewrite_to_defined_overflow for lhs already the correct type Date: Sun, 3 Sep 2023 09:18:19 -0700 Message-ID: <20230903161819.907375-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: c8tscsBzFeaO1ENZM2-Jq14N-nudxXVz X-Proofpoint-GUID: c8tscsBzFeaO1ENZM2-Jq14N-nudxXVz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-03_13,2023-08-31_01,2023-05-22_02 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776033949096054656 X-GMAIL-MSGID: 1776033949096054656 This improves rewrite_to_defined_overflow slightly if we already have an unsigned type. The only place where this seems to show up is ifcombine. It removes one extra statement which gets added and then later on removed. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: PR tree-optimization/111276 * gimple-fold.cc (rewrite_to_defined_overflow): Don't add a new lhs if we already the unsigned type. --- gcc/gimple-fold.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index fd01810581a..2fcafeada37 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -8721,10 +8721,19 @@ rewrite_to_defined_overflow (gimple *stmt, bool in_place /* = false */) op = gimple_convert (&stmts, type, op); gimple_set_op (stmt, i, op); } - gimple_assign_set_lhs (stmt, make_ssa_name (type, stmt)); + bool needs_cast_back = false; + if (!useless_type_conversion_p (type, TREE_TYPE (lhs))) + { + gimple_assign_set_lhs (stmt, make_ssa_name (type, stmt)); + needs_cast_back = true; + } + if (gimple_assign_rhs_code (stmt) == POINTER_PLUS_EXPR) gimple_assign_set_rhs_code (stmt, PLUS_EXPR); - gimple_set_modified (stmt, true); + + if (needs_cast_back || stmts) + gimple_set_modified (stmt, true); + if (in_place) { gimple_stmt_iterator gsi = gsi_for_stmt (stmt); @@ -8734,6 +8743,10 @@ rewrite_to_defined_overflow (gimple *stmt, bool in_place /* = false */) } else gimple_seq_add_stmt (&stmts, stmt); + + if (!needs_cast_back) + return stmts; + gimple *cvt = gimple_build_assign (lhs, NOP_EXPR, gimple_assign_lhs (stmt)); if (in_place) {