i386: Use SBB more [PR94650]
When returning 0 or -1, "SBB reg,reg" instruction that borrows carry
flag can be used. Carry flag can be generated by converting compare
with zero to a LTU compare with one, so e.g.
return -(x == 0)
generates:
cmpq $1, %rdi
sbbq %rax, %rax
instead of:
xorl %eax, %eax
testq %rdi, %rdi
sete %al
negq %rax
A similar conversion can be used for
return -(x != 0)
where NEG insn can be used instead of compare. According to x86 ISA,
NEG insn sets carry flag when the source operand is != 0, resulting in:
negq %rdi
sbbq %rax, %rax
The conversion avoids partial register stall with SETcc instructions.
PR target/94795
* config/i386/i386.md (*neg<mode>_ccc): New insn pattern.
(EQ compare->LTU compare splitter): New splitter.
(NE compare->NEG splitter): Ditto.
testsuite/ChangeLog:
PR target/94795
* gcc.target/i386/pr94795-1.c: New test.
* gcc.target/i386/pr94795-2.c: New test.