================
@@ -114,19 +92,42 @@ void LoweringPreparePass::lowerCastOp(cir::CastOp op) {
     break;
 
   case cir::CastKind::float_complex_to_real:
-  case cir::CastKind::int_complex_to_real:
-  case cir::CastKind::float_complex_to_bool:
+  case cir::CastKind::int_complex_to_real: {
+    loweredValue = lowerComplexToScalarCast(getContext(), op, op.getKind());
+    break;
+  }
+
+  case cir::CastKind::float_complex_to_bool: {
+    loweredValue = lowerComplexToScalarCast(getContext(), op,
+                                            cir::CastKind::float_to_bool);
+    break;
+  }
   case cir::CastKind::int_complex_to_bool: {
-    loweredValue = lowerComplexToScalarCast(getContext(), op);
+    loweredValue =
+        lowerComplexToScalarCast(getContext(), op, cir::CastKind::int_to_bool);
     break;
   }
 
-  case cir::CastKind::float_complex:
-  case cir::CastKind::float_complex_to_int_complex:
-  case cir::CastKind::int_complex:
-  case cir::CastKind::int_complex_to_float_complex:
-    loweredValue = lowerComplexToComplexCast(getContext(), op);
+  case cir::CastKind::float_complex: {
+    loweredValue =
+        lowerComplexToComplexCast(getContext(), op, cir::CastKind::floating);
+    break;
+  }
+  case cir::CastKind::float_complex_to_int_complex: {
+    loweredValue = lowerComplexToComplexCast(getContext(), op,
+                                             cir::CastKind::float_to_int);
     break;
+  }
+  case cir::CastKind::int_complex: {
+    loweredValue =
+        lowerComplexToComplexCast(getContext(), op, cir::CastKind::integral);
+    break;
+  }
+  case cir::CastKind::int_complex_to_float_complex: {
+    loweredValue = lowerComplexToComplexCast(getContext(), op,
+                                             cir::CastKind::int_to_float);
+    break;
+  }
----------------
xlauko wrote:

Use immediately invoked lambda here and getContext beforehand, it will be way 
nicer :)

Something like this:

```cpp
void LoweringPreparePass::lowerCastOp(cir::CastOp op) {
  mlir::MLIRContext *ctx = getContext();
  Value loweredValue = [&]() -> Value {
    switch (op.getKind()) {
    case cir::CastKind::float_to_complex:
    case cir::CastKind::int_to_complex:
      return lowerScalarToComplexCast(ctx, op);
    case cir::CastKind::float_complex_to_real:
    case cir::CastKind::int_complex_to_real:
      return lowerComplexToScalarCast(ctx, op, op.getKind());
    case cir::CastKind::float_complex_to_bool:
      return lowerComplexToScalarCast(ctx, op, cir::CastKind::float_to_bool);
    case cir::CastKind::int_complex_to_bool:
      return lowerComplexToScalarCast(ctx, op, cir::CastKind::int_to_bool);
    case cir::CastKind::float_complex:
      return lowerComplexToComplexCast(ctx, op, cir::CastKind::floating);
    case cir::CastKind::float_complex_to_int_complex:
      return lowerComplexToComplexCast(ctx, op, cir::CastKind::float_to_int);
    case cir::CastKind::int_complex:
      return lowerComplexToComplexCast(ctx, op, cir::CastKind::integral);
    case cir::CastKind::int_complex_to_float_complex:
      return lowerComplexToComplexCast(ctx, op, cir::CastKind::int_to_float);
    default:
      return nullptr;
    }
  }();

  if (loweredValue) {
    op.replaceAllUsesWith(loweredValue);
    op.erase();
  }
}
```

https://github.com/llvm/llvm-project/pull/149717
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to