public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/114025] New: Seeming missing frange based optimizations
Date: Tue, 20 Feb 2024 22:04:33 +0000	[thread overview]
Message-ID: <bug-114025-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114025

            Bug ID: 114025
           Summary: Seeming missing frange based optimizations
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
#include <algorithm>
#include <stdexcept>

#if 1
#define AINLINE
#else
#define AINLINE [[gnu::always_inline]] inline
#endif

class TestClass
{
public:
    AINLINE void SetValue(float value);

private:
    float m_Value;
};

AINLINE
void TestClass::SetValue(float value)
{
    if (value >= 0.0f && value <= 100.0f) {
        m_Value = value;
    }
    else {
        throw std::out_of_range("Value must be [0, 100].");
    }
}

void TestFunc(TestClass& t, float value)
{
    value = std::clamp(value, 30.0f, 50.0f);
    // When TestClass::SetValue is inlined, the exception throwing code is not
eliminated.
    // Given that at this point we can prove that 'value' lies in the range
[30.0f, 50.0f] well within the range required by the setter function, we can
rid the not taken paths of code.
    t.SetValue(value);
}


```

at `-O3 -ffinite-math-only` when AINLINE is declared as nothing, TestFunc is
not always to just the clamp, but if we define it to be `inline` with
always_inline, then it is optimized to clamp. as far as I can tell the IR in
VRP1 is not able to handle correctly put the frange in for some of the SSA_NAME
and so `value >= 0.0f && value <= 100.0f` is not optimized away.

                 reply	other threads:[~2024-02-20 22:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-114025-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).