[clang] [CIR] Upstream ShuffleDynamicOp for VectorType (PR #141411)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Wed May 28 11:40:07 PDT 2025
================
@@ -1871,6 +1872,54 @@ mlir::LogicalResult CIRToLLVMVecCmpOpLowering::matchAndRewrite(
return mlir::success();
}
+mlir::LogicalResult CIRToLLVMVecShuffleDynamicOpLowering::matchAndRewrite(
+ cir::VecShuffleDynamicOp op, OpAdaptor adaptor,
+ mlir::ConversionPatternRewriter &rewriter) const {
+ // LLVM IR does not have an operation that corresponds to this form of
+ // the built-in.
+ // __builtin_shufflevector(V, I)
+ // is implemented as this pseudocode, where the for loop is unrolled
+ // and N is the number of elements:
+ // masked = I & (N-1)
----------------
andykaylor wrote:
This is not quite what the classic codegen does, and I think it will be wrong for non-power-of-two vector sizes. The classic codegen uses a mask value that is equal to X - 1 where X is the next power of two above 'N - 1'. So if the number of elements is a power of two, it will be equivalent to the code here, but if not, it will mask differently.
See https://godbolt.org/z/c764a1T5v
https://github.com/llvm/llvm-project/pull/141411
More information about the cfe-commits
mailing list