Thanks Robin. is_gimple_constant makes more senes. Committed with addressing your comments.
juzhe.zh...@rivai.ai From: Robin Dapp Date: 2024-01-05 17:54 To: Juzhe-Zhong; gcc-patches CC: rdapp.gcc; kito.cheng; kito.cheng; jeffreyalaw Subject: Re: [PATCH] RISC-V: Teach liveness computation loop invariant shift amount[Dynamic LMUL] > 1). We not only have vashl_optab,vashr_optab,vlshr_optab which vectorize > shift with vector shift amount, > that is, vectorization of 'a[i] >> x[i]', the shift amount is loop variant. > 2). But also, we have ashl_optab, ashr_optab, lshr_optab which can vectorize > shift with scalar shift amount, > that is, vectorization of 'a[i] >> x', the shift amount is loop invariant. > > +static bool > +loop_invariant_op_p (class loop *loop, > + tree op) > +{ > + if (is_gimple_min_invariant (op)) > + return true; > + if (SSA_NAME_IS_DEFAULT_DEF (op) > + || !flow_bb_inside_loop_p (loop, gimple_bb (SSA_NAME_DEF_STMT (op)))) > + return true; > + return gimple_uid (SSA_NAME_DEF_STMT (op)) & 1; > +} > + Looks like this is straight from tree-ssa-loop-ch. Do we need is_gimple_min_invariant (is_gimple_constant could be sufficient?) and DEFAULT_DEF for our case? The rhs of a shift should never contain a default def? I'm not entirely happy about the "loop invariant" heuristic/proxy of the shift amount being vectorizable. That seems like something that could bite us in the future in case we do slp-like vectorization on loop-invariant (but varying) data. As it helps for now and is not a correctness issue I'd still tend to go forward with it. Regards Robin