[clang] [CIR] Upstream ComplexType builtin_complex (PR #144225)

Sirui Mu via cfe-commits cfe-commits at lists.llvm.org
Sat Jun 14 07:49:40 PDT 2025


================
@@ -44,6 +68,15 @@ void ComplexExprEmitter::emitStoreOfComplex(mlir::Location loc, mlir::Value val,
   builder.createStore(loc, val, destAddr);
 }
 
+mlir::Value ComplexExprEmitter::VisitCallExpr(const CallExpr *e) {
+  if (e->getCallReturnType(cgf.getContext())->isReferenceType())
+    return emitLoadOfLValue(e);
+
+  mlir::Location loc = cgf.getLoc(e->getExprLoc());
+  auto complex = cgf.emitCallExpr(e).getComplexVal();
+  return builder.createComplexCreate(loc, complex.first, complex.second);
----------------
Lancern wrote:

Call to functions that returns a complex value should result in a single `mlir::Value` that represents the complex value. #142779 modifies `RValue` and uses two `mlir::Value`s to represent a complex rvalue, which could result in unnecessary complex unpacking and packing operations.

I suggest we follow the incubator's approach and update the definition of `RValue`. Instead of using two `mlir::Value`s to represent a complex rvalue, use just one `mlir::Value` (just like how it represents a regular scalar value).

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


More information about the cfe-commits mailing list