<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/82381>82381</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed optimization: dead code is not eliminated based on possible floating-point values at any optimization level.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Archaic-Dreams
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/6sWTPvne9
```
#include <algorithm>
#include <stdexcept>
class TestClass
{
public:
void SetValue(float value);
private:
float m_Value;
};
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);
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVF2PqzYQ_TXmZbSImM888JBNmj5VqtSr3seVwUNwa2yKB9K9v76yySbLblc3ihKbGZ8558xg4Zy6GMSa5c8sP0Vipt5O9WFqe6Hap9OEYnBRY-Vr3RONjqUHxs-Mny9WNlZTbKcL4-cfjJ8L9_3b74vBPUtOLDmwIrl91y1PlWn1LBFYehT6YidF_cDSX_4v7kjivy2O9IiH31YL5-AbOjr61S1UPq-LcW60aj3FsAUAWKyS8AfSn0LPyHjVaSsIlnW3Z-nze_RxUosg3ACsB4aXFeCeX54-nA2FHsTSA0sPX9fd8vZ1VAeMVyEBvOj0BEmc-IcF4wW8BY4-sEt8iPE9bCD850YUfNqyoeyjnvZ9g9rhZwDqJ3sFR3KVYGd6sd3LJMzFy2Ccr_jD7AgaBJY_J4wfPSWWn2LG-XtbNzUfi61h59m0jFcP73gB5DF_6tlyl3rn22oxjG9GepB0teoI-c2zLbkwy_C9R_NV80A5UEYrg9LDUI-wjqayZnVLmQu0VoZMYwlQq0EZQSjjT5V-VQv6Y4JAEFCvHIxWGYIrQisMjJNdcI0zXt5UlKAVehaheuiFN_6DtPwEV9Qaror6TeqE_8xqQgnNa3jqkAgn6GbTehEe4VZ9UjJkeBUk_kYDo6Dege2CwDc5FL-b7M_v0rbP93sgknUq9-leRFjvyqTKsiop0qivG6y6qkq46JpuL_dtK5osk4koqy6rRNpFquYJzxLOk12RZ3wXF0lZVkWTt4I3ZZk1LEtwEErHWi-Dv5Ii5dyMdcXTahdp0aB24Ybj3OAVQtCPan6KptqfeWrmi2NZopUj90AhRRrr35RzKMGOpAb1QwTP0gNIFPKLvkMjwgkDo3VONRrXYVbm8rS2O7jm_AwI87qBBo0L6jiaJ_3xylXUz03c2oHxs-d4-3saJ_sXtsT4OShzjJ-D8v8CAAD__388wdo">