[Mlir-commits] [mlir] [MLIR][NVVM] Add new narrow FP convert Ops (PR #184291)
Durgadoss R
llvmlistbot at llvm.org
Tue Mar 3 03:48:01 PST 2026
================
@@ -2164,6 +2242,99 @@ def NVVM_ConvertF6x2ToF16x2Op :
def NVVM_ConvertF4x2ToF16x2Op :
NVVM_ConvertToFP16x2Op_Base<"F4", I8, "F16">;
+def NVVM_ConvertF32x2ToS2F6x2Op : NVVM_Op<"convert.f32x2.to.s2f6x2"> {
+ let summary = "Convert a pair of f32 inputs to S2F6x2";
+ let description = [{
+ This Op converts each of the given f32 inputs to the
+ S2F6x2 type. The result `dst` can be an I16 or vector<2xi8>.
+ The `relu` attribute, when set, lowers to the '.relu' variant
+ of the cvt instruction. The optional scaling-factor for the
+ conversion is provided through the operand `scaleFactor`.
+ Only `ue8m0` is supported as the type of the scale-factor currently.
+ }];
+
+ let results = (outs AnyTypeOf<[I16, VectorOfLengthAndType<[2], [I8]>]>:$dst);
+ let arguments = (ins F32:$a, F32:$b,
+ Optional<I16>:$scaleFactor,
+ DefaultValuedAttr<BoolAttr, "false">:$relu);
+ let assemblyFormat =
+ "$a `,` $b (`,` $scaleFactor^)? attr-dict `:` type($dst)";
+ let extraClassDeclaration = [{
+ static IDArgPair getIntrinsicIDAndArgs(Operation &op,
+ LLVM::ModuleTranslation &mt, llvm::IRBuilderBase &builder);
+ }];
+
+ string llvmBuilder = [{
+ auto [id, args] = NVVM::ConvertF32x2ToS2F6x2Op::getIntrinsicIDAndArgs(*op, moduleTranslation, builder);
+ llvm::Value *packedI16 = createIntrinsicCall(builder, id, args);
+ if(op.getDst().getType().isInteger(16))
+ $dst = packedI16;
+ else
+ $dst = builder.CreateBitCast(packedI16,
+ llvm::FixedVectorType::get(llvm::Type::getInt8Ty(builder.getContext()), 2));
----------------
durga4github wrote:
Since there are many usages of this createBitCast, I wonder if we should add a Util function (in NVVMDialect.h) and just reuse it everywhere.. But that's for a separate PR (before or after this)
https://github.com/llvm/llvm-project/pull/184291
More information about the Mlir-commits
mailing list