[Mlir-commits] [mlir] [mlir][spirv] Update math.powf lowering (PR #111388)
Jakub Kuderski
llvmlistbot at llvm.org
Mon Oct 7 13:16:40 PDT 2024
================
@@ -377,40 +377,40 @@ struct PowFOpPattern final : public OpConversionPattern<math::PowFOp> {
// Get int type of the same shape as the float type.
Type scalarIntType = rewriter.getIntegerType(32);
Type intType = scalarIntType;
- if (auto vectorType = dyn_cast<VectorType>(adaptor.getRhs().getType())) {
+ auto exponentType = adaptor.getRhs().getType();
+ if (auto vectorType = dyn_cast<VectorType>(exponentType)) {
auto shape = vectorType.getShape();
intType = VectorType::get(shape, scalarIntType);
}
// Per GL Pow extended instruction spec:
// "Result is undefined if x < 0. Result is undefined if x = 0 and y <= 0."
Location loc = powfOp.getLoc();
- Value zero =
- spirv::ConstantOp::getZero(adaptor.getLhs().getType(), loc, rewriter);
+ auto baseType = adaptor.getLhs().getType();
+ Value zero = spirv::ConstantOp::getZero(baseType, loc, rewriter);
Value lessThan =
rewriter.create<spirv::FOrdLessThanOp>(loc, adaptor.getLhs(), zero);
- // Per C/CPP spec:
- // "pow(base, exponent) returns NaN (and raises FE_INVALID) if base is "
- // " finite and negative and exponent is finite and non-integer. "
- // Calculae calc reminder from exponent and check whether it is zero
- Value floatOne =
- spirv::ConstantOp::getOne(adaptor.getRhs().getType(), loc, rewriter);
+ // Per C/C++ spec:
+ // > pow(base, exponent) returns NaN (and raises FE_INVALID) if base is
+ // > finite and negative and exponent is finite and non-integer.
+ // Calculate the reminder from the exponent and check whether it is zero.
+ Value floatOne = spirv::ConstantOp::getOne(exponentType, loc, rewriter);
Value expRem =
rewriter.create<spirv::FRemOp>(loc, adaptor.getRhs(), floatOne);
Value expRemNonZero =
rewriter.create<spirv::FOrdNotEqualOp>(loc, expRem, zero);
Value cmpNegativeWithFractionalExp =
rewriter.create<spirv::LogicalAndOp>(loc, expRemNonZero, lessThan);
- // Create NaN result and replace base value if conditions meet
+ // Create NaN result and replace base value if conditions are met
----------------
kuhar wrote:
```suggestion
// Create NaN result and replace base value if conditions are met.
```
https://github.com/llvm/llvm-project/pull/111388
More information about the Mlir-commits
mailing list