From patchwork Wed Aug 21 16:25:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artemiy Volkov X-Patchwork-Id: 1975053 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=R9daDRjC; dkim=pass (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.a=rsa-sha256 header.s=mail header.b=OPaUgQVH; 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 4WpsDv42JHz1yYZ for ; Thu, 22 Aug 2024 02:27:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 938853870896 for ; Wed, 21 Aug 2024 16:27: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 4E5783858C78 for ; Wed, 21 Aug 2024 16:26:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E5783858C78 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 4E5783858C78 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=1724257623; cv=none; b=ZcyPne7wQ3hOVa5w6zro3PbqQl94155c0ieKhcNKAVcRLk/SxIQ2sLxUHGike1pEPp6/zEutZc6YpMOv0hr5vwKNptHN2CeWhSmE5xfg4g1Nx5hh190v46WWLb0QC9+i6FaR39ZzJHBeJ4Cvnj17w0Qci6OHpfOM46ug/L7LZOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724257623; c=relaxed/simple; bh=vfynK39qMmt9/7AeXmRMGlpX+MN9gm7AjC418Msmmm8=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=xNkWKinxeRNk4VZJ+Aed7/lI+1O5lueEs1otMLa9aenZiKfNRnuZqcOzp+VGZfZpSEbNGHKb1QxvdT74YHzBUlCu9LQqJrWJrL8C2HmDnCz1y0Rw1FIKEjCRoiH8HYq2yKFrHMn4pO3zRAsNYZRUfWmbt06rx8YO6flzgHHQw0s= 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 47LFcTHv005823; Wed, 21 Aug 2024 09:26:54 -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=Ut7+5Bzw8LMiKHstmbKgrEUp4r5FF0NI kYL60AmlpLU=; b=R9daDRjC1p3tZtkcRcjAmleeEexrXLxmvYeCLntN+q0MHJmW riutIgnqLFyFOD9p9cInylyIrFSRzQaH9XFW6cRSJjr/cxMOTdi3TIgO6Or3H5/E r/u7RpDSd+c2KLtZSVB+oYiyq+fWn5DTcjfX1sZX13xrqZB0AgBFvsKAiXR4UbOI SqTxyTrNEuU8Pi95O7bjKWlOOYKCXYYuq8s0hdBSnE8MYZkbt6d/UlJTKQ9QUqMX +J0U3Itng5SHwkV6VTKZhJqAdZOw7dbacxbnx11BbXeuCM65qRXagT8ms9Gk8tg1 cDpD00lGOtH6vm87gt+aJu61csb6FIQI2VtduA== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 414g8m1bmv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Aug 2024 09:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1724257598; bh=vfynK39qMmt9/7AeXmRMGlpX+MN9gm7AjC418Msmmm8=; h=From:To:Cc:Subject:Date:From; b=OPaUgQVHT9acfzFD0wHPgDN0tM67QXo682JBj/0hrtIWE0revTiIwdmrR7HszmQ8t MQO+OlnSlU+d1BdiopKzphhiWzCX5gjonTHf9BNM/ixe0hCfcuLUkT2wEP2cqAnt3V GAvmmPIokby9F7PMHDKuw8g9re+V3724GoMMVGlZv3SXdZBadpAGoWR9Jmu4BpsUYZ dIdgAPaGJAeLM2lk9alOJzGXJe0s6oucpdtZVOXj86+uikCXmx7M3JzThZkSzZLs8s /t8pgAxggu1jN+KjoAghFixob/zxdX13Ynh+mo5VPKSW83StZwQTWSKK6VUCurvt9S RUoU7zrD/4/Sw== 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 340FE40364; Wed, 21 Aug 2024 16:26:37 +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 BE89AA009C; Wed, 21 Aug 2024 16:26:37 +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 v2] tree-optimization/116024 - match.pd: add 4 int-compare simplifications Date: Wed, 21 Aug 2024 09:25:35 -0700 Message-ID: <20240821162547.25246-1-artemiy@synopsys.com> X-Mailer: git-send-email 2.44.2 MIME-Version: 1.0 X-Proofpoint-GUID: natabgWm85IbIp-EXdGJsxsd-CjlOpJJ X-Authority-Analysis: v=2.4 cv=T4TeTOKQ c=1 sm=1 tr=0 ts=66c6154d cx=c_pps a=8EbXvwLXkpGsT4ql/pYRAw==:117 a=8EbXvwLXkpGsT4ql/pYRAw==:17 a=yoJbH4e0A30A:10 a=mDV3o1hIAAAA:8 a=jIQo8A4GAAAA:8 a=CnWCUrD4G1r7GC1IkCYA:9 a=jrLeG1Ep96sA:10 a=_FVE-zBwftR9WsbkzFJk:22 a=Lf5xNeLK5dgiOs8hzIjU:22 X-Proofpoint-ORIG-GUID: natabgWm85IbIp-EXdGJsxsd-CjlOpJJ 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-21_11,2024-08-19_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 malwarescore=0 bulkscore=0 clxscore=1011 spamscore=0 lowpriorityscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 impostorscore=0 mlxscore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2408210121 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, TXREP, T_SCC_BODY_TEXT_LINE, T_SPF_TEMPERROR 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 Hi, sending a v2 of https://gcc.gnu.org/pipermail/gcc-patches/2024-August/659851.html after changing variable types in all new testcases from standard to fixed-width. Could anyone please assist with reviewing and/or pushing to trunk/14 since I don't have commit access? Many thanks, Artemiy ---------- 8< ------------ 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.dg/tree-ssa/pr116024-1-fwrapv.c | 74 ++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr116024-1.c | 74 ++++++++++++++++++ .../gcc.dg/tree-ssa/pr116024-2-fwrapv.c | 38 ++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr116024-2.c | 39 ++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr116024.c | 74 ++++++++++++++++++ .../gcc.target/aarch64/gtu_to_ltu_cmp_1.c | 2 +- 8 files changed, 376 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 65a3aae2243..bf3ccef7437 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -8800,6 +8800,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 @@ -8827,7 +8828,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 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-1-fwrapv.c b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1-fwrapv.c new file mode 100644 index 00000000000..1fe8c821bec --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1-fwrapv.c @@ -0,0 +1,74 @@ +/* PR tree-optimization/116024 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop1-details -fwrapv" } */ + +#include +#include + +uint32_t f(void); + +int32_t i2(void) +{ + int32_t l = 2; + l = 10 - (int32_t)f(); + return l <= 20; // f() + 10 + INT_MIN <= 20 +} + +int32_t i2a(void) +{ + int32_t l = 2; + l = 10 - (int32_t)f(); + return l < 30; // f() + 19 + INT_MIN <= 29 +} + +int32_t i2b(void) +{ + int32_t l = 2; + l = 200 - (int32_t)f(); + return l <= 100; // f() - 100 + INT_MIN <= 100 +} + +int32_t i2c(void) +{ + int32_t l = 2; + l = 300 - (int32_t)f(); + return l < 100; // f() - 201 + INT_MIN <= 99 +} + +int32_t i2d(void) +{ + int32_t l = 2; + l = 1000 - (int32_t)f(); + return l >= 2000; // f() + 999 + INT_MIN > 1999 +} + +int32_t i2e(void) +{ + int32_t l = 2; + l = 1000 - (int32_t)f(); + return l > 3000; // f() + 2000 + INT_MIN > 3000 +} + +int32_t i2f(void) +{ + int32_t l = 2; + l = 20000 - (int32_t)f(); + return l >= 10000; // f() - 10001 + INT_MIN > 9999 +} + +int32_t i2g(void) +{ + int32_t l = 2; + l = 30000 - (int32_t)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 00000000000..ecafb41fa09 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1.c @@ -0,0 +1,74 @@ +/* PR tree-optimization/116024 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop1-details" } */ + +#include +#include + +uint32_t f(void); + +int32_t i2(void) +{ + uint32_t l = 2; + l = 10 - (uint32_t)f(); + return l <= 20; // f() + 10 <= 20 +} + +int32_t i2a(void) +{ + uint32_t l = 2; + l = 10 - (uint32_t)f(); + return l < 30; // f() + 19 <= 29 +} + +int32_t i2b(void) +{ + uint32_t l = 2; + l = 200 - (uint32_t)f(); + return l <= 100; // f() - 100 <= 100 +} + +int32_t i2c(void) +{ + uint32_t l = 2; + l = 300 - (uint32_t)f(); + return l < 100; // f() - 201 <= 99 +} + +int32_t i2d(void) +{ + uint32_t l = 2; + l = 1000 - (uint32_t)f(); + return l >= 2000; // f() + 999 > 1999 +} + +int32_t i2e(void) +{ + uint32_t l = 2; + l = 1000 - (uint32_t)f(); + return l > 3000; // f() + 2000 > 3000 +} + +int32_t i2f(void) +{ + uint32_t l = 2; + l = 20000 - (uint32_t)f(); + return l >= 10000; // f() - 10001 > 9999 +} + +int32_t i2g(void) +{ + uint32_t l = 2; + 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" } } */ 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..ff8f097e647 --- /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 <= INT_MAX - 10; // f() > INT_MIN + 9 +} + +int32_t i3a(void) +{ + int32_t l = -21 + (int32_t)f(); + return l < INT_MAX - 20; // f() > INT_MIN + 20 +} + +int32_t i3b(void) +{ + int32_t l = 30 + (int32_t)f(); + return l >= INT_MIN + 30; // f() <= INT_MAX - 30 +} + +int32_t i3c(void) +{ + int32_t l = 40 + (int32_t)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 00000000000..f7269765fcb --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-2.c @@ -0,0 +1,39 @@ +/* PR tree-optimization/116024 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop1-details" } */ + +#include +#include + +uint32_t f(void); + +int32_t i3(void) +{ + uint32_t l = 2; + l = UINT_MAX - 9 + (uint32_t)f(); + return l <= UINT_MAX - 10; // f() > 9 +} + +int32_t i3a(void) +{ + uint32_t l = UINT_MAX - 20 + (uint32_t)f(); + return l < UINT_MAX - 20; // f() > 20 +} + +int32_t i3b(void) +{ + uint32_t l = 30 + (uint32_t)f(); + return l >= 30; // f() < -30u +} + +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.* > 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 00000000000..22b08057b2b --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr116024.c @@ -0,0 +1,74 @@ +/* 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 = 2; + l = 10 - (int32_t)f(); + return l <= 9; // f() > 0 +} + +int32_t i1a(void) +{ + int32_t l = 2; + l = 20 - (int32_t)f(); + return l <= INT_MIN; // return 0 +} + +int32_t i1b(void) +{ + int32_t l = 2; + l = 30 - (int32_t)f(); + return l <= INT_MIN + 31; // f() == INT_MAX +} + +int32_t i1c(void) +{ + int32_t l = 2; + l = INT_MAX - 40 - (int32_t)f(); + return l <= -38; // f() > INT_MAX - 3 +} + +int32_t i1d(void) +{ + int32_t l = 2; + l = INT_MAX - 50 - (int32_t)f(); + return l <= INT_MAX - 1; // f() != -50 +} + +int32_t i1e(void) +{ + int32_t l = 2; + l = INT_MAX - 60 - (int32_t)f(); + return l != INT_MAX - 90; // f() != 30 +} + +int32_t i1f(void) +{ + int32_t l = 2; + l = INT_MIN + 70 - (int32_t)f(); + return l <= INT_MAX - 2; // return 0 +} + +int32_t i1g(void) +{ + int32_t l = 2; + l = INT_MAX/2 + 30 - (int32_t)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 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 } } */