https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119039
Bug ID: 119039 Summary: Improve simplify_switch_using_ranges Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: jakub at gcc dot gnu.org CC: aldyh at gcc dot gnu.org, amacleod at redhat dot com, jakub at gcc dot gnu.org, sjames at gcc dot gnu.org, unassigned at gcc dot gnu.org, yunboni at smail dot nju.edu.cn Depends on: 118953 Target Milestone: --- +++ This bug was initially created as a clone of Bug #118953 +++ simplify_switch_using_ranges and the find_case* functions it calls use just get_legacy_range and optimize just based on the first low_bound and last upper_bound or special case VR_ANTI_RANGE in the legacy. That way it optimizes away case labels completely outside of that legacy range and perhaps adjusts case ranges at the borders of those. But if it worked on int_range_max instead, it could do the same for all the subranges too, i.e. optimize away case labels completely in between the subranges or adjust case ranges on the borders of the subranges. Furthermore, as mentioned in PR118953, it could also look at irange_bitmask and also optimize out cases which obviously don't satisfy the irange_bitmask (e.g. if the controlling expression has MASK 0xfffff000 VALUE 0x2d, then any cases where the low 12 bits aren't equal to 0x2d are unreachable). Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118953 [Bug 118953] [14/15 regression] Miscompile at -O2 since r14-2473-g602e824eec30a7