From patchwork Wed Mar 3 23:36:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SXZhbiBTdcSNacSH?= X-Patchwork-Id: 1446965 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ohaIhM4E; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DrVkM1dzCz9sTD for ; Thu, 4 Mar 2021 10:36:11 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E33AB384B80F; Wed, 3 Mar 2021 23:36:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E33AB384B80F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1614814567; bh=c+zNBCFaNNqpSOYTp6jXds4hSmBE619MWhGmx93SU+o=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ohaIhM4EoOFhCvWRA5Qw2niBqVN7YXo7+XdXu6Oo3ZlrdK5jnOcb8b+DPRnunta7r zW1HqGITsj5onIMUfMY7el/wLUdV+b5lpXK781s1zsuIwOr9fFOAiE1jvw8QNGbIzt /A4fRKqLeSnH/k/jRnTHiQax3OdFEUBt5tKgnrtA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR06-DB8-obe.outbound.protection.outlook.com (mail-db8eur06olkn2077.outbound.protection.outlook.com [40.92.51.77]) by sourceware.org (Postfix) with ESMTPS id D80E3386197D for ; Wed, 3 Mar 2021 23:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D80E3386197D ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZBXOak1tXQKtSfd+fzbJ35lXXLEfaLde6JsCXHPUuDLDvysUCQfF3KorNLzsqNrSGWVjnCy+QRTwnVpFxVtDYRjwZvOOhdt3fJLqa1uu2ogALdugVf2m1y6uk5lF9PwvFCw7Krf0bs5XqFM0pzMYsly7cZKonPaWo9rxxNBpXdJ0wAu3wokWItCJx18x6GfpGUHk14ZFhRbbhmdPPMD+84IkSsSSftqSswy6Wnutn8L1sIdKWmF+HShV6V/YHxsKKkBq1MtRb62TIePzEg9UcfeCSMyFcXKeqr2CoqVH1tupZq76/F6hDhwjMvs3H5I9e9t0ytsAZEoRFbx9DxfXgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iJsWmzPjfos/+ZF3fnxHI3vexdA7R9dkccIpeXiHAhs=; b=PqpQjiyYlk0v1/PEkM1dhMwGm6OABSN7oqu9by3uPiVYx1XJlGWWd8nyYt64zaPs1GH2VuhxxY1JUMQMPwuj/dyEPKti2dg8NqNHMqO43L25kk/C8ZMfvgBJ1dspqJdpIr8482L01n983sa8JaD3rZSUqocm7MQh0Sq+yBmyr+Aegd1KxFP61X0rmyw3DS+3zi/nidRtzCihxYD+6IsAms+DLI22KUUstOwgU1WW3TPU5JoXLo24d7K18cSUUNUgJW0KL1pxX/rbUBODfIVf9vITIgiPJQevkEKtajJkKuLkKhfbV9fV5LFcDq6J56roIWDnJHcGz/iLD9lGZUvoiA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from DB8EUR06FT013.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc35::45) by DB8EUR06HT229.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc35::508) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19; Wed, 3 Mar 2021 23:36:02 +0000 Received: from AM6PR10MB2023.EURPRD10.PROD.OUTLOOK.COM (2a01:111:e400:fc35::50) by DB8EUR06FT013.mail.protection.outlook.com (2a01:111:e400:fc35::209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19 via Frontend Transport; Wed, 3 Mar 2021 23:36:02 +0000 Received: from AM6PR10MB2023.EURPRD10.PROD.OUTLOOK.COM ([fe80::5859:3a77:28f8:ce1f]) by AM6PR10MB2023.EURPRD10.PROD.OUTLOOK.COM ([fe80::5859:3a77:28f8:ce1f%7]) with mapi id 15.20.3890.029; Wed, 3 Mar 2021 23:36:02 +0000 To: "gcc-patches@gcc.gnu.org" Subject: [PATCH] ssa-ifcombine: combining comparisons [Bug 53806] Thread-Topic: [PATCH] ssa-ifcombine: combining comparisons [Bug 53806] Thread-Index: AQHXEINXxTdFxhQfiE+lD/g7Myx4CA== Date: Wed, 3 Mar 2021 23:36:02 +0000 Message-ID: Accept-Language: hr-HR, en-US Content-Language: hr-HR X-MS-Has-Attach: yes X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:472DAEB407C27BD75D481237FBF3EDD0BA454190329BC3085DD5B280B0388685; UpperCasedChecksum:2AFD12987DE42FF3CA05600635E196FE6F672F6E37C84B7E1A80B1D1D378CBCD; SizeAsReceived:6863; Count:41 x-tmn: [W17jloeomPI5vS+8MLkUPXyWt8li9Nf0uGR2qk/4ee9eATlMh9LKrTT4/X/q1rMo] x-ms-publictraffictype: Email x-incomingheadercount: 41 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 3222a989-495e-45b0-8387-08d8de9d1b7b x-ms-traffictypediagnostic: DB8EUR06HT229: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 26/sEfl5K4/4uu4R71dQsdwQ3i3oFZK2i3ZqQY0Bk28efSdqTKM4dS5uDTp4ApWnz40XUSqipUk5g40zty5SM4oSBkbtDM0t8d/Ke5ktVbxa+NqmrcM9EdByIUFnkzPDIx9ZdiraU08Z2S3K/PhiZDVbhczVK0gA6faBK5st65unB6YUmcknW8YjP4CL4/X6X2QP8Ug7Ja+TAfJV7Dgi+t3nEGNDRGYn7KeurRZmXKgYqEpNGVmAK9QxDFJ/K9PLLP9N1gaN2LG768S0Dj7oJxU3fvvgoeUCYwJP+QLYth58G4sMeqAQ36b9GGVgzQbZW8c41QsSNFtz6uVWbNytHURCgS3P7fCOi4tZ4j0IqetTAsaD1zKMkXW2ABW9iplb x-ms-exchange-antispam-messagedata: GsVTo5IwhKdgU05KhFua3CN2JBt6xY0YxeRHhL8eFDbRGIXg7IQhlQ1lfgdU1nISHVZ+rRr5YeRv7eaRNAqNzPZgdviec1OMwhCbeFDGzugTv5veGUj83BeihW+q2NG2gDHLWdxsBLqcBFwuCqXZS09nWHhu4glOTTCt0KlnKyK6CKYUdHmkKzwE7JzN7Yu2J6mRoycxI/i4ef3I6kMeag== x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-AuthSource: DB8EUR06FT013.eop-eur06.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 3222a989-495e-45b0-8387-08d8de9d1b7b X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Mar 2021 23:36:02.3737 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8EUR06HT229 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Ivan_Su=C4=8Di=C4=87_via_Gcc-patches?= From: =?utf-8?b?SXZhbiBTdcSNacSH?= Reply-To: =?iso-8859-2?q?Ivan_Su=E8i=E6?= Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, The patch solves the bug when in ifcombine are comparisons like <= and >= combined. I removed the trap check for last statement and that doesn't break the solution for bug 61383. In fold-const.c i removed the trap checks becase combining comparisons doesn't introduce new traps. I tested my patch on wsl2 debain and it doesn't have more failed tests then without my patch. Maybe the only problem with testing is that i get error tcl error sourcing gcc/testsuite/gcc.misc-tests/linkage.exp. That error I get without my patch, too. I hope you will accept my patch. diff --git a/ChangeLog b/ChangeLog index 6c07275d2b4..29176bf9607 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2021-03-03 Ivan Sucic + PR 53806 + * tree-ssa-ifcombine.c: Checking trap not for + last statment + * fold-const.c: The comparison combine makes + new comparison correct and the trap check is + not required. + * ssa-ifcombine-14.c: Testcase for if combine + comparisons of double type. + 2020-07-23 Release Manager * GCC 10.2.0 released. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 3744e4c2c2d..a83c98014fb 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -2860,40 +2860,6 @@ combine_comparisons (location_t loc, else if (compcode == COMPCODE_ORD) compcode = COMPCODE_TRUE; } - else if (flag_trapping_math) - { - /* Check that the original operation and the optimized ones will trap - under the same condition. */ - bool ltrap = (lcompcode & COMPCODE_UNORD) == 0 - && (lcompcode != COMPCODE_EQ) - && (lcompcode != COMPCODE_ORD); - bool rtrap = (rcompcode & COMPCODE_UNORD) == 0 - && (rcompcode != COMPCODE_EQ) - && (rcompcode != COMPCODE_ORD); - bool trap = (compcode & COMPCODE_UNORD) == 0 - && (compcode != COMPCODE_EQ) - && (compcode != COMPCODE_ORD); - - /* In a short-circuited boolean expression the LHS might be - such that the RHS, if evaluated, will never trap. For - example, in ORD (x, y) && (x < y), we evaluate the RHS only - if neither x nor y is NaN. (This is a mixed blessing: for - example, the expression above will never trap, hence - optimizing it to x < y would be invalid). */ - if ((code == TRUTH_ORIF_EXPR && (lcompcode & COMPCODE_UNORD)) - || (code == TRUTH_ANDIF_EXPR && !(lcompcode & COMPCODE_UNORD))) - rtrap = false; - - /* If the comparison was short-circuited, and only the RHS - trapped, we may now generate a spurious trap. */ - if (rtrap && !ltrap - && (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)) - return NULL_TREE; - - /* If we changed the conditions that cause a trap, we lose. */ - if ((ltrap || rtrap) != trap) - return NULL_TREE; - } if (compcode == COMPCODE_TRUE) return constant_boolean_node (true, truth_type); diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-14.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-14.c new file mode 100644 index 00000000000..f94bc1f2cbb --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-14.c @@ -0,0 +1,13 @@ +/* { do-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +int +f (double a,double b) +{ + if (a>=b) if (a<=b) return 1; + return 0; +} + +/* { dg-final { scan-tree-dump-times "==" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-not "<=" "optimized" } } */ +/* { dg-final { scan-tree-dump-not ">=" "optimized" } } */ diff --git a/gcc/tree-ssa-ifcombine.c b/gcc/tree-ssa-ifcombine.c index 21a70f4386d..f2abaf18342 100644 --- a/gcc/tree-ssa-ifcombine.c +++ b/gcc/tree-ssa-ifcombine.c @@ -125,7 +125,8 @@ bb_no_side_effects_p (basic_block bb) if (gimple_has_side_effects (stmt) || gimple_uses_undefined_value_p (stmt) - || gimple_could_trap_p (stmt) + /* Last statement is taken care by combining ifs */ + || (!gsi_one_before_end_p (gsi) && gimple_could_trap_p (stmt)) || gimple_vuse (stmt) /* const calls don't match any of the above, yet they could still have some side-effects - they could contain