[Mlir-commits] [mlir] [mlir][SPIR-V] Fix math.powf lowering for non-integer exponents (PR #197727)
Arseniy Obolenskiy
llvmlistbot at llvm.org
Fri May 15 08:32:24 PDT 2026
================
@@ -360,75 +362,86 @@ struct PowFOpPattern final : public OpConversionPattern<math::PowFOp> {
if (!dstType)
return failure();
- // Get the scalar float type.
- FloatType scalarFloatType;
- if (auto scalarType = dyn_cast<FloatType>(powfOp.getType())) {
- scalarFloatType = scalarType;
- } else if (auto vectorType = dyn_cast<VectorType>(powfOp.getType())) {
- scalarFloatType = cast<FloatType>(vectorType.getElementType());
- } else {
- return failure();
+ Location loc = powfOp.getLoc();
+ auto operandType = adaptor.getRhs().getType();
+
+ // Parity-based lowering requires an integer-valued constant exponent.
+ // Otherwise fall back to exp(y*log(x)), which yields NaN for x<0 (matches
+ // C).
+ auto isOdd = [](const APFloat &v) {
+ APSInt i(/*BitWidth=*/64, /*isUnsigned=*/false);
+ bool ignored;
+ v.convertToInteger(i, APFloat::rmTowardZero, &ignored);
+ return i[0];
+ };
+
+ Attribute rhsAttr;
+ SmallVector<bool> oddMask;
+ bool isIntegerValued = false;
+ if (matchPattern(adaptor.getRhs(), m_Constant(&rhsAttr))) {
+ isIntegerValued = TypeSwitch<Attribute, bool>(rhsAttr)
----------------
aobolensk wrote:
> Maybe make it back into lambda with `oddMask` captured?
That helps, thanks
https://github.com/llvm/llvm-project/pull/197727
More information about the Mlir-commits
mailing list