From: Uros Bizjak <ubizjak@gmail.com>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: [PATCH] i386: Optimize carry flag comparisons a bit
Date: Thu, 29 Apr 2021 22:04:55 +0200 [thread overview]
Message-ID: <CAFULd4Y81YB42x8KN9mVK6XVResi2o1+qdyGWv9XyjxOT22+Sw@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1188 bytes --]
In ix86_int_compare, opportunistically swap operands of GTU and LEU comparisons
to emit carry flag comparison, with the expectation that the comparison will
combine to *add<mode>3_carry_0 or *sub<mode>3_carry_0 insn pattern.
Do not use ix86_expand_carry_flag_compare because this function prefers
carry flag comparisons too much - it forces the constants into registers
and/or emits additional arithmetic instructions to convert simple
comparisons into carry flag comparisons - but simply swap operands to
convert GTU and LEU comparisons into GEU and LTU ones.
Also, change the insn predicates of *add<mode>3_carry_0 and
*sub<mode>3_carry_0 insn patterns to allow more combine opportunities
with memory operands.
2021-04-29 Uroš Bizjak <ubizjak@gmail.com>
gcc/
* config/i386/i386-expand.c (ix86_expand_int_compare):
Swap operands of GTU and LEU comparison to emit carry flag comparison.
* config/i386/i386.md (*add<mode>3_carry_0): Change insn
predicate to allow more combine opportunities with memory operands.
(*sub<mode>3_carry_0): Ditto.
Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.
Pushed to master.
Uros.
[-- Attachment #2: p.diff.txt --]
[-- Type: text/plain, Size: 1655 bytes --]
diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
index 76990628150..fee4d07b7fd 100644
--- a/gcc/config/i386/i386-expand.c
+++ b/gcc/config/i386/i386-expand.c
@@ -2658,6 +2658,14 @@ ix86_expand_int_compare (enum rtx_code code, rtx op0, rtx op1)
machine_mode cmpmode;
rtx tmp, flags;
+ /* Swap operands to emit carry flag comparison. */
+ if ((code == GTU || code == LEU)
+ && nonimmediate_operand (op1, VOIDmode))
+ {
+ std::swap (op0, op1);
+ code = swap_condition (code);
+ }
+
cmpmode = SELECT_CC_MODE (code, op0, op1);
flags = gen_rtx_REG (cmpmode, FLAGS_REG);
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index eff189f17b4..b7f3e36a70c 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -6777,7 +6777,7 @@ (define_insn "*add<mode>3_carry_0"
[(match_operand 2 "flags_reg_operand") (const_int 0)])
(match_operand:SWI 1 "nonimmediate_operand" "0")))
(clobber (reg:CC FLAGS_REG))]
- "ix86_unary_operator_ok (PLUS, <MODE>mode, operands)"
+ "!MEM_P (operands[0]) || rtx_equal_p (operands[0], operands[1])"
"adc{<imodesuffix>}\t{$0, %0|%0, 0}"
[(set_attr "type" "alu")
(set_attr "use_carry" "1")
@@ -6919,7 +6919,7 @@ (define_insn "*sub<mode>3_carry_0"
(match_operator:SWI 3 "ix86_carry_flag_operator"
[(match_operand 2 "flags_reg_operand") (const_int 0)])))
(clobber (reg:CC FLAGS_REG))]
- "ix86_unary_operator_ok (MINUS, <MODE>mode, operands)"
+ "!MEM_P (operands[0]) || rtx_equal_p (operands[0], operands[1])"
"sbb{<imodesuffix>}\t{$0, %0|%0, 0}"
[(set_attr "type" "alu")
(set_attr "use_carry" "1")
reply other threads:[~2021-04-29 20:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAFULd4Y81YB42x8KN9mVK6XVResi2o1+qdyGWv9XyjxOT22+Sw@mail.gmail.com \
--to=ubizjak@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).