================
@@ -2330,6 +2330,28 @@ OpFoldResult cir::SelectOp::fold(FoldAdaptor adaptor) {
 
   return {};
 }
+LogicalResult cir::SelectOp::verify() {
+  // INFO: No need to check if trueTy == falseTy here, it's verified by
+  // the AllTypesMatch trait already.
+  // We can go straight into getting the vector type.
+
+  auto condVecTy =
+      mlir::dyn_cast<cir::VectorType>(this->getCondition().getType());
+  auto trueVecTy =
+      mlir::dyn_cast<cir::VectorType>(this->getTrueValue().getType());
+  auto falseVecTy =
+      mlir::dyn_cast<cir::VectorType>(this->getFalseValue().getType());
+
+  if (condVecTy && (!trueVecTy || !falseVecTy)) {
+    // INFO: No need to check for size of vector here, it's verified by
+    // the AllTypesMatch trait already
+    return emitOpError()
+           << "second and third operand must both be of the same "
+              "vector type when"
+              " the conditional operand is of vector boolean type";
+  }
+  return mlir::success();
+}
----------------
xlauko wrote:

```suggestion
}

LogicalResult cir::SelectOp::verify() {
  // AllTypesMatch already guarantees trueVal and falseVal have matching types.
  auto condTy = dyn_cast<cir::VectorType>(getCondition().getType());

  // If condition is not a vector, no further checks are needed.
  if (!condTy)
    return success();

  // When condition is a vector, both other operands must also be vectors.
  if (!isa<cir::VectorType>(getTrueValue().getType()) ||
      !isa<cir::VectorType>(getFalseValue().getType())) {
    return emitOpError()
           << "expected both true and false operands to be vector types "
              "when the condition is a vector boolean type";
  }

  return success();
}
```

https://github.com/llvm/llvm-project/pull/170427
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to