https://bugs.llvm.org/show_bug.cgi?id=46809
Bug ID: 46809
Summary: Missed optimization to use the carry flag after
subtracting
Product: libraries
Version: 10.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Backend: X86
Assignee: unassignedb...@nondot.org
Reporter: josephcsi...@gmail.com
CC: craig.top...@gmail.com, llvm-bugs@lists.llvm.org,
llvm-...@redking.me.uk, spatel+l...@rotateright.com
Consider these two C functions:
unsigned f1(unsigned x, unsigned y) {
unsigned z = x - y;
if (x < y) {
z += 100;
}
return z;
}
unsigned f2(unsigned x, unsigned y) {
unsigned z;
if (__builtin_usub_overflow(x, y, &z)) {
z += 100;
}
return z;
}
At -O3 or -Os, they both generate the same assembly:
movl %edi, %eax
movl %edi, %ecx
subl %esi, %ecx
addl $100, %ecx
subl %esi, %eax
cmovbl %ecx, %eax
retq
https://godbolt.org/z/MevEM9
That's suboptimal. They should have instead used lea to save a move, save a
duplicate subtraction, and avoid clobbering the carry flag, like this:
subl %esi, %edi
leal 100(%rdi), %eax
cmovael %edi, %eax
retq
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs