In particular, it couldn't handle cases where lookup table constant
expressions involved bitcasts. This does not seem to come up
frequently in C++, but comes up reasonably often in Rust via
#[derive(Debug)].
Originally reported by pcwalton.
Differential D109565
Teach SimplifyCFG to fold switches into lookup tables in more cases. resistor on Sep 9 2021, 10:13 PM. Authored by
Details In particular, it couldn't handle cases where lookup table constant Originally reported by pcwalton.
Diff Detail
Event TimelineComment Actions Looks fine to me. Note that to trigger on Debug we also need the frontend changes at https://github.com/rust-lang/rust/pull/88832. Comment Actions Won't this also skip non-zero-offset GEP's?
Comment Actions Update based on comments to preserve original behavior of shouldBuildLookupTablesForConstant().
Comment Actions Update for comments.
|
Note that GEPs are already handled below, so we should either drop that handling, or handle bitcasts in the same way. The current GEP handling uses "no notional overindexing" as the condition, which I agree is an unnecessary requirement here -- your choice of "inbounds with constant offsets" is the right one. Whether there is notional overindexing really shouldn't matter in this context, the relocation only cares about offsets.
However, something your implementation changes is that shouldBuildLookupTablesForConstant() no longer gets called on the original constant, only on the stripped one. It looks like only ARM uses this hook and wouldn't be affected by the change (because the stripped bitcasts/GEPs do not affect whether the constant requires relocation), but I think it would be in the spirit of the hook to continue calling it on the original constant.