public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/98060] New: Failure to optimize cmp+setnb+add to cmp+sbb
@ 2020-11-29 23:07 gabravier at gmail dot com
2020-11-30 16:21 ` [Bug target/98060] " ubizjak at gmail dot com
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: gabravier at gmail dot com @ 2020-11-29 23:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98060
Bug ID: 98060
Summary: Failure to optimize cmp+setnb+add to cmp+sbb
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: gabravier at gmail dot com
Target Milestone: ---
int r(unsigned v0, unsigned v1, int v2)
{
return (v0 >= v1) + v2;
}
This code, on x86, can be implemented with `cmp` followed by `sbb`. This
optimization is done by LLVM, but not by GCC.
-O3 x86 output on LLVM :
r:
mov eax, edx
cmp edi, esi
sbb eax, -1
ret
On GCC :
r:
xor eax, eax
cmp edi, esi
setnb al
add eax, edx
ret
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/98060] Failure to optimize cmp+setnb+add to cmp+sbb
2020-11-29 23:07 [Bug target/98060] New: Failure to optimize cmp+setnb+add to cmp+sbb gabravier at gmail dot com
@ 2020-11-30 16:21 ` ubizjak at gmail dot com
2020-12-02 15:31 ` ubizjak at gmail dot com
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2020-11-30 16:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98060
Uroš Bizjak <ubizjak at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Last reconfirmed| |2020-11-30
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #1 from Uroš Bizjak <ubizjak at gmail dot com> ---
There are several other cases where sbb/adc can be used:
--cut here--
int r1 (unsigned v0, unsigned v1, int v2)
{
return (v0 >= v1) + v2;
}
int r2 (unsigned v0, unsigned v1, int v2)
{
return (v1 > v0) + v2;
}
int r3 (unsigned v0, unsigned v1, int v2)
{
return (v0 <= v1) + v2;
}
int r4 (unsigned v0, unsigned v1, int v2)
{
return (v1 < v0) + v2;
}
--cut here--
r1 and r3 can be implemented with sbb $-1, reg, r2 and r4 with adc $0, reg.
gcc currently converts only r4.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/98060] Failure to optimize cmp+setnb+add to cmp+sbb
2020-11-29 23:07 [Bug target/98060] New: Failure to optimize cmp+setnb+add to cmp+sbb gabravier at gmail dot com
2020-11-30 16:21 ` [Bug target/98060] " ubizjak at gmail dot com
@ 2020-12-02 15:31 ` ubizjak at gmail dot com
2020-12-02 15:42 ` ubizjak at gmail dot com
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2020-12-02 15:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98060
--- Comment #2 from Uroš Bizjak <ubizjak at gmail dot com> ---
Created attachment 49662
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49662&action=edit
Testcases
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/98060] Failure to optimize cmp+setnb+add to cmp+sbb
2020-11-29 23:07 [Bug target/98060] New: Failure to optimize cmp+setnb+add to cmp+sbb gabravier at gmail dot com
2020-11-30 16:21 ` [Bug target/98060] " ubizjak at gmail dot com
2020-12-02 15:31 ` ubizjak at gmail dot com
@ 2020-12-02 15:42 ` ubizjak at gmail dot com
2020-12-02 19:47 ` ubizjak at gmail dot com
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2020-12-02 15:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98060
Uroš Bizjak <ubizjak at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |ubizjak at gmail dot com
Status|NEW |ASSIGNED
--- Comment #3 from Uroš Bizjak <ubizjak at gmail dot com> ---
Created attachment 49663
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49663&action=edit
Proposed patch
Proposed patch does a couple of things:
a) introduces reversed adc and sbb insn patterns
b) introduces carry_flag_unset_operator
c) SUBSTANTIALLY cleans carry flag checking predicates
d) rearranges integer compares to allow more combines with carry flag
e) enhances ix86_unary_operator_ok to allow input memory operand for adc and
sbb
I don't think this patch is appropriate for stage-3+, let's wait for stage-1 to
reopen.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/98060] Failure to optimize cmp+setnb+add to cmp+sbb
2020-11-29 23:07 [Bug target/98060] New: Failure to optimize cmp+setnb+add to cmp+sbb gabravier at gmail dot com
` (2 preceding siblings ...)
2020-12-02 15:42 ` ubizjak at gmail dot com
@ 2020-12-02 19:47 ` ubizjak at gmail dot com
2020-12-18 15:19 ` ubizjak at gmail dot com
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2020-12-02 19:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98060
Uroš Bizjak <ubizjak at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #49663|0 |1
is obsolete| |
--- Comment #4 from Uroš Bizjak <ubizjak at gmail dot com> ---
Created attachment 49666
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49666&action=edit
Updated patch
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/98060] Failure to optimize cmp+setnb+add to cmp+sbb
2020-11-29 23:07 [Bug target/98060] New: Failure to optimize cmp+setnb+add to cmp+sbb gabravier at gmail dot com
` (3 preceding siblings ...)
2020-12-02 19:47 ` ubizjak at gmail dot com
@ 2020-12-18 15:19 ` ubizjak at gmail dot com
2021-04-30 8:16 ` cvs-commit at gcc dot gnu.org
2021-04-30 8:39 ` ubizjak at gmail dot com
6 siblings, 0 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2020-12-18 15:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98060
Uroš Bizjak <ubizjak at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |12.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/98060] Failure to optimize cmp+setnb+add to cmp+sbb
2020-11-29 23:07 [Bug target/98060] New: Failure to optimize cmp+setnb+add to cmp+sbb gabravier at gmail dot com
` (4 preceding siblings ...)
2020-12-18 15:19 ` ubizjak at gmail dot com
@ 2021-04-30 8:16 ` cvs-commit at gcc dot gnu.org
2021-04-30 8:39 ` ubizjak at gmail dot com
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-04-30 8:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98060
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Uros Bizjak <uros@gcc.gnu.org>:
https://gcc.gnu.org/g:c111f6066043d3b7bc4141ca0411eae9294aa6c5
commit r12-311-gc111f6066043d3b7bc4141ca0411eae9294aa6c5
Author: Uros Bizjak <ubizjak@gmail.com>
Date: Fri Apr 30 10:15:26 2021 +0200
i386: Introduce reversed ADC and SBB patterns [PR98060]
The compiler is able to merge LTU comparisons with PLUS or MINUS pattern to
form addition with carry (ADC) and subtraction with borrow (SBB)
instructions:
op = op + carry [ADC $0, op]
op = op - carry [SBB $0, op]
The patch introduces reversed ADC and SBB insn patterns:
op = op + !carry [SBB $-1, op]
op = op - !carry [ADC $-1, op]
allowing the compiler to also merge GEU comparisons.
2021-04-30 Uroš Bizjak <ubizjak@gmail.com>
gcc/
PR target/98060
* config/i386/i386.md (*add<mode>3_carry_0r): New insn pattern.
(*addsi3_carry_zext_0r): Ditto.
(*sub<mode>3_carry_0): Ditto.
(*subsi3_carry_zext_0r): Ditto.
* config/i386/predicates.md (ix86_carry_flag_unset_operator):
New predicate.
* config/i386/i386.c (ix86_rtx_costs) <case PLUS, case MINUS>:
Also consider ix86_carry_flag_unset_operator to calculate
the cost of adc/sbb insn.
gcc/testsuite/
PR target/98060
* gcc.target/i386/pr98060.c: New test.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/98060] Failure to optimize cmp+setnb+add to cmp+sbb
2020-11-29 23:07 [Bug target/98060] New: Failure to optimize cmp+setnb+add to cmp+sbb gabravier at gmail dot com
` (5 preceding siblings ...)
2021-04-30 8:16 ` cvs-commit at gcc dot gnu.org
@ 2021-04-30 8:39 ` ubizjak at gmail dot com
6 siblings, 0 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2021-04-30 8:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98060
Uroš Bizjak <ubizjak at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #6 from Uroš Bizjak <ubizjak at gmail dot com> ---
Implemented in gcc-12.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-04-30 8:39 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-29 23:07 [Bug target/98060] New: Failure to optimize cmp+setnb+add to cmp+sbb gabravier at gmail dot com
2020-11-30 16:21 ` [Bug target/98060] " ubizjak at gmail dot com
2020-12-02 15:31 ` ubizjak at gmail dot com
2020-12-02 15:42 ` ubizjak at gmail dot com
2020-12-02 19:47 ` ubizjak at gmail dot com
2020-12-18 15:19 ` ubizjak at gmail dot com
2021-04-30 8:16 ` cvs-commit at gcc dot gnu.org
2021-04-30 8:39 ` ubizjak at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).