> So what I'm most worried about is that you modify only the > SLP_TREE_VECTYPE and that in-place. Both the SLP_TREE_SCALAR_STMTS > and the SLP_TREE_REPRESENTATIVE have contradicting info, so > I wonder how you get away without modifying the reduction epilogue > code. If that just works then it would be by chance, not by design.
Yeah, wouldn't disagree that it's hackish but from what I could see at least vect_create_epilog_for_reduction always converts to the scalar type so the "compensation" was already there. I went through some more usage sites and while there are surely still holes but I didn't manage to trigger them in a first attempt (likely because the "pass" is not doing a lot right now). > I see the scalar pattern approach isn't any easier as you'd have to > introduce pattern stmts for PHIs. Using SLP patterns would work > to some extent, but there's still the issue that the live lane for > the reduction epilog has a wrong type and we do not represent > compensation for that. So both those and your approach feel > like hacks. To add to that, my main issue about pattern matching, vect or SLP was that when deciding for a lower precision I'd also want to check the reduction operation. If, it feels like a higher-level pattern matching the whole chain, so more like something slp_optimize would do. > In the end I'm going to point to the pre-pass we have to facilitate > vectorization which is if-conversion. What I'd do is attempt to > narrow the reduction PHI and insert a compensation scalar conversion > at the loop exit. It should be possible to use check_reduction_path > to gather SSA cycles. Would you be ok with doing it in ifcvt? I guess there's precedent with bitfield lowering but... :) What I'm concerned about is that we don't know about patterns yet (SAD is not embarrassingly simple) and "always" reducing the precision would penalize targets that don't have a 2x but only a 4x SAD (x86?). For non-pattern operations like regular + it might be easier. In my initial attempt, I adjusted the vectype in vect_get_vector_types_for_stmt for those statements marked part of a narrowable cycle via STMT_VINFO_REDUC_PREC but that's not any prettier either as scalar and vector similarly disagree. -- Regards Robin
