From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from IND01-MA1-obe.outbound.protection.outlook.com (mail-ma1ind01olkn0182.outbound.protection.outlook.com [104.47.100.182]) by sourceware.org (Postfix) with ESMTPS id 1D46D3858D3C for ; Sun, 23 Jan 2022 08:37:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1D46D3858D3C ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E23+l+YHI16/GNMOzYNrtlZQn46y7sO1RdgZTImrB4sM8Puh14o5mnsQ+jlU3pF5K+Fo2/NijRJgQuLgMzxMeTrXm52WLlMKAjC+HP+pzRz6nQ+aZYm2inzAjO+rG8VKO3olBgndBbZIXp6MyGwhUnIhlIhwarGjYaDXE+Zrz1IwODZT5EqK7UkUzvfQemDg6DWIpCjFd30qDr0PLaABwZGM6ndWs+oQ1113EWJZDAkiee/k9rV0DddA3G1xOjjcg0aXE+hkkokYcrvr4luyYMAE0fiGfad/RKrFCekhZ99MPizqMZfBRT+isI8LvbyIlmqlBs5pnnM26bSzTftMOg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kHe6Y1hkJDZvuEQ6WfEUc1oUwQCW6a4CfD7rLPyxqbY=; b=dLJ2gMWb8G/G8wWNq3zm8kvIpnpONDOQ9fKr04Kdn7PhzDZ9icThKOjloAvqXn8Bf4NHY0WLaK9qswKfaYE0WPDPHds+spGoG5ROGI7YstzVTpckhulIUaKWpk5DEsVtW9lJuXEmKGIwAEt29yotqZrit6s1tqT//zQB4witu/q1Gc5mUonO/wre8/EthZW631qd6TS2VG2cUWdMZTGh4oL6hb5OjjC2iuek84RAFbhXheMY4giw8UKM0buMO+kjV+YcyWIM8rj9vrwdyX5DRF0qTt2EEDdM9XBC+7P2KrP1flfYzOW7FqdwuSLQvc41/2x4Oz/5gMnf+6t4ohksrg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MA1PR0101MB1559.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:2d::13) by MAXPR01MB3695.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:6b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.10; Sun, 23 Jan 2022 08:37:43 +0000 Received: from MA1PR0101MB1559.INDPRD01.PROD.OUTLOOK.COM ([fe80::10ef:c976:293:fbb7]) by MA1PR0101MB1559.INDPRD01.PROD.OUTLOOK.COM ([fe80::10ef:c976:293:fbb7%10]) with mapi id 15.20.4909.017; Sun, 23 Jan 2022 08:37:42 +0000 From: Vishal Subramanyam To: "gcc-help@gcc.gnu.org" Subject: Pure/const function not getting executed as the first operand to logical OR ( || ) (C++) Thread-Topic: Pure/const function not getting executed as the first operand to logical OR ( || ) (C++) Thread-Index: AQHYEDFsnpbDIN0L3Em2YYRQSo5zug== Date: Sun, 23 Jan 2022 08:37:42 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: suggested_attachment_session_id: ac2b5d2b-1dbb-19f5-6867-b92535bb9ba6 x-tmn: [TykwJ478wtvlLMX+t0/zVA1hMS/D4URgMdnIzZTOLF0=] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 3f172083-73f4-439a-d0bd-08d9de4b9f86 x-ms-traffictypediagnostic: MAXPR01MB3695:EE_ x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: QmHIH5dmiy8+6KNVAZMI9/Wd8PKPdQoVmUQj5sz+nEP7eqwqK8k14tZKwvKpXfgpgo2nCwFZJDGK3ynuF9QSqcdfrx/6Vr6rvUNPesIUXDtqTwV0HFx136EkNRCJRrwKpuvl8eS1wz798EMxOd6leMbOSUWFbW+7c56jRl/i2OKkxF939Y8pmjykozMzDEwnFkqKH6Vq9yuRowCC/IZqxl4Id/7Q0Z7pSwbA8luYhw8UGyr2+HJgO1r5iAd+WQR9lIubS0h8Yh6Zd4Z8gHK5opsT9xCct6MzFTnKSqtg4WT0DH+mNNoK9Qv55idpqoySkJ/rRPE3bV6E11RNmatSlVKu+k0MRTlKv1MIae27/8QRaQJ92bSsgPEE6it4Q4RkSRXwDaenkKlHFfD2LXu/eOjmWijbdMOq/vn0p/YsKus4OKpywDVazpynH1M26bHK25Cb++sU9CorVR9kInCbpcKH9p7oeKfWgPVDRdSu/Rr9T+ucIUWIQvqV8vPSIRIszhYiPeHbiV/4AFV6s/mOOqg1RFS3akUsI/gS5y6H9nJeTBHu97UHEhk+01nRRT2F8QaGAq5tc6QjNC+7RN1VfQ== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?Q?kOLcjKlcnYFSuRdV6PFLFzK2trLujqgQdglnIUVYv1cXC4r0F47tisXd2P?= =?iso-8859-1?Q?p3NYnHO/9cSNe+QyWkhkeNvspi3Eao47chNIMYU/nigvDLgm0ixcZC0nyK?= =?iso-8859-1?Q?qIiSHhzUmgYSPs5ZHKlGyEuBaq0SOodJu6IjpxgnHQciIMBc2HpkNz0uye?= =?iso-8859-1?Q?gE7Yh4sLYtOUXfRJ2fHbPFoznpW8wF4AvZ6y6QZMONzi435yylZz6d6kjg?= =?iso-8859-1?Q?RXWbwgMvRiIdcn+ajsnK0cMS0iQJRZnO3VL7osfvjwNApE9w8pSS59b1MZ?= =?iso-8859-1?Q?Q70xYQD2uOApZ3/S8S9gOFhm0yXZ1RNwBUaPLXJUC6B4BZ2E0YwJZAzC0O?= =?iso-8859-1?Q?s/1SpGzSUqCCNKYrjExGrvTQ+ZmHS0/0nsx456NB1ISl7Tj8hB9zYgsTWP?= =?iso-8859-1?Q?rg6IdWjM6/N8NmatoWa0vz+6Z2EVzkQGfUPu3+eieOl53r1mjVDLx3EKyw?= =?iso-8859-1?Q?CxUihqh3wfGRcB31BnE3dWOh2EcZrAfhvUECFN4dtk0/iUjzXecJnJnEDI?= =?iso-8859-1?Q?f0udN4J/WfnbDMZLw/UfHpHP0HiycSrqDU10gCesnaURx4SdKqTTrmiay/?= =?iso-8859-1?Q?kRCmhvLsNts4w6V6Q348b8rAzngUDhzdTskeDxGO3v7VtMsEOYPevuRjCq?= =?iso-8859-1?Q?H3E8xHhMMdAhuGf+QmVIlxU3Uzu2oCx/Km3Sw0gurFDeHy6P7yzfQSPRKS?= =?iso-8859-1?Q?ZOUaKAL4qfNahNX0PGnPQCy0F4O+3DCeC93dX93UuRs3L5yYMOQjbmvzUm?= =?iso-8859-1?Q?81wDJI5MELqlZps9Mz/iR1FxSyhLxnGWb/3A6TCC47o9Gt59+a78ZlLiEy?= =?iso-8859-1?Q?ZKKWKihXm2XPKf/d7LIOtVCFBI6097Oj7/fHHezNaTayVUqxwa+RcymRjg?= =?iso-8859-1?Q?gzK5C++P3UW7xlk+H23oUqyfhDvMKwZ5rJpSBN2dOO4dph1icE9oc6/edc?= =?iso-8859-1?Q?tWNfh0XoU3pUvGyEk3e+7WaUk+vgxpqeIPvTmhJe2D5n/U1H0BW1NQ=3D?= =?iso-8859-1?Q?=3D?= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA1PR0101MB1559.INDPRD01.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 3f172083-73f4-439a-d0bd-08d9de4b9f86 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Jan 2022 08:37:42.9180 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted 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: MAXPR01MB3695 X-Spam-Status: No, score=0.5 required=5.0 tests=BAYES_20, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Jan 2022 08:37:51 -0000 When compiling the following C++ snippet with -O0, I'm getting a Floating P= oint Exception on my Ubuntu 21.10, g++ 11.2.0, x86-64.=0A= =0A= #include =0A= =0A= int func(int n, int r)=0A= {=0A= return n % r;=0A= }=0A= int main()=0A= {=0A= const int n =3D 15, r =3D 0;=0A= if (r =3D=3D 0 || func(n, r))=0A= std::cout << "YES" << std::endl;=0A= else=0A= std::cout << "NO" << std::endl;=0A= if (func(n, r) || r =3D=3D 0)=0A= std::cout << "YES" << std::endl;=0A= else=0A= std::cout << "NO" << std::endl;=0A= return 0;=0A= }=0A= =0A= With -O0, I'm getting a Floating Point error in the second if condition sin= ce it involves executing the "func" function where division by zero occurs.= =0A= =0A= YES=0A= Floating point exception (core dumped)=0A= =0A= Now, with -O1 optimization, this is the output.=0A= =0A= YES=0A= YES=0A= =0A= The "func" call has been optimized away. I checked the assembly code output= with -S and verified the same. Now, I would like to know what was the opti= mization (the optimization option) that led to this happening. When I tried= compiling the same code with -O0 but with an additional "-fipa-pure-const"= , I'm getting the same output as the O1 program with two YESes. But when I = try compiling with both the -O1 and -fno-ipa-pure-const, I am not getting t= he Floating Point Exception. If -fipa-pure-const is responsible for the opt= imization that removes the function call, shouldn't the function call occur= with -fno-ipa-pure-const. I have tried various combinations of options rel= ated to dead code elimination and branch probabilities, but can't figure ou= t what's happening?=0A= =0A= Thanks,=0A= Vishal=