On Fri, Oct 15, 2021 at 11:15 AM Eric Botcazou via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Hi, > > in order to make it possible to vectorize loops running over arrays in Ada, > which generally contain index checks, hence control-flow instructions, we rely > on loop unswitching to generate two copies of the loop, one guarded with a > global condition (no index check fails in the loop) and vectorizable and one > with the original index checks and non-vectorizable. This is achieved by the > simple trick of prepending the global_condition to the condition of the index > checks and letting the loop unswitching pass do its magic. > > But there is an enemy, namely if-combining, which can turn a simple boolean > conjunction into something else that loop unswitching cannot deal with, and a > testcase is attached with 3 slightly different versions of the same issue. > > Therefore the attached patch attempts to tame if-combining by reasoning on the > loop invariant status (really loop depths) of the conditions. > > Bootstrapped/regtested on x86-64/Linux, OK for the mainline?
Hmm, I see the issue. This heuristic probably defeats associating the combined conditions to "good" order? That is, it looks to me that eventually teaching unswitching to unswitch on comparisons [feeding GIMPLE_CONDs] would solve the issue as well? Martin was working on generalizing the code to handle switches so eventually he can look into also handling condition parts. That said, reassoc does order the outermost loop invariant conditions in the leaf of the condition chain, no? So, for (i;;) { bool a = inv < 0; bool b = i > 3; bool c = a && b; if (c) ... } could be unswitched as if (inv < 0) for (i;;) { bool a = true; bool b = i > 3; bool c = a && b; if (c) ... } else for (i;;) { bool a = false; bool b = i > 3; bool c = a && b; if (c) ... } > > 2021-10-15 Eric Botcazou <ebotca...@adacore.com> > > * tree-ssa-ifcombine.c: Include cfgloop.h. > (operand_loop_depth): New function. > (ifcombine_ifandif): When loop unswitching is enabled, do not merge > conditions whose loop invariant status is different. > > > 2021-10-15 Eric Botcazou <ebotca...@adacore.com> > > * gnat.dg/vect19.ads, gnat.dg/vect19.adb: New test. > > -- > Eric Botcazou