* [PATCH][RTL-ifcvt] PR rtl-optimization/68435 Allow (c ? x++ : x--) form
@ 2015-11-23 15:38 Kyrill Tkachov
2015-11-25 2:26 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Kyrill Tkachov @ 2015-11-23 15:38 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 1186 bytes --]
Hi all,
In this PR we fail to if-convert a case where in the expression x = c ? a : b;
'a' and 'b' are something like x + 1 and x - 1.
So x appears in a and b.
The code that checks that nothing from the else block modifies the registers used in a
rejects this case. It should accept when the modification is in the last insn of the block
i.e. insn_a or insn_b in the language of noce_try_cmove_arith because we will not be
emitting insn_a and insn_b verbatim, but rather their modified versions emit_a and emit_b
that have had their destinations modified to fresh pseudos, so no conflicts will arise.
Bootstrapped and tested on arm, aarch64, x86_64.
This improved if-conversion opportunities a bit across SPEC2006, not so much as to make
a difference, but definitely a small improvement.
Ok for trunk?
Thanks,
Kyrill
2015-11-23 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
PR rtl-optimization/68435
* ifcvt.c (noce_try_cmove_arith): Skip final insn when checking
for clonflicts between a, b and the set destinations.
2015-11-23 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
PR rtl-optimization/68435
* gcc.dg/pr68435.c: New test.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ifcvt-fix-x86.patch --]
[-- Type: text/x-patch; name=ifcvt-fix-x86.patch, Size: 3060 bytes --]
commit c890c68e2862980731e95cb4b7982f10b29109b7
Author: Kyrylo Tkachov <kyrylo.tkachov@arm.com>
Date: Fri Nov 20 09:13:04 2015 +0000
[ifcvt] PR rtl-optimization/68435 Allow (c ? x++ : x--) form
diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index d721ec7..af7a3b9 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -2210,7 +2210,10 @@ noce_try_cmove_arith (struct noce_if_info *if_info)
if (tmp_b && then_bb)
{
FOR_BB_INSNS (then_bb, tmp_insn)
- if (modified_in_p (orig_b, tmp_insn))
+ /* Don't check inside insn_a. We will have changed it to emit_a
+ with a destination that doesn't conflict. */
+ if (!(insn_a && tmp_insn == insn_a)
+ && modified_in_p (orig_b, tmp_insn))
{
modified_in_a = true;
break;
@@ -2223,7 +2226,10 @@ noce_try_cmove_arith (struct noce_if_info *if_info)
if (tmp_b && else_bb)
{
FOR_BB_INSNS (else_bb, tmp_insn)
- if (modified_in_p (orig_a, tmp_insn))
+ /* Don't check inside insn_b. We will have changed it to emit_b
+ with a destination that doesn't conflict. */
+ if (!(insn_b && tmp_insn == insn_b)
+ && modified_in_p (orig_a, tmp_insn))
{
modified_in_b = true;
break;
diff --git a/gcc/testsuite/gcc.dg/pr68435.c b/gcc/testsuite/gcc.dg/pr68435.c
new file mode 100644
index 0000000..765699a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr68435.c
@@ -0,0 +1,52 @@
+/* { dg-do compile { target aarch64*-*-* x86_64-*-* } } */
+/* { dg-options "-fdump-rtl-ce1 -O2 -w" } */
+
+typedef struct cpp_reader cpp_reader;
+enum cpp_ttype
+{
+ CPP_EQ =
+ 0, CPP_NOT, CPP_GREATER, CPP_LESS, CPP_PLUS, CPP_MINUS, CPP_MULT, CPP_DIV,
+ CPP_MOD, CPP_AND, CPP_OR, CPP_XOR, CPP_RSHIFT, CPP_LSHIFT, CPP_MIN,
+ CPP_MAX, CPP_COMPL, CPP_AND_AND, CPP_OR_OR, CPP_QUERY, CPP_COLON,
+ CPP_COMMA, CPP_OPEN_PAREN, CPP_CLOSE_PAREN, CPP_EQ_EQ, CPP_NOT_EQ,
+ CPP_GREATER_EQ, CPP_LESS_EQ, CPP_PLUS_EQ, CPP_MINUS_EQ, CPP_MULT_EQ,
+ CPP_DIV_EQ, CPP_MOD_EQ, CPP_AND_EQ, CPP_OR_EQ, CPP_XOR_EQ, CPP_RSHIFT_EQ,
+ CPP_LSHIFT_EQ, CPP_MIN_EQ, CPP_MAX_EQ, CPP_HASH, CPP_PASTE,
+ CPP_OPEN_SQUARE, CPP_CLOSE_SQUARE, CPP_OPEN_BRACE, CPP_CLOSE_BRACE,
+ CPP_SEMICOLON, CPP_ELLIPSIS, CPP_PLUS_PLUS, CPP_MINUS_MINUS, CPP_DEREF,
+ CPP_DOT, CPP_SCOPE, CPP_DEREF_STAR, CPP_DOT_STAR, CPP_ATSIGN, CPP_NAME,
+ CPP_NUMBER, CPP_CHAR, CPP_WCHAR, CPP_OTHER, CPP_STRING, CPP_WSTRING,
+ CPP_HEADER_NAME, CPP_COMMENT, CPP_MACRO_ARG, CPP_PADDING, CPP_EOF,
+};
+
+static struct op lex (cpp_reader *, int);
+
+struct op
+{
+ enum cpp_ttype op;
+ long value;
+};
+
+int
+_cpp_parse_expr (pfile)
+{
+ struct op init_stack[20];
+ struct op *stack = init_stack;
+ struct op *top = stack + 1;
+ int skip_evaluation = 0;
+ for (;;)
+ {
+ struct op op;
+ op = lex (pfile, skip_evaluation);
+ switch (op.op)
+ {
+ case CPP_OR_OR:
+ if (top->value)
+ skip_evaluation++;
+ else
+ skip_evaluation--;
+ }
+ }
+}
+
+/* { dg-final { scan-rtl-dump "2 true changes made" "ce1" } } */
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH][RTL-ifcvt] PR rtl-optimization/68435 Allow (c ? x++ : x--) form
2015-11-23 15:38 [PATCH][RTL-ifcvt] PR rtl-optimization/68435 Allow (c ? x++ : x--) form Kyrill Tkachov
@ 2015-11-25 2:26 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2015-11-25 2:26 UTC (permalink / raw)
To: Kyrill Tkachov, GCC Patches
On 11/23/2015 08:35 AM, Kyrill Tkachov wrote:
> Hi all,
>
> In this PR we fail to if-convert a case where in the expression x = c ?
> a : b;
> 'a' and 'b' are something like x + 1 and x - 1.
> So x appears in a and b.
> The code that checks that nothing from the else block modifies the
> registers used in a
> rejects this case. It should accept when the modification is in the last
> insn of the block
> i.e. insn_a or insn_b in the language of noce_try_cmove_arith because we
> will not be
> emitting insn_a and insn_b verbatim, but rather their modified versions
> emit_a and emit_b
> that have had their destinations modified to fresh pseudos, so no
> conflicts will arise.
>
> Bootstrapped and tested on arm, aarch64, x86_64.
> This improved if-conversion opportunities a bit across SPEC2006, not so
> much as to make
> a difference, but definitely a small improvement.
>
> Ok for trunk?
>
> Thanks,
> Kyrill
>
> 2015-11-23 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
>
> PR rtl-optimization/68435
> * ifcvt.c (noce_try_cmove_arith): Skip final insn when checking
> for clonflicts between a, b and the set destinations.
>
> 2015-11-23 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
>
> PR rtl-optimization/68435
> * gcc.dg/pr68435.c: New test.
OK. Thanks,
jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-11-25 0:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-23 15:38 [PATCH][RTL-ifcvt] PR rtl-optimization/68435 Allow (c ? x++ : x--) form Kyrill Tkachov
2015-11-25 2:26 ` Jeff Law
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).