bjorn3 commented on issue #1102:
Is this still a problem with the new x64 backend?
cfallin commented on issue #1102:
I'm not sure if this would use
cmov
today (it should if the CLIF uses aselect
op) but the branches should be reasonable (like llvm and gcc) now due toMachBuffer
's simplification pass.
cfallin closed issue #1102:
I thought I'd look into codegen. Consider the following test of a simple branch, where compilers were asked to generate the best code:
int five(int a) { return a > 5 ? 8 : a; }
LLVM generates:
0000000000000000 <five>: 0: 83 ff 06 cmp $0x6,%edi 3: b8 05 00 00 00 mov $0x5,%eax 8: 0f 4c c7 cmovl %edi,%eax b: c3 retq
GCC generates:
0000000000000000 <five>: 0: 89 f8 mov %edi,%eax 2: 83 ff 06 cmp $0x6,%edi 5: ba 08 00 00 00 mov $0x8,%edx a: 0f 4d c2 cmovge %edx,%eax d: c3 retq
And Cranelift generates (via clang-compiled wasm):
Disassembly of 22 bytes: 0: 55 push rbp 1: 48 89 e5 mov rbp, rsp 4: b8 08 00 00 00 mov eax, 8 9: 83 ff 05 cmp edi, 5 c: 7f 04 jg 0x12 e: 89 f8 mov eax, edi 10: eb 02 jmp 0x14 12: eb fc jmp 0x10 14: 5d pop rbp 15: c3 ret
There are some obvious things to fix up:
- [ ] Constructing/destructing stack frames can be skipped if the stack is unused.
- [x]
0xc
jumps conditionally to0x12
, which is an unconditional jump to0x10
, which is an unconditional jump to0x14
, which is an unconditional jump to the end of the function.- [ ] Simple branches can be folded into
cmov
on x86. In this case we havecmp
..jg
..mov
..jmp
which is exactly what acmov
does.
akirilov-arm commented on issue #1102:
The first item is covered by #1148.
Last updated: Dec 23 2024 at 13:07 UTC