Open wangpc-pp opened 9 months ago
@llvm/issue-subscribers-backend-risc-v
Author: Wang Pengcheng (wangpc-pp)
The last example can be optimized with full use of ISD nodes instead of mixing in intrinsics.
v16xi32 add(v16xi32 a, v16xi8 b) {
v16xi32 c = __builtin_convertvector(b, v16xi32);
return a + c;
}
But when GISel is supported, we may need to do all the optimizations on GIR again? Or should we move all optimizations to later MIR passes?
RISCVFoldMasks and #71764 is an effort to move some of the SelectionDAG code out into MIR passes.
We can't optimize vzext.vf2+vadd.vv to vwaddu.wv, because we lower these intrinsics to RVV pseudos directly.
I can't remember where I first heard this argument, but I think there was a question as to whether or not intrinsics should be optimised away? Since there might be the expectation that if the user writes __riscv_vzext_vf2_u16m2
then there should be a vzext.vf2
in the resulting code.
The last example can be optimized with full use of ISD nodes instead of mixing in intrinsics.
v16xi32 add(v16xi32 a, v16xi8 b) { v16xi32 c = __builtin_convertvector(b, v16xi32); return a + c; }
Thanks! I think my unawareness of this just shows these potential missed optimizations. 😄
But when GISel is supported, we may need to do all the optimizations on GIR again? Or should we move all optimizations to later MIR passes?
RISCVFoldMasks and #71764 is an effort to move some of the SelectionDAG code out into MIR passes.
Yeah! Thanks for mentioning these works!
We can't optimize vzext.vf2+vadd.vv to vwaddu.wv, because we lower these intrinsics to RVV pseudos directly.
I can't remember where I first heard this argument, but I think there was a question as to whether or not intrinsics should be optimised away? Since there might be the expectation that if the user writes
__riscv_vzext_vf2_u16m2
then there should be avzext.vf2
in the resulting code.
As my example shows, we have already broken this convention for vmv.v.x
intrinsics now.
Not directly related to this, but I'm not sure HasOptimizedZeroStrideLoad
should default to true.
Not directly related to this, but I'm not sure
HasOptimizedZeroStrideLoad
should default to true.
See https://reviews.llvm.org/D137699. cc @preames
In the SelectionDAG level, we have several code paths to generate RVV pseudos:
Most of the optimizations for RVV are based on RISCVISD nodes, so we may miss some opportunities to optimize some codes. For example (https://godbolt.org/z/f1jWEfhG7):
These two snippets are of same assemblies because we lower intrinsics of
vmv.v.x
toRISCVISD::VMV_V_X
first, and then we can optimize it to zero-stride load if profitable. But, this is not common for other cases:We can't optimize
vzext.vf2+vadd.vv
tovwaddu.wv
, because we lower these intrinsics to RVV pseudos directly. Of cource, there is the same problem forISD->RVV pseudos
path:I think we need to an universal representation (RISCVISD?) to do optimizations. But when GISel is supported, we may need to do all the optimizations on GIR again? Or should we move all optimizations to later MIR passes?