[Mlir-commits] [mlir] [mlir][math] Add constant folding for `math.fpowi` (PR #193761)

Sohaib Iftikhar llvmlistbot at llvm.org
Fri Apr 24 04:10:51 PDT 2026


================
@@ -159,44 +164,49 @@ Attribute constFoldBinaryOpConditional(ArrayRef<Attribute> operands,
   Type rhsType = getAttrType(operands[1]);
   if (!lhsType || !rhsType)
     return {};
-  if (lhsType != rhsType)
-    return {};
+  if constexpr (std::is_same_v<LElementValueT, RElementValueT>)
+    if (lhsType != rhsType)
+      return {};
 
-  return constFoldBinaryOpConditional<AttrElementT, ElementValueT, PoisonAttr,
-                                      ResultAttrElementT, ResultElementValueT,
-                                      CalculationT>(
+  return constFoldBinaryOpConditional<
+      LAttrElementT, RAttrElementT, LElementValueT, RElementValueT, PoisonAttr,
+      ResultAttrElementT, ResultElementValueT, CalculationT>(
       operands, lhsType, std::forward<CalculationT>(calculate));
 }
 
-template <class AttrElementT,
-          class ElementValueT = typename AttrElementT::ValueType,
+template <class LAttrElementT, class RAttrElementT = LAttrElementT,
+          class LElementValueT = typename LAttrElementT::ValueType,
+          class RElementValueT = typename RAttrElementT::ValueType,
           class PoisonAttr = void, //
-          class ResultAttrElementT = AttrElementT,
+          class ResultAttrElementT = LAttrElementT,
           class ResultElementValueT = typename ResultAttrElementT::ValueType,
           class CalculationT =
-              function_ref<ResultElementValueT(ElementValueT, ElementValueT)>>
+              function_ref<ResultElementValueT(LElementValueT, RElementValueT)>>
 Attribute constFoldBinaryOp(ArrayRef<Attribute> operands, Type resultType,
                             CalculationT &&calculate) {
-  return constFoldBinaryOpConditional<AttrElementT, ElementValueT, PoisonAttr,
-                                      ResultAttrElementT>(
+  return constFoldBinaryOpConditional<LAttrElementT, RAttrElementT,
+                                      LElementValueT, RElementValueT,
+                                      PoisonAttr, ResultAttrElementT>(
       operands, resultType,
-      [&](ElementValueT a, ElementValueT b)
+      [&](LElementValueT a, RElementValueT b)
----------------
sohaibiftikhar wrote:

Sorry that was a premature comment. Its just a template instantiations of dependent code. For instance.

```
constFoldBinaryOp<FloatAttr, FloatAttr::ValueType, void, IntegerAttr>(
```

Now needs to be changed to.
```
constFoldBinaryOp<FloatAttr, FloatAttr, FloatAttr::ValueType,
FloatAttr::ValueType, void, IntegerAttr>
```

Which broke compilation downstream. Perhaps it would made sense to add a default specialization for this that redirects to the other.

https://github.com/llvm/llvm-project/pull/193761


More information about the Mlir-commits mailing list