[SAOC 2026] MLIR support Weekly Update #7

Asadbek aosindarov at gmail.com
Fri Nov 6 22:32:55 UTC 2026


Hello everyone,

This week, I worked on expanding last week's integer arithmetic 
for MLIR lowering support in LDC. I also added support for 
floating-point types (`float` and `double`) and handled 
signedness properly this time.

LDC can now lower the following D code:

```d
void do_something() {}

double fadd(double a, double b) { return a + b; }
float fsub(float a, float b) { return a - b; }
double fmul(double a, double b) { return a * b; }
float fdiv(float a, float b) { return a / b; }
double fmod_(double a, double b) { return a % b; }

double prec(double a, double b) { return a - b / a % b; }
double two() { return 2.5; }

double fromI(int a) { return a; }
double fromU(uint a) { return a; }

```

into this MLIR output:

```mlir
module {
   func.func @_D4test12do_somethingFZv() {
     return
   }
   func.func @_D4test4faddFddZd(%arg0: f64, %arg1: f64) -> f64 {
     %0 = arith.addf %arg0, %arg1 : f64
     return %0 : f64
   }
   func.func @_D4test4fsubFffZf(%arg0: f32, %arg1: f32) -> f32 {
     %0 = arith.subf %arg0, %arg1 : f32
     return %0 : f32
   }
   func.func @_D4test4fmulFddZd(%arg0: f64, %arg1: f64) -> f64 {
     %0 = arith.mulf %arg0, %arg1 : f64
     return %0 : f64
   }
   func.func @_D4test4fdivFffZf(%arg0: f32, %arg1: f32) -> f32 {
     %0 = arith.divf %arg0, %arg1 : f32
     return %0 : f32
   }
   func.func @_D4test5fmod_FddZd(%arg0: f64, %arg1: f64) -> f64 {
     %0 = arith.remf %arg0, %arg1 : f64
     return %0 : f64
   }
   func.func @_D4test4precFddZd(%arg0: f64, %arg1: f64) -> f64 {
     %0 = arith.divf %arg1, %arg0 : f64
     %1 = arith.remf %0, %arg1 : f64
     %2 = arith.subf %arg0, %1 : f64
     return %2 : f64
   }
   func.func @_D4test3twoFZd() -> f64 {
     %cst = arith.constant 2.500000e+00 : f64
     return %cst : f64
   }

   func.func @_D4test5fromIFiZd(%arg0: i32) -> f64 {
     %0 = arith.sitofp %arg0 : i32 to f64
     return %0 : f64
   }
   func.func @_D4test5fromUFkZd(%arg0: i32) -> f64 {
     %0 = arith.uitofp %arg0 : i32 to f64
     return %0 : f64
   }

}
```

This is just a small sample. I've also built out a larger test 
suite covering additional binary operations while working on this.

As a next step, I am working on comparison expressions, local 
variables, and lexical scopes (to ensure stack variables are 
properly cleaned up when a scope exits). Having variable and 
scope management in place is a prerequisite before I can move on 
to control flow constructs like if statements and loops. Once 
loops are working, I'd like to experiment with automatically 
lowering eligible loops to scf.parallel. Thanks to Nicholas for 
the idea!

Feedback and questions are welcome!

Best,
Asadbek


More information about the Digitalmars-d mailing list