[PATCH] D157204: [MLIR][Math] Add support for f16 in the expansion of math.roundeven

Rob Suderman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 16 15:08:26 PDT 2023


rsuderman added inline comments.


================
Comment at: mlir/lib/Dialect/Math/Transforms/ExpandPatterns.cpp:308
 
-  if (!operandETy.isF32() || !resultETy.isF32()) {
-    return rewriter.notifyMatchFailure(op, "not a roundeven of f32.");
+  if (!(operandETy.isF16() && resultETy.isF16()) &&
+      !(operandETy.isF32() && resultETy.isF32())) {
----------------
I would just check whether the operand / result types are floating point values. `isa<FloatType>(operandETy) && isa<FloatType>(resultETy)` should suffice.


================
Comment at: mlir/lib/Dialect/Math/Transforms/ExpandPatterns.cpp:314
+  Type fTy = operandTy;
+  Type iTy = operandETy.isF16() ? b.getI16Type() : b.getI32Type();
+  if (auto shapedTy = dyn_cast<ShapedType>(fTy)) {
----------------
`iTy = rewriter.getIntegerType(operandEty.getIntOrFloatBitWidth());`


================
Comment at: mlir/lib/Dialect/Math/Transforms/ExpandPatterns.cpp:319
 
-  Value c1Float = createFloatConst(loc, f32Ty, 1.0, b);
-  Value c0 = createIntConst(loc, i32Ty, 0, b);
-  Value c1 = createIntConst(loc, i32Ty, 1, b);
-  Value cNeg1 = createIntConst(loc, i32Ty, -1, b);
-  Value c23 = createIntConst(loc, i32Ty, 23, b);
-  Value c31 = createIntConst(loc, i32Ty, 31, b);
-  Value c127 = createIntConst(loc, i32Ty, 127, b);
-  Value c2To22 = createIntConst(loc, i32Ty, 1 << 22, b);
-  Value c23Mask = createIntConst(loc, i32Ty, (1 << 23) - 1, b);
-  Value expMask = createIntConst(loc, i32Ty, (1 << 8) - 1, b);
-
-  Value operandBitcast = b.create<arith::BitcastOp>(i32Ty, operand);
+  unsigned bitWidth = llvm::cast<FloatType>(operandETy).getWidth();
+  // The width returned by getFPMantissaWidth includes the integer bit.
----------------
there is a `getIntOrFloatBitWidth()` function that should help you.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157204/new/

https://reviews.llvm.org/D157204



More information about the llvm-commits mailing list