From patchwork Thu Aug 8 10:35:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artemiy Volkov X-Patchwork-Id: 1970492 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=hABBq9JY; dkim=pass (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.a=rsa-sha256 header.s=mail header.b=N0plPt73; 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 4Wfk3n1Yhqz1ybS for ; Thu, 8 Aug 2024 20:36:19 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 725883858420 for ; Thu, 8 Aug 2024 10:36:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00230701.pphosted.com (mx0b-00230701.pphosted.com [148.163.158.9]) by sourceware.org (Postfix) with ESMTPS id DDC333858D28 for ; Thu, 8 Aug 2024 10:35:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DDC333858D28 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 DDC333858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.9 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723113356; cv=none; b=l4iMbChQ6uZVI9Np4Q3McmBby6xSp56fWi+WRdUgj/Qn7ZE2E5vvGU7vEiiGKj8OKalNs8CPYzpOzxqYZ+IS+D73Z+tEFQThDXVkDx2RlancQHSeWO2qMXmsgkWzzKAIWxcY/18EIHKQyDqxyHoWquhmn+xlMdFUiSNGgCbbv0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723113356; c=relaxed/simple; bh=o22PZQ1AtWjXI5/Zjj7S631qnmBIdK5Xu53nGXjaqFA=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=EbMuzrYXCxT8ozuVJtyHRiuNIe1q698UVFI/1pL9mMJsZoXGbOLqWdxmSgL3/CY5FOatKZtrfB2T4SIFy6JGkVB3BHptSP5Ia086sWDEteUtqKhqOvDKzj9gwVSpadWpXwCDOvcYNxPzpFcdTPNPsZlJT1+PyyGs1R/2Xwv/Nsw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0297265.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4786G4xN016840; Thu, 8 Aug 2024 03:35:52 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h= cc:content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=pfptdkimsnps; bh=tZZnatHlnPLo3p22dI51uLhSUcYD0Cy7 cBykOGzW37Y=; b=hABBq9JYu1jDDaKEVJBogWJ0UaVrtP4pdg4nFNfhSAJ2bWkv v0OP8XOmFAcERCVQp3lsJ9weEwdgeCiMCmb64ag5kxDjXFiLze3AI9rXJUQZ+Wnf bQAdeut0JUfE664g2je/1iBHP5N1gjnKWcfrNbS/V0amB/Ca4VN53bi2oODkbIoI YDRwUwEeXnfdObZmVq+qzVNgdzpFCe12mVJ6vtlXszdafU4fmfojMXpUU49nPCpf uh0F3fYDRQkkY/QuCCrw6NdWqyhuGsD0yCSryKRzwDp0k99TIj8Zr6K/oLcakWfI uKhrL5iW0dEkp24x13hII2whiSAsvXUvKzi6oQ== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 40uujagq9g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Aug 2024 03:35:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1723113351; bh=o22PZQ1AtWjXI5/Zjj7S631qnmBIdK5Xu53nGXjaqFA=; h=From:To:Cc:Subject:Date:From; b=N0plPt73maNJgr9pGjPV4Xi5+1dOz1mTvggyxCqLKc5ePhdPwpne1cau1z3GawwKq 8KT5b0lEDA9lBI23t9C7phTJpMJyEZtMCy5XIAMJFkMb37qM29P7AIJOqrmIGKtFC5 fG6vu3EIclGjukXruR2nnTFKvpAo5vcmyv4Zp1ILJe7MYyQdTpgampjcHZQc0z1U2/ GfpHUqu9vuCn1ShgBkmW0DcLZ/aLvWIKpzGvwdY0Vvx6snY0D3hgKdVMiX9HDhqTwx pBBD/olu9Y0MZfm4j3NzHcOihVd902fr6S7Z0wHjgOEx14mDzrfF6XEsiKIWimlWoR iu20ML2bp12Ag== Received: from mailhost.synopsys.com (badc-mailhost4.synopsys.com [10.192.0.82]) (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 9F11340467; Thu, 8 Aug 2024 10:35:50 +0000 (UTC) Received: from us01arcgnu2.internal.synopsys.com (us01arcgnu2.internal.synopsys.com [10.15.128.224]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id 12B3FA0099; Thu, 8 Aug 2024 10:35:49 +0000 (UTC) X-SNPS-Relay: synopsys.com From: Artemiy Volkov To: gcc-patches@gcc.gnu.org Cc: quic_apinski@quicinc.com, rguenther@suse.de, Artemiy Volkov Subject: [PATCH] tree-optimization/116024 - match.pd: add 4 int-compare simplifications Date: Thu, 8 Aug 2024 03:35:26 -0700 Message-ID: <20240808103526.67007-1-artemiy@synopsys.com> X-Mailer: git-send-email 2.44.2 MIME-Version: 1.0 X-Proofpoint-GUID: LA-bjHZZHSpcttIgX6GuDEgTJSzsX5Tp X-Proofpoint-ORIG-GUID: LA-bjHZZHSpcttIgX6GuDEgTJSzsX5Tp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-08_11,2024-08-07_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 adultscore=0 priorityscore=1501 bulkscore=0 mlxlogscore=999 clxscore=1011 lowpriorityscore=0 malwarescore=0 phishscore=0 impostorscore=0 mlxscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2408080076 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org This patch implements match.pd patterns for the following transformations: (1) (UB-on-overflow types) C1 - X cmp C2 -> X cmp C1 - C2 (2) (unsigned types) C1 - X cmp C2 -> (a) X cmp C1 - C2, when cmp is !=, == (b) X - (C1 - C2) cmp C2, when cmp is <=, > (c) X - (C1 - C2 + 1) cmp C2, when cmp is <, >= (3) (signed wrapping types) C1 - X cmp C2 (a) X cmp C1 - C2, when cmp is !=, == (b) X - (C1 + 1) rcmp -C2 - 1, otherwise (4) (all wrapping types) X + C1 cmp C2 -> (a) X cmp C2 - C1, when cmp is !=, == (b) X cmp -C1, when cmp is <=, > and C2 - C1 == max (c) X cmp -C1, when cmp is <, >= and C2 - C1 == min Included along are testcases for all the aforementioned changes. 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 transformations around integer comparison. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr116024.c: New test. * gcc.dg/tree-ssa/pr116024-1.c: Ditto. * gcc.dg/tree-ssa/pr116024-1-fwrapv.c: Ditto. * gcc.dg/tree-ssa/pr116024-2.c: Ditto. * gcc.dg/tree-ssa/pr116024-2-fwrapv.c: Ditto. * gcc.dg/pr67089-6.c: Adjust. * gcc.target/aarch64/gtu_to_ltu_cmp_1.c: Ditto. Signed-off-by: Artemiy Volkov --- gcc/match.pd | 75 +++++++++++++++++++++- gcc/testsuite/gcc.dg/pr67089-6.c | 4 +- gcc/testsuite/gcc.dg/tree-ssa/pr116024-1-fwrapv.c | 73 +++++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr116024-1.c | 73 +++++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr116024-2-fwrapv.c | 37 +++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr116024-2.c | 38 +++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr116024.c | 73 +++++++++++++++++++++ .../gcc.target/aarch64/gtu_to_ltu_cmp_1.c | 2 +- 8 files changed, 371 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr116024-1-fwrapv.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr116024-1.c 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 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr116024.c diff --git a/gcc/match.pd b/gcc/match.pd index d401e75..97d4398 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -8418,6 +8418,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 @@ -8445,7 +8446,79 @@ 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 X + C1 CMP C2 to X CMP -C1 when possible. */ + (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 (min, wi::to_wide (@1)) + : wi::sub (min, wi::to_wide (@1)); + tree c1_cst = build_uniform_cst (TREE_TYPE (@0), + 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. */ + +(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) + (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)) + (with + { + fold_overflow_warning (("assuming signed overflow does not occur " + "when simplifying conditional to constant"), + WARN_STRICT_OVERFLOW_CONDITIONAL); + } + (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); + })) + (with + { + fold_overflow_warning (("assuming signed overflow does not occur " + "when changing C1 - X cmp C2 to " + "X cmp C1 - C2"), + WARN_STRICT_OVERFLOW_COMPARISON); + } + (rcmp @1 { res; })))) + (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_int_cst (TREE_TYPE (@1), 1); }))) @2))) + (if (TYPE_OVERFLOW_WRAPS (TREE_TYPE (@1))) + (if (cmp == EQ_EXPR || cmp == NE_EXPR) + (cmp @1 (minus @0 @2)) + (rcmp (minus @1 (plus @0 { build_int_cst (TREE_TYPE (@1), 1); })) + (negate @2)))))))) /* Canonicalizations of BIT_FIELD_REFs. */ diff --git a/gcc/testsuite/gcc.dg/pr67089-6.c b/gcc/testsuite/gcc.dg/pr67089-6.c index b59d75b..80a33c3 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-1-fwrapv.c b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1-fwrapv.c new file mode 100644 index 0000000..fdee4cb --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1-fwrapv.c @@ -0,0 +1,73 @@ +/* PR tree-optimization/116024 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop1-details -fwrapv" } */ + +#include + +unsigned f(void); + +int i2(void) +{ + int l = 2; + l = 10 - (int)f(); + return l <= 20; // f() + 10 + INT_MIN <= 20 +} + +int i2a(void) +{ + int l = 2; + l = 10 - (int)f(); + return l < 30; // f() + 19 + INT_MIN <= 29 +} + +int i2b(void) +{ + int l = 2; + l = 200 - (int)f(); + return l <= 100; // f() - 100 + INT_MIN <= 100 +} + +int i2c(void) +{ + int l = 2; + l = 300 - (int)f(); + return l < 100; // f() - 201 + INT_MIN <= 99 +} + +int i2d(void) +{ + int l = 2; + l = 1000 - (int)f(); + return l >= 2000; // f() + 999 + INT_MIN > 1999 +} + +int i2e(void) +{ + int l = 2; + l = 1000 - (int)f(); + return l > 3000; // f() + 2000 + INT_MIN > 3000 +} + +int i2f(void) +{ + int l = 2; + l = 20000 - (int)f(); + return l >= 10000; // f() - 10001 + INT_MIN > 9999 +} + +int i2g(void) +{ + int l = 2; + l = 30000 - (int)f(); + return l > 10000; // f() - 20000 + INT_MIN > 10000 +} + +/* { dg-final { scan-tree-dump-times "Removing dead stmt:.*?- _" 8 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ -11.*\n.*>= -20" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ -11.*\n.*>= -29" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ -201.*\n.*>= -100" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ -301.*\n.*>= -99" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ -1001.*\n.*< -1999" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ -1001.*\n.*< -3000" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ -20001.*\n.*< -9999" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* \\+ -30001.*\n.*< -10000" 1 "forwprop1" } } */ 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 0000000..40b797c --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1.c @@ -0,0 +1,73 @@ +/* PR tree-optimization/116024 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop1-details" } */ + +#include + +unsigned f(void); + +int i2(void) +{ + unsigned l = 2; + l = 10 - (unsigned)f(); + return l <= 20; // f() + 10 <= 20 +} + +int i2a(void) +{ + unsigned l = 2; + l = 10 - (unsigned)f(); + return l < 30; // f() + 19 <= 29 +} + +int i2b(void) +{ + unsigned l = 2; + l = 200 - (unsigned)f(); + return l <= 100; // f() - 100 <= 100 +} + +int i2c(void) +{ + unsigned l = 2; + l = 300 - (unsigned)f(); + return l < 100; // f() - 201 <= 99 +} + +int i2d(void) +{ + unsigned l = 2; + l = 1000 - (unsigned)f(); + return l >= 2000; // f() + 999 > 1999 +} + +int i2e(void) +{ + unsigned l = 2; + l = 1000 - (unsigned)f(); + return l > 3000; // f() + 2000 > 3000 +} + +int i2f(void) +{ + unsigned l = 2; + l = 20000 - (unsigned)f(); + return l >= 10000; // f() - 10001 > 9999 +} + +int i2g(void) +{ + unsigned l = 2; + l = 30000 - (unsigned)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" } } */ 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 0000000..4fff886 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-2-fwrapv.c @@ -0,0 +1,37 @@ +/* PR tree-optimization/116024 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop1-details -fwrapv" } */ + +#include + +unsigned f(void); + +int i3(void) +{ + int l = -10 + (int)f(); + return l <= INT_MAX - 10; // f() > INT_MIN + 9 +} + +int i3a(void) +{ + int l = -21 + (int)f(); + return l < INT_MAX - 20; // f() > INT_MIN + 20 +} + +int i3b(void) +{ + int l = 30 + (int)f(); + return l >= INT_MIN + 30; // f() <= INT_MAX - 30 +} + +int i3c(void) +{ + int l = 40 + (int)f(); + return l > INT_MIN + 39; // f() <= INT_MAX - 39 +} + +/* { 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.* >= -2147483627" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* <= 2147483618" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* <= 2147483608" 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 0000000..f492e72 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-2.c @@ -0,0 +1,38 @@ +/* PR tree-optimization/116024 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop1-details" } */ + +#include + +unsigned f(void); + +int i3(void) +{ + unsigned l = 2; + l = UINT_MAX - 9 + (unsigned)f(); + return l <= UINT_MAX - 10; // f() > 9 +} + +int i3a(void) +{ + unsigned l = UINT_MAX - 20 + (unsigned)f(); + return l < UINT_MAX - 20; // f() > 20 +} + +int i3b(void) +{ + unsigned l = 30 + (unsigned)f(); + return l >= 30; // f() < -30u +} + +int i3c(void) +{ + unsigned l = 40 + (unsigned)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.* > 9" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to.* > 20" 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.dg/tree-ssa/pr116024.c b/gcc/testsuite/gcc.dg/tree-ssa/pr116024.c new file mode 100644 index 0000000..26bb81d --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr116024.c @@ -0,0 +1,73 @@ +/* PR tree-optimization/116024 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop1-details" } */ + +#include + +unsigned f(void); + +int i1(void) +{ + int l = 2; + l = 10 - (int)f(); + return l <= 9; // f() > 0 +} + +int i1a(void) +{ + int l = 2; + l = 20 - (int)f(); + return l <= INT_MIN; // return 0 +} + +int i1b(void) +{ + int l = 2; + l = 30 - (int)f(); + return l <= INT_MIN + 31; // f() == INT_MAX +} + +int i1c(void) +{ + int l = 2; + l = INT_MAX - 40 - (int)f(); + return l <= -38; // f() > INT_MAX - 3 +} + +int i1d(void) +{ + int l = 2; + l = INT_MAX - 50 - (int)f(); + return l <= INT_MAX - 1; // f() != -50 +} + +int i1e(void) +{ + int l = 2; + l = INT_MAX - 60 - (int)f(); + return l != INT_MAX - 90; // f() != 30 +} + +int i1f(void) +{ + int l = 2; + l = INT_MIN + 70 - (int)f(); + return l <= INT_MAX - 2; // return 0 +} + +int i1g(void) +{ + int l = 2; + l = INT_MAX/2 + 30 - (int)f(); + return l <= INT_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" } } */ 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 81c536c..bfcec67 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 } } */