if-to-switch pass avoids merging anti-range IORs
GCC's if-to-switch pass now correctly handles conditions involving anti-ranges, fixing incorrect case generation for switch statements.
A bug in GCC’s if-to-switch optimization pass has been fixed, preventing it from incorrectly merging ‘anti-ranges’ in logical OR conditions. The pass previously mishandled conditions like (x not in R1) | (x not in R2), leading to generated switch cases that covered the union of R1 and R2 instead of their intersection. This resulted in some values reaching the wrong code path. The fix ensures that IOR conditions are only merged if they involve ‘IN_P’ ranges, guaranteeing correct switch case generation.
In Details
The gimple-if-to-switch.cc pass aims to convert complex conditional logic into efficient switch statements. This commit addresses a flaw in find_conditions where it incorrectly processed ORed 'anti-ranges' (i.e., NOT IN conditions). When combining two anti-ranges, the resulting set of values is the complement of the union of the individual ranges. The pass erroneously generated switch cases based on the union, causing values outside the intersection but within the union to be misrouted. The fix restricts the merging of IOR conditions to only those where all operands are 'IN_P' ranges, e…
- if-to-switch
- A GCC optimization pass that transforms conditional logic (
ifstatements) into more efficientswitchstatements when applicable. - IOR
- Logical Inclusive OR operation.
- anti-range
- In the context of GCC's range analysis, an 'anti-range' represents values that are *not* within a specified range.
- IN_P
- A flag or status indicating that a value or range is within a specified set or condition.
- SSA name
- Static Single Assignment form, an intermediate representation where every variable is assigned exactly once.