https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99548
Bug ID: 99548
Summary: Help me! Lost the fight against the compiler.
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: unlvsur at live dot com
Target Milestone: ---
https://godbolt.org/z/Kd8q57
The compiler just could not generate as good as assembly as I manually wrote.
Unfortunately, due to the calling convention issues, the inline asm version
would never be portable and hurt other compiler optimizations.
Some patterns like neither GCC nor clang could correctly deal with it.
std::uint64_t v=0;//set 0 to make compiler happy or it is UB.
sub_borrow(carry,v,v,v);
movl $0, %eax
movq %rax, %rdx
sbbq %rax, %rdx
What the code actually want is to
sbb %rdx,%rdx
Which is to set the register to the UINT64_MAX when carry (borrow) flag is 1.
movq (%rdx), %rcx
movq 8(%rsi), %r9
addq (%rsi), %rcx
movq 16(%rsi), %r8
movq 24(%rdx), %rax
adcq 8(%rdx), %r9
movq 24(%rsi), %rsi
adcq 16(%rdx), %r8
adcq %rax, %rsi
movl $0, %eax
Do we have any possibility to fix those optimization issues in the compiler?