[clang] [CIR] Upstream CreateOp for ComplexType with folder (PR #143192)

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 9 06:18:13 PDT 2025


================
@@ -1641,6 +1641,34 @@ LogicalResult cir::VecTernaryOp::verify() {
   return success();
 }
 
+//===----------------------------------------------------------------------===//
+// ComplexCreateOp
+//===----------------------------------------------------------------------===//
+
+LogicalResult cir::ComplexCreateOp::verify() {
+  if (getType().getElementType() != getReal().getType()) {
+    emitOpError()
+        << "operand type of cir.complex.create does not match its result type";
+    return failure();
+  }
+
+  return success();
+}
+
+OpFoldResult cir::ComplexCreateOp::fold(FoldAdaptor adaptor) {
+  mlir::Attribute real = adaptor.getReal();
+  mlir::Attribute imag = adaptor.getImag();
+  if (!real || !imag)
+    return {};
+
+  // When both of real and imag are constants, we can fold the operation into an
+  // `#cir.const_complex` operation.
----------------
bcardosolopes wrote:

Thanks for adding a folder :) 

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


More information about the cfe-commits mailing list