public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/c++-coroutines] i386: Use SBB more [PR94650]
@ 2020-05-04 21:15 Iain D Sandoe
0 siblings, 0 replies; only message in thread
From: Iain D Sandoe @ 2020-05-04 21:15 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:9decd08b7b153a593a0b61e4f5373cb9574a1973
commit 9decd08b7b153a593a0b61e4f5373cb9574a1973
Author: Uros Bizjak <ubizjak@gmail.com>
Date: Mon May 4 18:53:30 2020 +0200
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.
Diff:
---
gcc/config/i386/i386.md | 44 ++++++++++++++++++++++++++++---
gcc/testsuite/gcc.target/i386/pr94795-1.c | 21 +++++++++++++++
gcc/testsuite/gcc.target/i386/pr94795-2.c | 20 ++++++++++++++
3 files changed, 82 insertions(+), 3 deletions(-)
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index bd144ab3d5e..76c00867231 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -9900,6 +9900,17 @@
[(set_attr "type" "negnot")
(set_attr "mode" "SI")])
+(define_insn "*neg<mode>_ccc"
+ [(set (reg:CCC FLAGS_REG)
+ (ne:CCC
+ (match_operand:SWI 1 "nonimmediate_operand" "0")
+ (const_int 0)))
+ (clobber (match_scratch:SWI 0 "=<r>"))]
+ ""
+ "neg{<imodesuffix>}\t%0"
+ [(set_attr "type" "negnot")
+ (set_attr "mode" "<MODE>")])
+
;; Negate with jump on overflow.
(define_expand "negv<mode>3"
[(parallel [(set (reg:CCO FLAGS_REG)
@@ -18015,9 +18026,9 @@
(set_attr "length_immediate" "0")])
(define_insn "*x86_mov<mode>cc_0_m1_neg"
- [(set (match_operand:SWI48 0 "register_operand" "=r")
- (neg:SWI48 (match_operator 1 "ix86_carry_flag_operator"
- [(reg FLAGS_REG) (const_int 0)])))
+ [(set (match_operand:SWI 0 "register_operand" "=<r>")
+ (neg:SWI (match_operator 1 "ix86_carry_flag_operator"
+ [(reg FLAGS_REG) (const_int 0)])))
(clobber (reg:CC FLAGS_REG))]
""
"sbb{<imodesuffix>}\t%0, %0"
@@ -18045,6 +18056,33 @@
(clobber (reg:CC FLAGS_REG))])]
"operands[2] = GEN_INT (INTVAL (operands[2]) + 1);")
+(define_split
+ [(set (match_operand:SWI 0 "register_operand")
+ (neg:SWI
+ (eq:SWI
+ (match_operand 1 "int_nonimmediate_operand")
+ (const_int 0))))]
+ ""
+ [(set (reg:CC FLAGS_REG) (compare:CC (match_dup 1) (const_int 1)))
+ (parallel [(set (match_dup 0)
+ (neg:SWI (ltu:SWI (reg:CC FLAGS_REG) (const_int 0))))
+ (clobber (reg:CC FLAGS_REG))])])
+
+(define_split
+ [(set (match_operand:SWI 0 "register_operand")
+ (neg:SWI
+ (ne:SWI
+ (match_operand 1 "int_nonimmediate_operand")
+ (const_int 0))))]
+ ""
+ [(parallel [(set (reg:CCC FLAGS_REG)
+ (ne:CCC (match_dup 1) (const_int 0)))
+ (clobber (match_dup 2))])
+ (parallel [(set (match_dup 0)
+ (neg:SWI (ltu:SWI (reg:CCC FLAGS_REG) (const_int 0))))
+ (clobber (reg:CC FLAGS_REG))])]
+ "operands[2] = gen_rtx_SCRATCH (GET_MODE (operands[1]));")
+
(define_insn "*mov<mode>cc_noc"
[(set (match_operand:SWI248 0 "register_operand" "=r,r")
(if_then_else:SWI248 (match_operator 1 "ix86_comparison_operator"
diff --git a/gcc/testsuite/gcc.target/i386/pr94795-1.c b/gcc/testsuite/gcc.target/i386/pr94795-1.c
new file mode 100644
index 00000000000..c87a3dd4030
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr94795-1.c
@@ -0,0 +1,21 @@
+/* PR target/94795 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+char fooc (char x)
+{
+ return x ? -1 : 0;
+}
+
+short foos (short x)
+{
+ return x ? -1 : 0;
+}
+
+long fooi (long x)
+{
+ return x ? -1 : 0;
+}
+
+/* { dg-final { scan-assembler-not "test|cmp" } } */
+/* { dg-final { scan-assembler-times "sbb" 3 } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr94795-2.c b/gcc/testsuite/gcc.target/i386/pr94795-2.c
new file mode 100644
index 00000000000..87d76299a8a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr94795-2.c
@@ -0,0 +1,20 @@
+/* PR target/94795 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+char fooc (char x)
+{
+ return -(x == 0);
+}
+
+short foos (short x)
+{
+ return -(x == 0);
+}
+
+long fooi (long x)
+{
+ return -(x == 0);
+}
+
+/* { dg-final { scan-assembler-times "sbb" 3 } } */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-05-04 21:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-04 21:15 [gcc/devel/c++-coroutines] i386: Use SBB more [PR94650] Iain D Sandoe
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).