On Mon, Oct 12, 2020 at 3:02 PM Martin Liška <mli...@suse.cz> wrote: > > On 10/12/20 2:44 PM, Martin Liška wrote: > > On 10/7/20 10:00 AM, Richard Biener wrote: > >> As said I'd have a BB-local pass over BBs recording the index variable > >> and the range covered by the BBs gcond, plus recording how many excess > >> stmts there are for eventual code motion. > >> > >> Only after that BB-local pass start to group BBs in a walk from dominated > >> to > >> dominating BBs looking for common indexes and building a case vector. > >> > >> The main thing is to avoid repeatedly analyzing BBs conditions (so the > >> first > >> pass could be also a on-demand precompute thing) and making the > >> case vector build optimal. > > > > I have a patch that does that using the infrastructure from > > tree-ssa-reassoc. > > Now I would like to implement the code hoisting. Am I right that we want > > something like: > > > > if (index == C0) > > goto BB_0; > > else > > { > > BB1_to_hoist_stmts; > > if (index == C1) > > goto BB_1; > > else > > { > > BB2_to_hoist_stmts; > > if (index == C2) > > goto BB_2; > > else > > goto default_BB; > > } > > } > > > > be converted into: > > > > switch(index) > > { > > case C0: > > goto BB_0; > > case C1: > > BB1_to_hoist_stmts; > > goto BB_1; > > case C2: > > BB1_to_hoist_stmts; > > BB2_to_hoist_stmts; > > goto BB_2; > > else: > > BB1_to_hoist_stmts; > > BB2_to_hoist_stmts; > > goto default_BB; > > } > > > > ? > > Reading again Richi's comment: > > > ifcombine simply hoists any stmts without side-effects up the > > dominator tree and thus only requires BBs without side-effects > > (IIRC there's a predicate fn for that). > > we likely want to hoist the statements "up" to the gswitch BB?
Yes. code sinking later will sink what can be sunk. > Martin > > > > > Thanks, > > Martin >