[clang] [llvm] [RISCV][P-ext] Add scalar merge intrinsics (PR #239119)
Sam Elliott via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 10 16:51:05 PST 2026
================
@@ -983,6 +983,31 @@ __riscv_wzip16p_64(uint32_t __rs1, uint32_t __rs2) {
return (uint64_t)__riscv_pzip_u16x4((uint16x2_t)__rs1, (uint16x2_t)__rs2);
}
+/* Scalar Merge */
+static __inline__ int32_t __DEFAULT_FN_ATTRS
+__riscv_merge_i32(int32_t __rs1, int32_t __rs2, uint32_t __rd) {
+ return (int32_t)__builtin_riscv_merge_u32((uint32_t)__rs1, (uint32_t)__rs2,
+ __rd);
----------------
lenary wrote:
Sorry, I want to re-open this discussion as I'm not sure we should have a middle-end intrinsic for this. I don't mind about the builtin, frankly.
The downside of an intrinsic is that we have to teach all the optimisations about it, so we get constant folding and the like. This is much easier to maintain.
The up-side is the pattern isn't broken, which is arguably better for users avoiding regressions or some odd emergent behaviours when those optimisations intersect.
I don't know exactly the right trade-off here. One thing I thought of is trying to support something like `__builtin_ct_select` with this builtin, but... a user can just use that and its intrinsic is already implemented (though, the lowering may not be great with the P extension yet).
https://github.com/llvm/llvm-project/pull/239119
More information about the cfe-commits
mailing list