[llvm] [VPlan] Fold safe divisors into VP intrinsics with EVL (PR #148828)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 21 07:49:40 PDT 2025
https://github.com/preames commented:
High level comment, mostly exploring options.
I'm not sure this can't be done profitably in the backend. The key thing we can exploit is that the div instruction has a passthru operand. (Note that the vp node doesn't expose that.)
Given the passthru operand which starts as poison/undef, any div by a lane which can be proven to be one can be replaced by a passthru operand equal to the LHS, with a predicate (either mask or VL) which is inactive when the RHS would have been 1.
At least in principle, it seems like we should be able to do this as a DAG combine. The main question I haven't dug into is the timing of the lowering of the vp.merge vs the the sdiv. My idea here requires a point where we have the full complexity of a RISCV vdiv node, while being able to analyze the merge.
Unfortunately, I agree this can't easily be done in RISCVCodeGenPrepare. Without the passthru operand on the vp.sdiv, we'd need to do a demanded lane analysis to prove the tail lands can be changed to poison. Hm, we could reverse the order of the sdiv and merge here (by using vp.sdiv and duplicating the masking), would doing that let existing optimizations prune the merge?
https://github.com/llvm/llvm-project/pull/148828
More information about the llvm-commits
mailing list