Commit fd83ee9
[stdlib] Improve
The `InlineArray` copy/move constructors current implementation simply
looped through each element and moved/copied. This produced poor codegen
as it does not take advantage of any loop unrolling or checking if the
element types are trivial and simply copying the underlying MLIR
storage.
The previous codegen for a simple function:
```mojo
fn return_array() -> InlineArray[Int32, 4]:
var arr = InlineArray[Int32, 4](fill=0)
return arr^
```
produces this codegen:
```
define dso_local void @"test_inline_array::return_array"(ptr noalias noundef nonnull writeonly captures(none) %0) #0 !dbg !5 {
tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %0, i8 0, i64 16, i1 false), !dbg !90
tail call void asm sideeffect "nop", ""() #2, !dbg !91
ret void, !dbg !32
}
```
but now, we get this improved LLVM IR:
```
define dso_local void @"test_inline_array::_return_array"(ptr noalias noundef nonnull writeonly captures(none) initializes((0, 16)) %0) #0 !dbg !5 {
tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %0, i8 0, i64 16, i1 false), !dbg !51
ret void, !dbg !32
}
```
Notably there is no `asm sideffect "nop"` and an `initializes((0, 16))`
is on the `ptr` argument showing that the values do get initialized.
MODULAR_ORIG_COMMIT_REV_ID: 14efb85038ec4697b7e52a8b7beb76e2b48b09bcInlineArray move/copy for trivial types.1 parent 98c608a commit fd83ee9
2 files changed
Lines changed: 42 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
360 | 363 | | |
361 | 364 | | |
362 | 365 | | |
| |||
368 | 371 | | |
369 | 372 | | |
370 | 373 | | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
376 | 382 | | |
377 | 383 | | |
378 | 384 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
392 | 393 | | |
393 | 394 | | |
394 | 395 | | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
395 | 421 | | |
396 | 422 | | |
0 commit comments