From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by sourceware.org (Postfix) with ESMTPS id DE43F385E005 for ; Fri, 5 Jan 2024 00:56:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE43F385E005 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DE43F385E005 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b2e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704416183; cv=none; b=EBPeTO99FrlGaeiWxoiDsfNbXVK+/rHki6h3dHz8Y/CuvszOdHZDZvKOC9kOPrWmRN4YcLGs9O/2bHe7HzoETIyjFYnH0wiiFArMBOoRuC+u61XnV4coeGHv8k3NqHk5iTc5lZWOBsR9IpKlJDnBjSsn39T7AVYCD+0Tx5ctU8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704416183; c=relaxed/simple; bh=16qoI0Cl8ADFJUUU0SIE1ekRUoV1J+6WR5HEndrHFnw=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=U80VlsnpXw9mTve4eTcfcKGuHJf0iRlllCNyqR4e0XFpMY4xj77JApl4Xo9w/xMWkfWOver5PbkRcaeuPwFeNxlmGIjUYw5Iv0t0UtTjrO9qB+p23KaGqaLdoY12Wmc+C4O4cEqE+gsKNDkoQ56WEuGwH4e50zsG/no8R0T1kns= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb2e.google.com with SMTP id 3f1490d57ef6-dbdd013c68bso945796276.2 for ; Thu, 04 Jan 2024 16:56:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704416176; x=1705020976; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=niqJYVUi+HOLoURatq6fs6vDNAZt4BqKb5IDHkO+rtQ=; b=ZX7hs6dgdyMw+zG0Dkf/JEuimQFKh8hP/0iSXo3Xq101oMCRwqJ/Z1LySU2PUMdoBA FcZEgo8KQAt2AWhdUMI/OWcjPOWpXrwAoNuNRw72HBBS+GcrOdpqK1PK5J0qv/t3uf2K OG9nz1gUvRKSp9Oa5vrvtJ0oWRy6taTFItTm4gkLYNZt0oui0WGOuScbzepmPxLWQHA7 CXpEbdxZUQASXBKJAYYPv679Gty3VQBfWoAsfWWy60y5ZAcImYlBcDQ4cihYxu5wCPSY pIJiWhRNb8VYCecPqiEaBuT5JhIOPqbxuO2Hyr7J5CVe6PZrncqzcTYC9rKTRku2Jh2l QiDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704416176; x=1705020976; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=niqJYVUi+HOLoURatq6fs6vDNAZt4BqKb5IDHkO+rtQ=; b=se8lVKjOWqYIlYZgkT+zFS4+hYyyCeYRAccjhkuCM8idb1tHDO1eyit/82SGI3Inj+ 8rK8cqm2LxcOhpEjAbqTtEWxpgz4FoYBP0k0Kiv+AiB/rW9vEUjhUdG5lumIDabNcxbU E3O4P+u14K/jzNL6Hc8hVY6VcutJbNUXH76YjYYiCr2JowNuHwXYp7Udq6tuP44oILuf 76nTw3n5D1WiNktSfOZmVASVwsu77SjnAJN2bItRx09bClzq3b3fdbH4dTHQLS9jwIvR w+Ptjdu0zGamClHbSf8G6u0Y/qi87HCs99cgb+CLPOuvn8ekeEWdpUBABiQ1uxSeHVlX BPJQ== X-Gm-Message-State: AOJu0Yyyzxg9WwePB2dt6/PgQ/AHfpIK8tsXKDLlW4/VdcRgSG9feWKQ I7usuGDaa0+jiV6iJOakR2LpfRt1XUriM8xXUOk= X-Google-Smtp-Source: AGHT+IHhScYQ1c8lUGOPxwuv6aCOwed57pl5KFGg2QMpQP/zuGHmWFY15xKxmUGS4XKFJ7SfbTLk8BpqA9rOA/67TNI= X-Received: by 2002:a25:820d:0:b0:dbc:c592:5a3c with SMTP id q13-20020a25820d000000b00dbcc5925a3cmr1429808ybk.2.1704416176029; Thu, 04 Jan 2024 16:56:16 -0800 (PST) MIME-Version: 1.0 References: <38c39ae1-d017-4cf4-a48c-797a273f50a5@126.com> In-Reply-To: <38c39ae1-d017-4cf4-a48c-797a273f50a5@126.com> From: Hashan Gayasri Date: Fri, 5 Jan 2024 11:56:04 +1100 Message-ID: Subject: Re: pragma GCC optimize prevents inlining To: LIU Hao Cc: gcc-help@gcc.gnu.org Content-Type: multipart/alternative; boundary="000000000000b8c3d8060e2850da" X-Spam-Status: No, score=0.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000b8c3d8060e2850da Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Hao, Thanks for the suggestion! Yes, - fno-math-errno is definitely more suitable for enabling globally than -ffast-math. While I don't particularly remember using errno for math functions in particularm it's used in non-math functions. So eventhough it seems reasonable to be enabled globally, still a bit tricky to validate that it doesn't cause any unintentional side effects with a large codebase with 3rd parety libs. Another weird side effect I noticed is GCC still doesn't inline the function when the function is within a `pragma GCC optimize ("-fno-math-errno") ` region and -ffast-math is enabled globally eventhough -fno-math-errno is a subset. If you enable both -ffast-math and -fno-math-errno, globally, the function gets inlined. I'm not sure if improving that should be considered as a bug-fix or a feature/enhancement. Best Regards, Hashan Gayasri On Thu, 4 Jan 2024, 8:28 pm LIU Hao, wrote: > =E5=9C=A8 2024/1/4 17:01, Hashan Gayasri via Gcc-help =E5=86=99=E9=81=93: > > I wanted the following to be to be optimized: > > > > (... ...) > > > > So that std::lrint uses the vcvtsd2si instruction on X86 with SSE2. It > > does that but prevents the instruction from being inlined. I complied > with > > - O3 -march=3Dnative -DNDEBUG. > > Actually `-ffast-math` is an overkill; `-fno-math-errno` isn't practically > bad, and can be enabled > globally: > (https://gcc.godbolt.org/z/hhfP6cYrr) > > ``` > //#pragma GCC push_options > //#pragma GCC optimize ("-ffast-math") > > inline int64_t __attribute__ ((const)) RoundToNearestLong (double v) > { > // assert(fegetround() =3D=3D FE_TONEAREST); > return lrint(v); > } > > //#pragma GCC pop_options > > void > xgset(int64_t& r, double s) > { > r =3D RoundToNearestLong(s); > } > ``` > > results in > ``` > xgset(long&, double): > vcvtsd2si rax, xmm0 > mov QWORD PTR [rdi], rax > ret > ``` > > > > -- > Best regards, > LIU Hao > > --000000000000b8c3d8060e2850da--