On 9/1/24 9:47 AM, Filip Kastl wrote:
On Sun 2024-09-01 09:25:07, Jeff Law wrote:
On 9/1/24 9:19 AM, Filip Kastl wrote:
(I'm Cc-ing Diego since he originally contributed the VRP pass and Jeff because
I've seen him in git blame on many lines of vr-values.cc around the place I
would like to make modifications)
Hello,
In this RFC I'd like to propose the following: When the value range statement
simplification machinery encounters a switch with a default case that never
executes, it should mark the default case with __builtin_unreachable instead of
removing the default case. I think that should be the "canonical"
representation of switches with this property.
In terms of changes made to GCC code, this would be a small patch.
I'd like to hear other people's opinions on this. Perhaps there are
implications of this change or some other issues with the idea which I don't
see.
The right thing to do is to eliminate the unreachable code. We don't
replace the body of an if (0) with a __builtin_unreachable. We remove it.
Switch statements should be no different here.
If that inhibits later analysis or optimization then that's an indicator
that we need to improve our frameworks, not that we should keep dead code
lying around in the IL.
Jeff
I see. This is not the way forward. While reading your reply it occured to me
that it could be possible to use value range info in switch conversion to get
the switches in question optimized without relying on __bultin_unreachable.
I'll try that.
I think one of the problems we've got is that when we drop unreachable
paths it makes it much harder to reconstruct certain range information.
We've seen this on a few tests since the new Ranger framework went in.
I think that argues we need to handle this earlier, need to find a way
to either carry range information further, or recreate the more precise
range information later Your initial idea falls into that last bucket.
There may be other ways to do that. For example, we could actually
annotate the switch node with some additional data from the early
analysis/optimization -- without introducing the builtin_unreachable.
jeff