Commit 4c2af25
authored
aot compiler: Use larger alignment for load/store when possible (bytecodealliance#3552)
Consider the following wasm module:
```wast
(module
(func (export "foo")
i32.const 0x104
i32.const 0x12345678
i32.store
)
(memory 1 1)
)
```
While the address (0x104) is perfectly aligned for i32.store,
as our aot compiler uses 1-byte alignment for load/store LLVM
IR instructions, it often produces inefficient machine code,
especially for alignment-sensitive targets.
For example, the above "foo" function is compiled into the
following xtensa machine code.
```
0000002c <aot_func_internal#0>:
2c: 004136 entry a1, 32
2f: 07a182 movi a8, 0x107
32: 828a add.n a8, a2, a8
34: 291c movi.n a9, 18
36: 004892 s8i a9, a8, 0
39: 06a182 movi a8, 0x106
3c: 828a add.n a8, a2, a8
3e: ffff91 l32r a9, 3c <aot_func_internal#0+0x10> (ff91828a <aot_func_internal#0+0xff91825e>)
3e: R_XTENSA_SLOT0_OP .literal+0x8
41: 004892 s8i a9, a8, 0
44: 05a182 movi a8, 0x105
47: 828a add.n a8, a2, a8
49: ffff91 l32r a9, 48 <aot_func_internal#0+0x1c> (ffff9182 <aot_func_internal#0+0xffff9156>)
49: R_XTENSA_SLOT0_OP .literal+0xc
4c: 41a890 srli a10, a9, 8
4f: 0048a2 s8i a10, a8, 0
52: 04a182 movi a8, 0x104
55: 828a add.n a8, a2, a8
57: 004892 s8i a9, a8, 0
5a: f01d retw.n
```
Note that the each four bytes are stored separately using
one-byte-store instruction, s8i.
This commit tries to use larger alignments for load/store LLVM IR
instructions when possible. with this commit, the above example is
compiled into the following machine code, which seems more reasonable.
```
0000002c <aot_func_internal#0>:
2c: 004136 entry a1, 32
2f: ffff81 l32r a8, 2c <aot_func_internal#0> (81004136 <aot_func_internal#0+0x8100410a>)
2f: R_XTENSA_SLOT0_OP .literal+0x8
32: 416282 s32i a8, a2, 0x104
35: f01d retw.n
```
Note: this doesn't work well for --xip because aot_load_const_from_table()
hides the constness of the value. Maybe we need our own mechanism to
propagate the constness and the value.1 parent 607ae47 commit 4c2af25
File tree
5 files changed
+65
-19
lines changed- core/iwasm
- common
- compilation
- simd
- tests/unit/compilation
5 files changed
+65
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
883 | 883 | | |
884 | 884 | | |
885 | 885 | | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
886 | 892 | | |
887 | 893 | | |
888 | 894 | | |
| |||
1032 | 1038 | | |
1033 | 1039 | | |
1034 | 1040 | | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
1035 | 1047 | | |
1036 | 1048 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
| 100 | + | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
| |||
180 | 181 | | |
181 | 182 | | |
182 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
183 | 204 | | |
184 | 205 | | |
185 | 206 | | |
| |||
205 | 226 | | |
206 | 227 | | |
207 | 228 | | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
208 | 232 | | |
209 | 233 | | |
210 | 234 | | |
| |||
324 | 348 | | |
325 | 349 | | |
326 | 350 | | |
327 | | - | |
| 351 | + | |
328 | 352 | | |
329 | 353 | | |
330 | 354 | | |
| |||
343 | 367 | | |
344 | 368 | | |
345 | 369 | | |
346 | | - | |
| 370 | + | |
347 | 371 | | |
348 | 372 | | |
349 | 373 | | |
| |||
445 | 469 | | |
446 | 470 | | |
447 | 471 | | |
| 472 | + | |
448 | 473 | | |
449 | | - | |
| 474 | + | |
450 | 475 | | |
451 | 476 | | |
452 | 477 | | |
| |||
515 | 540 | | |
516 | 541 | | |
517 | 542 | | |
| 543 | + | |
518 | 544 | | |
519 | | - | |
| 545 | + | |
520 | 546 | | |
521 | 547 | | |
522 | 548 | | |
| |||
591 | 617 | | |
592 | 618 | | |
593 | 619 | | |
| 620 | + | |
594 | 621 | | |
595 | | - | |
| 622 | + | |
596 | 623 | | |
597 | 624 | | |
598 | 625 | | |
| |||
614 | 641 | | |
615 | 642 | | |
616 | 643 | | |
| 644 | + | |
617 | 645 | | |
618 | | - | |
| 646 | + | |
619 | 647 | | |
620 | 648 | | |
621 | 649 | | |
| |||
640 | 668 | | |
641 | 669 | | |
642 | 670 | | |
| 671 | + | |
643 | 672 | | |
644 | | - | |
| 673 | + | |
645 | 674 | | |
646 | 675 | | |
647 | 676 | | |
| |||
691 | 720 | | |
692 | 721 | | |
693 | 722 | | |
| 723 | + | |
694 | 724 | | |
695 | | - | |
| 725 | + | |
696 | 726 | | |
697 | 727 | | |
698 | 728 | | |
| |||
748 | 778 | | |
749 | 779 | | |
750 | 780 | | |
| 781 | + | |
751 | 782 | | |
752 | | - | |
| 783 | + | |
753 | 784 | | |
754 | 785 | | |
755 | 786 | | |
| |||
771 | 802 | | |
772 | 803 | | |
773 | 804 | | |
| 805 | + | |
774 | 806 | | |
775 | | - | |
| 807 | + | |
776 | 808 | | |
777 | 809 | | |
778 | 810 | | |
| |||
1302 | 1334 | | |
1303 | 1335 | | |
1304 | 1336 | | |
1305 | | - | |
| 1337 | + | |
1306 | 1338 | | |
1307 | 1339 | | |
1308 | 1340 | | |
| |||
1392 | 1424 | | |
1393 | 1425 | | |
1394 | 1426 | | |
1395 | | - | |
| 1427 | + | |
1396 | 1428 | | |
1397 | 1429 | | |
1398 | 1430 | | |
| |||
1505 | 1537 | | |
1506 | 1538 | | |
1507 | 1539 | | |
1508 | | - | |
| 1540 | + | |
1509 | 1541 | | |
1510 | 1542 | | |
1511 | 1543 | | |
| |||
1579 | 1611 | | |
1580 | 1612 | | |
1581 | 1613 | | |
1582 | | - | |
| 1614 | + | |
1583 | 1615 | | |
1584 | 1616 | | |
1585 | 1617 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
290 | | - | |
| 290 | + | |
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
| 104 | + | |
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
| |||
0 commit comments