https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97515
--- Comment #2 from Andrew Macleod <amacleod at redhat dot com> --- Created attachment 49417 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49417&action=edit check for undefined before not returning a constant value The ranger deals with UNDEFINED slightly differently than traditional EVRP, which is exposed in this PR. An UNDEFINED value can be calculated in unreachable code. ie bb5: a_3 = 5 if (a_3 < 0) goto bb6 else goto bb9 bb6: z_8 = a_3 the edge 5->6 cannot be taken, Calculating the range for a_3 on this edge is calculated by taking the outgoing edge range of [-INF, -1] and intersecting it with the known range of [5, 5]. Which is [] or undefined. The value has no meaning on that edge since the edge can't be taken. The substitute_and_fold engine is driven by replacing values with their constant equivalent. It does so only as a statement is visited. When it gets to z_8 = a_3, the ranger was returning a range of [] AKA undefined instead of [5,5] so the use of a_3 was not being replaced by subst_and_fold in this block. This results in a reference to a_3 being left in the IL.. and chaos ensues. The simple solution to this is to adjust the way value_of() is calculated on ranges from the ranger. If the resulting range is UNDEFINED from a query, do a quick check of the global value and if its a constant, return that. This has been a lagging issue that pops up from time to time which is nicely demonstrated in this PR. This patch is undergoing testing currently