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

Sohaib Iftikhar llvmlistbot at llvm.org
Fri Apr 24 04:48:30 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:

It could be used explicitly in that case.

In any case this is not an issue anymore. I was able to patch it internally. Was not used in too many places.

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


More information about the Mlir-commits mailing list