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.