[Mlir-commits] [mlir] [mlir][spirv] Add folding for SelectOp (PR #85430)

Finn Plummer llvmlistbot at llvm.org
Tue Mar 19 12:19:47 PDT 2024


================
@@ -801,16 +801,18 @@ OpFoldResult spirv::LogicalOrOp::fold(FoldAdaptor adaptor) {
 // spirv.SelectOp
 //===----------------------------------------------------------------------===//
 
-template <class AttrElementT,
-          class ElementValueT = typename AttrElementT::ValueType>
-static Attribute foldSelections(const ElementsAttr &condAttrs,
-                                const ElementsAttr &trueAttrs,
-                                const ElementsAttr &falseAttrs) {
+static Attribute foldSelectOp(ArrayRef<Attribute> operands) {
+  auto condAttrs = dyn_cast<DenseElementsAttr>(operands[0]);
+  auto trueAttrs = dyn_cast<DenseElementsAttr>(operands[1]);
+  auto falseAttrs = dyn_cast<DenseElementsAttr>(operands[2]);
+  if (!condAttrs || !trueAttrs || !falseAttrs)
+    return Attribute();
+
   auto condsIt = condAttrs.value_begin<BoolAttr>();
-  auto trueAttrsIt = trueAttrs.value_begin<ElementValueT>();
-  auto falseAttrsIt = falseAttrs.value_begin<ElementValueT>();
+  auto trueAttrsIt = trueAttrs.value_begin<Attribute>();
+  auto falseAttrsIt = falseAttrs.value_begin<Attribute>();
 
-  SmallVector<ElementValueT, 4> elementResults;
+  SmallVector<Attribute, 4> elementResults;
   elementResults.reserve(condAttrs.getNumElements());
   for (size_t i = 0, e = condAttrs.getNumElements(); i < e;
----------------
inbelic wrote:

Oh nice!

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


More information about the Mlir-commits mailing list