From patchwork Mon Sep 30 08:04:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artemiy Volkov X-Patchwork-Id: 1990776 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.a=rsa-sha256 header.s=pfptdkimsnps header.b=iD+Ukbhy; dkim=pass (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.a=rsa-sha256 header.s=mail header.b=gEVWzxX4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHDDD57FMz1xsq for ; Mon, 30 Sep 2024 18:06:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8AD3A3851C05 for ; Mon, 30 Sep 2024 08:06:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by sourceware.org (Postfix) with ESMTPS id E2BEF385EC0B for ; Mon, 30 Sep 2024 08:04:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E2BEF385EC0B Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=synopsys.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=synopsys.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E2BEF385EC0B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727683484; cv=none; b=vrtrchN6TmnmrxQpXMy7qVUWTzBqYsNha8Bfo34WxgVnD3aZzy5zZtCMqtidzv5/tCoQUuhweHhw7AzhzMyXQ68FdFV+Z2cyg4QuTnuIs3cjjXzoNKkUb7StckQTsCfLQwxGCOulxh2lF3A1296UpgBNtJ8DF95PcYevRJH22AI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727683484; c=relaxed/simple; bh=YbNHqy46Qp5bR05FzaFK4MzrJXux0x88+/UgsNUPsic=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=Yq8OeAPrAaCEmSP9vnn8frrZbm0Wu2B8on//T11IHSYcufW6DasueaoJB7uHu/7CHDiCVGlYgGsIMpNHxllNS+lKTO0LmI02dykotOWQKwYcm35egErocNYDhb5uB11SAdsaD5yvp0UdS7fiR9VrJgBgUfwSS0/e2Qm74VVA5hc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0297266.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48U5qjTK024194; Mon, 30 Sep 2024 01:04:40 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pfptdkimsnps; bh=Tjf6DAgx /w6g3xXAwIokU6RJtoMbIvaNIGexE/9DR6k=; b=iD+UkbhygKGya2w14T4uIupr 5L2Jdpbu+TorKyN7duXZzq6DOVggBX8+bx5IuPZad3Ske/OC3cFO5KiIZZ+kYCSq raTbUJvW/Y/2TAM02d/t8tx4NiL8a0/Iza2lt2qamBaqOjZTQ8OMccKS1yjd1/oW UWJBlqDpZ7I13AenDH7FqRhcVdKuEGLrjc72pAjuMVG7avC7t/23gN0O1LTDxnTd EvA8HuACRGbE/Ly/vAKdsJJXFYEUtPtezXWrBqojPzglERIKlfr0iKBrohc/q7si ZRvIS0IngNb6bva7T6LembF7JcaCIbo9PoscdyegbltVEk0T1vGg1RIe6sXmNA== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 41ybr32p2j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 Sep 2024 01:04:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1727683478; bh=YbNHqy46Qp5bR05FzaFK4MzrJXux0x88+/UgsNUPsic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gEVWzxX43zpcJODwhiAazRQa6ZTsBI5YoVAOEzdq45koi7tTb2l4i6K4a650OhlHe PU3TdEUqkXBlo5azDmkYgKwPfAh8mw6PjS+YJnH/KVCfPhUoKYbSR/YRiXPUSbXa4I WZezDkzOjFU1jKlt21ubG3tZwazF6ojsPyqku23WD6Y5w++cMAkW2m6jfDBYv52Mzo BIguIQyAHMtepeeWyM/RLdPPmLnq5KjH2yGwYYOI6aPi3bPedmR047Tf2mFVA6FDto rWuQrpb4kBPaRi9Uun+/lDzd9uVeolCfWUrger0QPCsBrkT6sMMASA0voNBiPzEWo0 MPdbG/kOUzh9w== Received: from mailhost.synopsys.com (badc-mailhost1.synopsys.com [10.192.0.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) client-signature RSA-PSS (2048 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 71DA140349; Mon, 30 Sep 2024 08:04:38 +0000 (UTC) Received: from us01arcgnu3.internal.synopsys.com (us01arcgnu3.internal.synopsys.com [10.194.34.166]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id C6B41A00AE; Mon, 30 Sep 2024 08:04:37 +0000 (UTC) X-SNPS-Relay: synopsys.com From: Artemiy Volkov To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, jeffreyalaw@gmail.com, quic_apinski@quicinc.com, Artemiy Volkov Subject: [PATCH v4 1/4] tree-optimization/116024 - simplify C1-X cmp C2 for UB-on-overflow types Date: Mon, 30 Sep 2024 01:04:05 -0700 Message-ID: <20240930080408.2501963-2-artemiy@synopsys.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240930080408.2501963-1-artemiy@synopsys.com> References: <20240930080408.2501963-1-artemiy@synopsys.com> MIME-Version: 1.0 X-Authority-Analysis: v=2.4 cv=NpODcNdJ c=1 sm=1 tr=0 ts=66fa5b97 cx=c_pps a=t4gDRyhI9k+KZ5gXRQysFQ==:117 a=t4gDRyhI9k+KZ5gXRQysFQ==:17 a=EaEq8P2WXUwA:10 a=qPHU084jO2kA:10 a=jIQo8A4GAAAA:8 a=bXNIPKydyp0ayI4OiMwA:9 a=Lf5xNeLK5dgiOs8hzIjU:22 X-Proofpoint-ORIG-GUID: uTTO9FPQONfnxQp5SbIC274V6r-OwvIu X-Proofpoint-GUID: uTTO9FPQONfnxQp5SbIC274V6r-OwvIu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 phishscore=0 spamscore=0 mlxscore=0 clxscore=1015 adultscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 impostorscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409300057 X-Spam-Status: No, score=-11.5 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_NONE, 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: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Implement a match.pd pattern for C1 - X cmp C2, where C1 and C2 are integer constants and X is of a UB-on-overflow type. The pattern is simplified to X rcmp C1 - C2 by moving X and C2 to the other side of the comparison (with opposite signs). If C1 - C2 happens to overflow, replace the whole expression with either a constant 0 or a constant 1 node, depending on the comparison operator and the sign of the overflow. This transformation allows to occasionally save load-immediate / subtraction instructions, e.g. the following statement: 10 - (int) x <= 9; now compiles to sgt a0,a0,zero instead of li a5,10 sub a0,a5,a0 slti a0,a0,10 on 32-bit RISC-V. Additional examples can be found in the newly added test file. This patch has been bootstrapped and regtested on aarch64, x86_64, and i386, and additionally regtested on riscv32. Existing tests were adjusted where necessary. gcc/ChangeLog: PR tree-optimization/116024 * match.pd: New transformation around integer comparison. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr116024.c: New test. * gcc.dg/pr67089-6.c: Adjust. Signed-off-by: Artemiy Volkov --- gcc/match.pd | 26 ++++++++++ gcc/testsuite/gcc.dg/pr67089-6.c | 4 +- gcc/testsuite/gcc.dg/tree-ssa/pr116024.c | 66 ++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr116024.c diff --git a/gcc/match.pd b/gcc/match.pd index e06a812e976..b074f49eebd 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -8996,6 +8996,32 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) } (cmp @0 { res; }))))))))) +/* Invert sign of X in comparisons of the form C1 - X CMP C2. */ + +(for cmp (lt le gt ge eq ne) + rcmp (gt ge lt le eq ne) + (simplify + (cmp (minus INTEGER_CST@0 @1) INTEGER_CST@2) +/* For UB-on-overflow types, simply switch sides for X and C2 + to arrive at X RCMP C1 - C2, handling the case when the latter + expression overflows. */ + (if (!TREE_OVERFLOW (@0) && !TREE_OVERFLOW (@2) + && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@1))) + (with { tree res = int_const_binop (MINUS_EXPR, @0, @2); } + (if (TREE_OVERFLOW (res)) + (switch + (if (cmp == NE_EXPR) + { constant_boolean_node (true, type); }) + (if (cmp == EQ_EXPR) + { constant_boolean_node (false, type); }) + { + bool less = cmp == LE_EXPR || cmp == LT_EXPR; + bool ovf_high = wi::lt_p (wi::to_wide (@0), 0, + TYPE_SIGN (TREE_TYPE (@0))); + constant_boolean_node (less == ovf_high, type); + }) + (rcmp @1 { res; })))))) + /* Canonicalizations of BIT_FIELD_REFs. */ (simplify diff --git a/gcc/testsuite/gcc.dg/pr67089-6.c b/gcc/testsuite/gcc.dg/pr67089-6.c index b59d75b2318..80a33c3f3e2 100644 --- a/gcc/testsuite/gcc.dg/pr67089-6.c +++ b/gcc/testsuite/gcc.dg/pr67089-6.c @@ -57,5 +57,5 @@ T (25, unsigned short, 2U - x, if (r > 2U) foo (0)) T (26, unsigned char, 2U - x, if (r <= 2U) foo (0)) /* { dg-final { scan-tree-dump-times "ADD_OVERFLOW" 16 "widening_mul" { target { i?86-*-* x86_64-*-* } } } } */ -/* { dg-final { scan-tree-dump-times "SUB_OVERFLOW" 11 "widening_mul" { target { { i?86-*-* x86_64-*-* } && { ! ia32 } } } } } */ -/* { dg-final { scan-tree-dump-times "SUB_OVERFLOW" 9 "widening_mul" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ +/* { dg-final { scan-tree-dump-times "SUB_OVERFLOW" 9 "widening_mul" { target { { i?86-*-* x86_64-*-* } && { ! ia32 } } } } } */ +/* { dg-final { scan-tree-dump-times "SUB_OVERFLOW" 7 "widening_mul" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr116024.c b/gcc/testsuite/gcc.dg/tree-ssa/pr116024.c new file mode 100644 index 00000000000..6efa0c2f916 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr116024.c @@ -0,0 +1,66 @@ +/* PR tree-optimization/116024 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop1-details" } */ + +#include +#include + +uint32_t f(void); + +int32_t i1(void) +{ + int32_t l = 10 - (int32_t)f(); + return l <= 9; // f() > 0 +} + +int32_t i1a(void) +{ + int32_t l = 20 - (int32_t)f(); + return l <= INT32_MIN; // return 0 +} + +int32_t i1b(void) +{ + int32_t l = 30 - (int32_t)f(); + return l <= INT32_MIN + 31; // f() == INT32_MAX +} + +int32_t i1c(void) +{ + int32_t l = INT32_MAX - 40 - (int32_t)f(); + return l <= -38; // f() > INT32_MAX - 3 +} + +int32_t i1d(void) +{ + int32_t l = INT32_MAX - 50 - (int32_t)f(); + return l <= INT32_MAX - 1; // f() != -50 +} + +int32_t i1e(void) +{ + int32_t l = INT32_MAX - 60 - (int32_t)f(); + return l != INT32_MAX - 90; // f() != 30 +} + +int32_t i1f(void) +{ + int32_t l = INT32_MIN + 70 - (int32_t)f(); + return l <= INT32_MAX - 2; // return 0 +} + +int32_t i1g(void) +{ + int32_t l = INT32_MAX/2 + 30 - (int32_t)f(); + return l <= INT32_MIN/2 - 30; // return 1 +} + + +/* { dg-final { scan-tree-dump-times "Removing dead stmt:.*?- _" 5 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "return 0" 2 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "return 1" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* > 0" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* == 2147483647" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* > 2147483644" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* != 4294967246" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* != 30" 1 "forwprop1" } } */ From patchwork Mon Sep 30 08:04:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artemiy Volkov X-Patchwork-Id: 1990773 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.a=rsa-sha256 header.s=pfptdkimsnps header.b=WQ7YE93o; dkim=pass (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.a=rsa-sha256 header.s=mail header.b=S+E8Fthb; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHDBz50nPz1xsq for ; Mon, 30 Sep 2024 18:05:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 89B773860762 for ; Mon, 30 Sep 2024 08:05:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by sourceware.org (Postfix) with ESMTPS id 36301385EC15 for ; Mon, 30 Sep 2024 08:04:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 36301385EC15 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=synopsys.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=synopsys.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 36301385EC15 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727683484; cv=none; b=cAu1DrTMU1ISep01MtR7V0lCM1qn51jJdiV5/1jHIkYVF4Zjqz5YQzEFEsonc2Y9KrkgoIAhJD/6yLStnfjm7mdpGH1y6neezWflneft5ViosvlmaMyBUTsSVq81CV9VwFviClGtlsHYzoILxY0mtg4QG1pAwO0k/qlD/ER8Mp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727683484; c=relaxed/simple; bh=QojDTvvH+hrijZ5qqqKt7ob8tfrMMi2ZRG96S/SYkSw=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=TzQ244xFj4LC7rlJhjopuwy2DP08aYRojdNS5p4J5kb2isOVOTgBVPmxI8YlbuFQD6bmiHmc5B0GqJPxw3UAqLebzMKINCvo2LyYL70jeHVXo/uYPTjejAXlF8Kgczx7UYp1ZzF2MZ/HVzDnzyu8r0jAScnIHWPXteFXR+UiODs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0098571.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48U61iUZ008337; Mon, 30 Sep 2024 01:04:40 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pfptdkimsnps; bh=x9mSFxr6 moAK0Qv+9eN+difOXApF3CI8rRPbLuFXzkk=; b=WQ7YE93ojivbZDjEJQBEfOxn j8F8cyGj5S+T11OVRS3MDKu8eInFOgUpFFoazXjH7yi9/Vk/HOHFF/5j8Y4nBqC3 onmDyajGqd1fL1qZNWj4tQol9SKibzG+sVaDF8ZWJ8llTYGNvIXP3Ru4+ZL4gVcC a/w3z4zZhZpgCEZT5JpY4PbvGEoTARt6rFrYE1gQ1Z0z9uwmslQP53cGp9W7P3rj yYaCkqKJeZMzAXU5/xkqSGhQJawMLD+WLSI+7LMS6VN4kkRmdxgLq0HIUWYYT5l8 UeqtdDjntESFaZ2r3FV+zB69Jj5A4bBJ1nRv44/0UXbabgMl0izBCGUSzlJ7pQ== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 41xgtn7d2p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 Sep 2024 01:04:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1727683479; bh=QojDTvvH+hrijZ5qqqKt7ob8tfrMMi2ZRG96S/SYkSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S+E8FthbhzD1yzg26fawOyqOiMLLCSYkUZ42YoGAZ4QT73vow6HJGkIMLTwunQOR+ z/ylJ/zQnSYsl8IJFuTV6B1PxmCoS6hzvXkfbvcHRA7auUa1kMEVQawnplGvqwCq55 bv/GF6uDgkzJACsnQgetIgW2vwVSJHZBqgxdUKlc9BAFoFRY9PFuJH0+QYWdzRUb8a oYgPtwn3pfpy6KVPpfx/F1GUt0RRZzmhAFK8G0YD3FRO9KXOkhNz8NeIyP+DLNB8rb h6QWwKdBiRuC7knelsvUPbcaRD2gTJ0H5BJq2KKXOVLvAW4OEIkRLq+5vFyg9MYtN4 DZaFk3zSzSslA== Received: from mailhost.synopsys.com (badc-mailhost1.synopsys.com [10.192.0.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) client-signature RSA-PSS (2048 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 2FF594048F; Mon, 30 Sep 2024 08:04:39 +0000 (UTC) Received: from us01arcgnu3.internal.synopsys.com (us01arcgnu3.internal.synopsys.com [10.194.34.166]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id F115AA00B0; Mon, 30 Sep 2024 08:04:38 +0000 (UTC) X-SNPS-Relay: synopsys.com From: Artemiy Volkov To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, jeffreyalaw@gmail.com, quic_apinski@quicinc.com, Artemiy Volkov Subject: [PATCH v4 2/4] tree-optimization/116024 - simplify C1-X cmp C2 for unsigned types Date: Mon, 30 Sep 2024 01:04:06 -0700 Message-ID: <20240930080408.2501963-3-artemiy@synopsys.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240930080408.2501963-1-artemiy@synopsys.com> References: <20240930080408.2501963-1-artemiy@synopsys.com> MIME-Version: 1.0 X-Proofpoint-GUID: ndaYf2CO8woZLrM3a8JnI6WNRrDBsbnx X-Proofpoint-ORIG-GUID: ndaYf2CO8woZLrM3a8JnI6WNRrDBsbnx X-Authority-Analysis: v=2.4 cv=faX/yFQF c=1 sm=1 tr=0 ts=66fa5b98 cx=c_pps a=t4gDRyhI9k+KZ5gXRQysFQ==:117 a=t4gDRyhI9k+KZ5gXRQysFQ==:17 a=EaEq8P2WXUwA:10 a=qPHU084jO2kA:10 a=jIQo8A4GAAAA:8 a=rGqp4SXJTxKLiM_M_kEA:9 a=Lf5xNeLK5dgiOs8hzIjU:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 bulkscore=0 clxscore=1015 suspectscore=0 adultscore=0 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 priorityscore=1501 mlxlogscore=999 malwarescore=0 mlxscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409300057 X-Spam-Status: No, score=-11.5 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_NONE, 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: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Implement a match.pd transformation inverting the sign of X in C1 - X cmp C2, where C1 and C2 are integer constants and X is of an unsigned type, by observing that: (a) If cmp is == or !=, simply move X and C2 to opposite sides of the comparison to arrive at X cmp C1 - C2. (b) If cmp is <: - C1 - X < C2 means that C1 - X spans the range of 0, 1, ..., C2 - 1; - This means that X spans the range of C1 - (C2 - 1), C1 - (C2 - 2), ..., C1; - Subtracting C1 - (C2 - 1), X - (C1 - (C2 - 1)) is one of 0, 1, ..., C1 - (C1 - (C2 - 1)); - Simplifying the above, X - (C1 - C2 + 1) is one of 0, 1, ..., C2 - 1; - Summarizing, the expression C1 - X < C2 can be transformed into X - (C1 - C2 + 1) < C2. (c) Similarly, if cmp is <=: - C1 - X <= C2 means that C1 - X is one of 0, 1, ..., C2; - It follows that X is one of C1 - C2, C1 - (C2 - 1), ..., C1; - Subtracting C1 - C2, X - (C1 - C2) has range 0, 1, ..., C2; - Thus, the expression C1 - X <= C2 can be transformed into X - (C1 - C2) <= C2. (d) The >= and > cases are negations of (b) and (c), respectively. This transformation allows to occasionally save load-immediate / subtraction instructions, e.g. the following statement: 300 - (unsigned int)f() < 100; now compiles to addi a0,a0,-201 sltiu a0,a0,100 instead of li a5,300 sub a0,a5,a0 sltiu a0,a0,100 on 32-bit RISC-V. Additional examples can be found in the newly added test file. This patch has been bootstrapped and regtested on aarch64, x86_64, and i386, and additionally regtested on riscv32. gcc/ChangeLog: PR tree-optimization/116024 * match.pd: New transformation around integer comparison. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr116024-1.c: New test. Signed-off-by: Artemiy Volkov --- gcc/match.pd | 23 +++++++- gcc/testsuite/gcc.dg/tree-ssa/pr116024-1.c | 65 ++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr116024-1.c diff --git a/gcc/match.pd b/gcc/match.pd index b074f49eebd..46195a603d0 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -9020,7 +9020,28 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) TYPE_SIGN (TREE_TYPE (@0))); constant_boolean_node (less == ovf_high, type); }) - (rcmp @1 { res; })))))) + (rcmp @1 { res; }))) +/* For unsigned types, transform like so (using < as example): + C1 - X < C2 + ==> C1 - X = { 0, 1, ..., C2 - 1 } + ==> X = { C1 - (C2 - 1), ..., C1 + 1, C1 } + ==> X - (C1 - (C2 - 1)) = { 0, 1, ..., C1 - (C1 - (C2 - 1)) } + ==> X - (C1 - C2 + 1) = { 0, 1, ..., C2 - 1 } + ==> X - (C1 - C2 + 1) < C2. + + Similarly, + C1 - X <= C2 ==> X - (C1 - C2) <= C2; + C1 - X >= C2 ==> X - (C1 - C2 + 1) >= C2; + C1 - X > C2 ==> X - (C1 - C2) > C2. */ + (if (TYPE_UNSIGNED (TREE_TYPE (@1))) + (switch + (if (cmp == EQ_EXPR || cmp == NE_EXPR) + (cmp @1 (minus @0 @2))) + (if (cmp == LE_EXPR || cmp == GT_EXPR) + (cmp (plus @1 (minus @2 @0)) @2)) + (if (cmp == LT_EXPR || cmp == GE_EXPR) + (cmp (plus @1 (minus @2 + (plus @0 { build_one_cst (TREE_TYPE (@1)); }))) @2))))))) /* Canonicalizations of BIT_FIELD_REFs. */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1.c new file mode 100644 index 00000000000..91cb6a7c4f1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1.c @@ -0,0 +1,65 @@ +/* PR tree-optimization/116024 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop1-details" } */ + +#include + +uint32_t f(void); + +int32_t i2(void) +{ + uint32_t l = 10 - (uint32_t)f(); + return l <= 20; // f() + 10 <= 20 +} + +int32_t i2a(void) +{ + uint32_t l = 10 - (uint32_t)f(); + return l < 30; // f() + 19 < 30 +} + +int32_t i2b(void) +{ + uint32_t l = 200 - (uint32_t)f(); + return l <= 100; // f() - 100 <= 100 +} + +int32_t i2c(void) +{ + uint32_t l = 300 - (uint32_t)f(); + return l < 100; // f() - 201 < 100 +} + +int32_t i2d(void) +{ + uint32_t l = 1000 - (uint32_t)f(); + return l >= 2000; // f() + 999 >= 2000 +} + +int32_t i2e(void) +{ + uint32_t l = 1000 - (uint32_t)f(); + return l > 3000; // f() + 2000 > 3000 +} + +int32_t i2f(void) +{ + uint32_t l = 20000 - (uint32_t)f(); + return l >= 10000; // f() - 10001 >= 10000 +} + +int32_t i2g(void) +{ + uint32_t l = 30000 - (uint32_t)f(); + return l > 10000; // f() - 20000 > 10000 +} + +/* { dg-final { scan-tree-dump-times "Removing dead stmt:.*?- _" 8 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ 10.*\n.*<= 20" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ 19.*\n.*<= 29" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ 4294967196.*\n.*<= 100" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ 4294967095.*\n.*<= 99" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ 999.*\n.*> 1999" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ 2000.*\n.*> 3000" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ 4294957295.*\n.*> 9999" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ 4294947296.*\n.*> 10000" 1 "forwprop1" } } */ From patchwork Mon Sep 30 08:04:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artemiy Volkov X-Patchwork-Id: 1990777 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.a=rsa-sha256 header.s=pfptdkimsnps header.b=sbpzjhCN; dkim=pass (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.a=rsa-sha256 header.s=mail header.b=CmJq0gnF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHDDK6hgDz1xsq for ; Mon, 30 Sep 2024 18:06:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 204EE3860008 for ; Mon, 30 Sep 2024 08:06:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by sourceware.org (Postfix) with ESMTPS id 419D5385EC17 for ; Mon, 30 Sep 2024 08:04:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 419D5385EC17 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=synopsys.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=synopsys.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 419D5385EC17 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727683484; cv=none; b=hIYkQcZkEU6Q3jX4QTw2ESnUa6MWZX/bSVgOg7IWD59IDaj9KwgO4P8VuWgxbVM2+oW1cdeS5RoNxQTDN3f91SFZfoDNTqeCmMzJnHaWbp35ayqEi16yx6DfHqQwSnfWe8n3OudEWL41DBguZAaaYXt95QXkGsmzX9WAcXHxliQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727683484; c=relaxed/simple; bh=KaSL0/S6MgFnUukKwkC0Wf+22ZPH+P9wra85mnlAb4c=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=Y2a38AJ888q25TXyIeIkpxgLs84e+fA6enTmZ4QgOExf4q5SKE/0F6P6VIvZndCZBZWAi0pLW+hax1UsymcxukPcp20J6AHt6BhVAMddd5UN3o4TN1C/k0u9z2qdIMbNNxLAjFO0/cSme/atLVa2LWnwMhfnN1kvvruRkTzazmE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0098571.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48U61iUb008337; Mon, 30 Sep 2024 01:04:41 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pfptdkimsnps; bh=q9hSVx2A Feuc+190k3EpgxUzm1TVqWJvwFCTzNdyRhM=; b=sbpzjhCNpCA79Lz4ZnpxSsvA E3HCddaOQ4uQbRghyl3GmvKdTeb2+kMp6VDoEJ73SNcEUaYtdGStNKXCnm9rLCNW CF+qZy9bK3IpMIHtBoHdGF2Aoa3h2FtrYz9cpJs17Cc/MNdWNXISw+gqF9ZFleYJ cddbUsaPKXL6aikJUMXy/Kr6cfFj/CQ/Olh86d7DIIQ9Z6kjIiTf3M/F6NzXmd7z VY5+VFWvmToRXFjpzQVpQKX7r6IqMjroS4mi/Ehv9pbWwj3E9FT+an19YIgv/OvH HqD5Uu8BlwbJFFpt2VNXnrkG1Um39XWe7oEtVRNJaAVxeIGUd40JHQ6eUzNX7g== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 41xgtn7d2u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 Sep 2024 01:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1727683480; bh=KaSL0/S6MgFnUukKwkC0Wf+22ZPH+P9wra85mnlAb4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CmJq0gnFuqrFjA93tbAHcPNqOt65U3TCKtD1c0ZUMsqxmTVw7PUdgfqbBJtbAYH1s 8TAh/90vEPNR3K1Ga7jcMvptoJ1TVv80cJudsYKHQtCG5n/2RGuJ+Uvywzkuh2y2ho mbzHNgdBSkoM5bpZYuHhP9YsFm8wmojRbBVl32ZjSEQ9fcC5BfYl7dyInArYch7F3d h4wFxwHizZpLDP208rPlfwGXgxLWT3mvp5V2UOGhqTu7ensSbJvtHuuuWM1BWvOgDY 1gZSvtWgm29noDhxagTCswzJ6S37KQ1OEN3loOgoO+CAYk3lI7iGkUKDRTpYsCbXY2 IuCay5q/5wPlw== Received: from mailhost.synopsys.com (badc-mailhost1.synopsys.com [10.192.0.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) client-signature RSA-PSS (2048 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 78C0940561; Mon, 30 Sep 2024 08:04:40 +0000 (UTC) Received: from us01arcgnu3.internal.synopsys.com (us01arcgnu3.internal.synopsys.com [10.194.34.166]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id 19EAAA0071; Mon, 30 Sep 2024 08:04:40 +0000 (UTC) X-SNPS-Relay: synopsys.com From: Artemiy Volkov To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, jeffreyalaw@gmail.com, quic_apinski@quicinc.com, Artemiy Volkov Subject: [PATCH v4 3/4] tree-optimization/116024 - simplify C1-X cmp C2 for wrapping signed types Date: Mon, 30 Sep 2024 01:04:07 -0700 Message-ID: <20240930080408.2501963-4-artemiy@synopsys.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240930080408.2501963-1-artemiy@synopsys.com> References: <20240930080408.2501963-1-artemiy@synopsys.com> MIME-Version: 1.0 X-Proofpoint-GUID: 7SVwygWb3viZcFseWrGW9FsbzS_4zBB_ X-Proofpoint-ORIG-GUID: 7SVwygWb3viZcFseWrGW9FsbzS_4zBB_ X-Authority-Analysis: v=2.4 cv=faX/yFQF c=1 sm=1 tr=0 ts=66fa5b99 cx=c_pps a=t4gDRyhI9k+KZ5gXRQysFQ==:117 a=t4gDRyhI9k+KZ5gXRQysFQ==:17 a=EaEq8P2WXUwA:10 a=qPHU084jO2kA:10 a=jIQo8A4GAAAA:8 a=rGqp4SXJTxKLiM_M_kEA:9 a=Lf5xNeLK5dgiOs8hzIjU:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 bulkscore=0 clxscore=1015 suspectscore=0 adultscore=0 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 priorityscore=1501 mlxlogscore=999 malwarescore=0 mlxscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409300057 X-Spam-Status: No, score=-11.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_NONE, 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: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Implement a match.pd transformation inverting the sign of X in C1 - X cmp C2, where C1 and C2 are integer constants and X is of a wrapping signed type, by observing that: (a) If cmp is == or !=, simply move X and C2 to opposite sides of the comparison to arrive at X cmp C1 - C2. (b) If cmp is <: - C1 - X < C2 means that C1 - X spans the values of -INF, -INF + 1, ..., C2 - 1; - Therefore, X is one of C1 - -INF, C1 - (-INF + 1), ..., C1 - C2 + 1; - Subtracting (C1 + 1), X - (C1 + 1) is one of - (-INF) - 1, - (-INF) - 2, ..., -C2; - Using the fact that - (-INF) - 1 is +INF, derive that X - (C1 + 1) spans the values +INF, +INF - 1, ..., -C2; - Thus, the original expression can be simplified to X - (C1 + 1) > -C2 - 1. (c) Similarly, C1 - X <= C2 is equivalent to X - (C1 + 1) >= -C2 - 1. (d) The >= and > cases are negations of (b) and (c), respectively. (e) In all cases, the expression -C2 - 1 can be shortened to bit_not (C2). This transformation allows to occasionally save load-immediate / subtraction instructions, e.g. the following statement: 10 - (int)f() >= 20; now compiles to addi a0,a0,-11 slti a0,a0,-20 instead of li a5,10 sub a0,a5,a0 slti t0,a0,20 xori a0,t0,1 on 32-bit RISC-V when compiled with -fwrapv. Additional examples can be found in the newly added test file. This patch has been bootstrapped and regtested on aarch64, x86_64, and i386, and additionally regtested on riscv32. gcc/ChangeLog: PR tree-optimization/116024 * match.pd: New transformation around integer comparison. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr116024-1-fwrapv.c: New test. Signed-off-by: Artemiy Volkov --- gcc/match.pd | 21 +++++- .../gcc.dg/tree-ssa/pr116024-1-fwrapv.c | 65 +++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr116024-1-fwrapv.c diff --git a/gcc/match.pd b/gcc/match.pd index 46195a603d0..3b973887470 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -9041,7 +9041,26 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cmp (plus @1 (minus @2 @0)) @2)) (if (cmp == LT_EXPR || cmp == GE_EXPR) (cmp (plus @1 (minus @2 - (plus @0 { build_one_cst (TREE_TYPE (@1)); }))) @2))))))) + (plus @0 { build_one_cst (TREE_TYPE (@1)); }))) @2))) +/* For wrapping signed types (-fwrapv), transform like so (using < as example): + C1 - X < C2 + ==> C1 - X = { -INF, -INF + 1, ..., C2 - 1 } + ==> X = { C1 - (-INF), C1 - (-INF + 1), ..., C1 - C2 + 1 } + ==> X - (C1 + 1) = { - (-INF) - 1, - (-INF) - 2, ..., -C2 } + ==> X - (C1 + 1) = { +INF, +INF - 1, ..., -C2 } + ==> X - (C1 + 1) > -C2 - 1 + ==> X - (C1 + 1) > bit_not (C2) + + Similarly, + C1 - X <= C2 ==> X - (C1 + 1) >= bit_not (C2); + C1 - X >= C2 ==> X - (C1 + 1) <= bit_not (C2); + C1 - X > C2 ==> X - (C1 + 1) < bit_not (C2). */ + (if (!TYPE_UNSIGNED (TREE_TYPE (@1)) + && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@1))) + (if (cmp == EQ_EXPR || cmp == NE_EXPR) + (cmp @1 (minus @0 @2)) + (rcmp (minus @1 (plus @0 { build_one_cst (TREE_TYPE (@1)); })) + (bit_not @2)))))))) /* Canonicalizations of BIT_FIELD_REFs. */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1-fwrapv.c b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1-fwrapv.c new file mode 100644 index 00000000000..24e1abef774 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1-fwrapv.c @@ -0,0 +1,65 @@ +/* PR tree-optimization/116024 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop1-details -fwrapv" } */ + +#include + +uint32_t f(void); + +int32_t i2(void) +{ + int32_t l = 10 - (int32_t)f(); + return l <= 20; // f() - 11 >= -21 +} + +int32_t i2a(void) +{ + int32_t l = 10 - (int32_t)f(); + return l < 30; // f() - 11 > -31 +} + +int32_t i2b(void) +{ + int32_t l = 200 - (int32_t)f(); + return l <= 100; // f() - 201 >= -101 +} + +int32_t i2c(void) +{ + int32_t l = 300 - (int32_t)f(); + return l < 100; // f() - 301 > -101 +} + +int32_t i2d(void) +{ + int32_t l = 1000 - (int32_t)f(); + return l >= 2000; // f() - 1001 <= -2001 +} + +int32_t i2e(void) +{ + int32_t l = 1000 - (int32_t)f(); + return l > 3000; // f() - 1001 < -3001 +} + +int32_t i2f(void) +{ + int32_t l = 20000 - (int32_t)f(); + return l >= 10000; // f() - 20001 <= -10001 +} + +int32_t i2g(void) +{ + int32_t l = 30000 - (int32_t)f(); + return l > 10000; // f() - 30001 < -10001 +} + +/* { dg-final { scan-tree-dump-times "Removing dead stmt:.*?- _" 8 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ -11.*\n.*>= -21" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ -11.*\n.*>= -30" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ -201.*\n.*>= -101" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ -301.*\n.*>= -100" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ -1001.*\n.*< -2000" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ -1001.*\n.*< -3001" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ -20001.*\n.*< -10000" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ -30001.*\n.*< -10001" 1 "forwprop1" } } */ From patchwork Mon Sep 30 08:04:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artemiy Volkov X-Patchwork-Id: 1990780 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.a=rsa-sha256 header.s=pfptdkimsnps header.b=hSd4pMJi; dkim=pass (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.a=rsa-sha256 header.s=mail header.b=R4f8waKN; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHDG21H8lz1xsq for ; Mon, 30 Sep 2024 18:07:54 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 084FC385EC34 for ; Mon, 30 Sep 2024 08:07:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by sourceware.org (Postfix) with ESMTPS id E8F9B385F01C for ; Mon, 30 Sep 2024 08:04:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E8F9B385F01C Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=synopsys.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=synopsys.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E8F9B385F01C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727683487; cv=none; b=mC0hZ+t4NELgJ2ViKyUpgBIdS1sldNWT9dWYpRW8Z5sh8If7ZEJLb4SwDLyBQU9KSlOgwfkWPobCOKn8sEE1JBh/V/EMalnF93Q6XnwHrV5bFQVsTJv02uRZtUyY9NQbE+Vm+lcJrh7ueNeuJWm10S2m6VfNMUxtH2Gxidg0GC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727683487; c=relaxed/simple; bh=75oNLPo+2rfTRjGDJR+lakR79JeNEZ11ukmErWVHJ14=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=wm5jts2KsT63PG5j3lgulJ7CfzlKosqaURvIlQZuf+ZHmH9gBgXnDeyAoU6lSG0f0wMN4Nlg2cxcvug51zN0E1DSRRM0uKCuaK3wO8CVDzuQczPKdzAtz5dsbL39EBWbQzfDBLM71H5bzmDQwJMknybzMYj2z1+Xo3vT5PMN+zU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0297266.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48U69Vfu017537; Mon, 30 Sep 2024 01:04:42 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pfptdkimsnps; bh=+FUei9C+ WdGt77ij/4urriLt8AoQO3/ibBWhlhtwGPM=; b=hSd4pMJi+cqOb/5l2hwHm3TQ RgozhxPUOQYjyDBlZj808+DBLEASyqfkQHV6XWeMRE/bFxITcGOkAG/SlCbYX+Dp VCACaue0FniDjpWSO6lAuUDhxM4P4kAq24tHuxg7LwdS7G65yIVfoaR1274d8IzK HVSXY0MD1pZ10CAXS9/OjVv8cV889LDdRJXs6uCpcne/P7ZGkMdE362Uo7imDMvQ rDrfckjCGsxoMSEcuM0SKQIaJuFYgzAkusLh4R8tHbsFEv4XgoPJeMjg3PZaVkRz DatHE25JzZnWE8JQSrW5na3NUmISZTu/tO+iaNjadI1a1IzpayZ7KC+TqMXAxw== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 41ybr32p2y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 Sep 2024 01:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1727683481; bh=75oNLPo+2rfTRjGDJR+lakR79JeNEZ11ukmErWVHJ14=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R4f8waKNDDs8yghsIfxgVXd1/vF2wFsl+f3Hx386UhxeT/b2rC8mYI2C0tBn2ZozB fapMaYlcEUcV29Q4V8WIqLVJ9PoNkN8nIsYNJLzLISRmuZfouuU+VNtk0uybo3RHVI SWJ0NU4fq93wAGwbLmtlb3tH7oPmbM8Ao6mIFfiAB8wmYyBmaCqTpeC6uT762Mia4v D3elWAzCuGQnKuhvTSfOnHGZ6+vIG6DV7PDEmx9en6+GoxNJFqiZ4qWcqaCUgUJvNd QNQvYZEEVU45KOI8zEV5DXtsATxEbGfsOOKx9IbuGE+P3HFUJOvsU02vWuw9WWzQWI Ye+tyjRXZN6bQ== Received: from mailhost.synopsys.com (badc-mailhost1.synopsys.com [10.192.0.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) client-signature RSA-PSS (2048 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 2EA184048F; Mon, 30 Sep 2024 08:04:41 +0000 (UTC) Received: from us01arcgnu3.internal.synopsys.com (us01arcgnu3.internal.synopsys.com [10.194.34.166]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id D4C71A0071; Mon, 30 Sep 2024 08:04:40 +0000 (UTC) X-SNPS-Relay: synopsys.com From: Artemiy Volkov To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, jeffreyalaw@gmail.com, quic_apinski@quicinc.com, Artemiy Volkov Subject: [PATCH v4 4/4] tree-optimization/116024 - simplify some cases of X +- C1 cmp C2 Date: Mon, 30 Sep 2024 01:04:08 -0700 Message-ID: <20240930080408.2501963-5-artemiy@synopsys.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240930080408.2501963-1-artemiy@synopsys.com> References: <20240930080408.2501963-1-artemiy@synopsys.com> MIME-Version: 1.0 X-Authority-Analysis: v=2.4 cv=NpODcNdJ c=1 sm=1 tr=0 ts=66fa5b99 cx=c_pps a=t4gDRyhI9k+KZ5gXRQysFQ==:117 a=t4gDRyhI9k+KZ5gXRQysFQ==:17 a=EaEq8P2WXUwA:10 a=qPHU084jO2kA:10 a=jIQo8A4GAAAA:8 a=PRY1uSrw7YHn5vZb0VwA:9 a=Lf5xNeLK5dgiOs8hzIjU:22 X-Proofpoint-ORIG-GUID: SPjGAY0BtgkVB0ZGNIEBjneYiHVt2g5- X-Proofpoint-GUID: SPjGAY0BtgkVB0ZGNIEBjneYiHVt2g5- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 phishscore=0 spamscore=0 mlxscore=0 clxscore=1015 adultscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 impostorscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409300057 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, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, 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: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Whenever C1 and C2 are integer constants, X is of a wrapping type, and cmp is a relational operator, the expression X +- C1 cmp C2 can be simplified in the following cases: (a) If cmp is <= and C2 -+ C1 == +INF(1), we can transform the initial comparison in the following way: X +- C1 <= C2 -INF <= X +- C1 <= C2 (add left hand side which holds for any X, C1) -INF -+ C1 <= X <= C2 -+ C1 (add -+C1 to all 3 expressions) -INF -+ C1 <= X <= +INF (due to (1)) -INF -+ C1 <= X (eliminate the right hand side since it holds for any X) (b) By analogy, if cmp if >= and C2 -+ C1 == -INF(1), use the following sequence of transformations: X +- C1 >= C2 +INF >= X +- C1 >= C2 (add left hand side which holds for any X, C1) +INF -+ C1 >= X >= C2 -+ C1 (add -+C1 to all 3 expressions) +INF -+ C1 >= X >= -INF (due to (1)) +INF -+ C1 >= X (eliminate the right hand side since it holds for any X) (c) The > and < cases are negations of (a) and (b), respectively. This transformation allows to occasionally save add / sub instructions, for instance the expression 3 + (uint32_t)f() < 2 compiles to cmn w0, #4 cset w0, ls instead of add w0, w0, 3 cmp w0, 2 cset w0, ls on aarch64. Testcases that go together with this patch have been split into two separate files, one containing testcases for unsigned variables and the other for wrapping signed ones (and thus compiled with -fwrapv). Additionally, one aarch64 test has been adjusted since the patch has caused the generated code to change from cmn w0, #2 csinc w0, w1, wzr, cc (x < -2) to cmn w0, #3 csinc w0, w1, wzr, cs (x <= -3) This patch has been bootstrapped and regtested on aarch64, x86_64, and i386, and additionally regtested on riscv32. gcc/ChangeLog: PR tree-optimization/116024 * match.pd: New transformation around integer comparison. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr116024-2.c: New test. * gcc.dg/tree-ssa/pr116024-2-fwrapv.c: Ditto. * gcc.target/aarch64/gtu_to_ltu_cmp_1.c: Adjust. Signed-off-by: Artemiy Volkov --- gcc/match.pd | 43 ++++++++++++++++++- .../gcc.dg/tree-ssa/pr116024-2-fwrapv.c | 38 ++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr116024-2.c | 37 ++++++++++++++++ .../gcc.target/aarch64/gtu_to_ltu_cmp_1.c | 2 +- 4 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr116024-2-fwrapv.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr116024-2.c diff --git a/gcc/match.pd b/gcc/match.pd index 3b973887470..30e66d3dbfa 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -8967,6 +8967,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cmp @0 { TREE_OVERFLOW (res) ? drop_tree_overflow (res) : res; })))))))) (for cmp (lt le gt ge) + rcmp (gt ge lt le) (for op (plus minus) rop (minus plus) (simplify @@ -8994,7 +8995,47 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) "X cmp C2 -+ C1"), WARN_STRICT_OVERFLOW_COMPARISON); } - (cmp @0 { res; }))))))))) + (cmp @0 { res; }))))) +/* For wrapping types, simplify the following cases of X +- C1 CMP C2: + + (a) If CMP is <= and C2 -+ C1 == +INF (1), simplify to X >= -INF -+ C1 + by observing the following: + + X +- C1 <= C2 + ==> -INF <= X +- C1 <= C2 (add left hand side which holds for any X, C1) + ==> -INF -+ C1 <= X <= C2 -+ C1 (add -+C1 to all 3 expressions) + ==> -INF -+ C1 <= X <= +INF (due to (1)) + ==> -INF -+ C1 <= X (eliminate the right hand side since it holds for any X) + + (b) Similarly, if CMP is >= and C2 -+ C1 == -INF (1): + + X +- C1 >= C2 + ==> +INF >= X +- C1 >= C2 (add left hand side which holds for any X, C1) + ==> +INF -+ C1 >= X >= C2 -+ C1 (add -+C1 to all 3 expressions) + ==> +INF -+ C1 >= X >= -INF (due to (1)) + ==> +INF -+ C1 >= X (eliminate the right hand side since it holds for any X) + + (c) The > and < cases are negations of (a) and (b), respectively. */ + (if (TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0))) + (with + { + wide_int max = wi::max_value (TREE_TYPE (@0)); + wide_int min = wi::min_value (TREE_TYPE (@0)); + + wide_int c2 = rop == PLUS_EXPR + ? wi::add (wi::to_wide (@2), wi::to_wide (@1)) + : wi::sub (wi::to_wide (@2), wi::to_wide (@1)); + } + (if (((cmp == LE_EXPR || cmp == GT_EXPR) && wi::eq_p (c2, max)) + || ((cmp == LT_EXPR || cmp == GE_EXPR) && wi::eq_p (c2, min))) + (with + { + wide_int c1 = rop == PLUS_EXPR + ? wi::add (wi::bit_not (c2), wi::to_wide (@1)) + : wi::sub (wi::bit_not (c2), wi::to_wide (@1)); + tree c1_cst = wide_int_to_tree (TREE_TYPE (@0), c1); + } + (rcmp @0 { c1_cst; }))))))))) /* Invert sign of X in comparisons of the form C1 - X CMP C2. */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr116024-2-fwrapv.c b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-2-fwrapv.c new file mode 100644 index 00000000000..b9e88ba79fc --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-2-fwrapv.c @@ -0,0 +1,38 @@ +/* PR tree-optimization/116024 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop1-details -fwrapv" } */ + +#include +#include + +uint32_t f(void); + +int32_t i3(void) +{ + int32_t l = -10 + (int32_t)f(); + return l <= INT32_MAX - 10; // f() >= INT32_MIN + 10 +} + +int32_t i3a(void) +{ + int32_t l = -20 + (int32_t)f(); + return l < INT32_MAX - 19; // f() > INT32_MAX + 20 +} + +int32_t i3b(void) +{ + int32_t l = 30 + (int32_t)f(); + return l >= INT32_MIN + 30; // f() <= INT32_MAX - 30 +} + +int32_t i3c(void) +{ + int32_t l = 40 + (int32_t)f(); + return l > INT32_MIN + 39; // f() < INT32_MIN - 40 +} + +/* { dg-final { scan-tree-dump-times "Removing dead stmt:.*? \\+" 4 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* >= -2147483638" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* >= -2147483628" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* <= 2147483617" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* <= 2147483607" 1 "forwprop1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr116024-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-2.c new file mode 100644 index 00000000000..f7ff0776826 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-2.c @@ -0,0 +1,37 @@ +/* PR tree-optimization/116024 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop1-details" } */ + +#include + +uint32_t f(void); + +int32_t i3(void) +{ + uint32_t l = 10 + (uint32_t)f(); + return l <= 9; // f() >= -10u +} + +int32_t i3a(void) +{ + uint32_t l = 20 + (uint32_t)f(); + return l < 20; // f() > -21u +} + +int32_t i3b(void) +{ + uint32_t l = 30 + (uint32_t)f(); + return l >= 30; // f() <= -31u +} + +int32_t i3c(void) +{ + uint32_t l = 40 + (uint32_t)f(); + return l > 39; // f() < -39u +} + +/* { dg-final { scan-tree-dump-times "Removing dead stmt:.*? \\+" 4 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* > 4294967285" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* > 4294967275" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* <= 4294967265" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* <= 4294967255" 1 "forwprop1" } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/gtu_to_ltu_cmp_1.c b/gcc/testsuite/gcc.target/aarch64/gtu_to_ltu_cmp_1.c index 81c536c90af..bfcec6719de 100644 --- a/gcc/testsuite/gcc.target/aarch64/gtu_to_ltu_cmp_1.c +++ b/gcc/testsuite/gcc.target/aarch64/gtu_to_ltu_cmp_1.c @@ -10,4 +10,4 @@ f1 (int x, int t) return t; } -/* { dg-final { scan-assembler-times "cmn\\tw\[0-9\]+, #2" 1 } } */ +/* { dg-final { scan-assembler-times "cmn\\tw\[0-9\]+, #3" 1 } } */