From 9b71b2ab84caafd7f32429772745f9b07d85321f Mon Sep 17 00:00:00 2001 From: Kyrylo Tkachov Date: Wed, 25 Nov 2015 09:48:29 +0000 Subject: [PATCH] [RTL-ifcvt] PR rtl-optimization/68435 Allow (c ? x++ : x--) form PR rtl-optimization/68435 * ifcvt.c (noce_try_cmove_arith): Skip final insn when checking for conflicts between a, b and the set destinations. * gcc.dg/pr68435.c: New test. From-SVN: r230859 --- gcc/ChangeLog | 6 ++++ gcc/ifcvt.c | 10 +++++-- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.dg/pr68435.c | 52 ++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr68435.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ec493af77a8..49fa59bca05 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-11-25 Kyrylo Tkachov + + PR rtl-optimization/68435 + * ifcvt.c (noce_try_cmove_arith): Skip final insn when checking + for conflicts between a, b and the set destinations. + 2015-11-25 Richard Biener PR tree-optimization/68517 diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index eb5cae5a753..212d320dadb 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -2180,7 +2180,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; @@ -2193,7 +2196,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/ChangeLog b/gcc/testsuite/ChangeLog index 78e09048157..a1bbe87e3d7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-11-25 Kyrylo Tkachov + + PR rtl-optimization/68435 + * gcc.dg/pr68435.c: New test. + 2015-11-25 Richard Biener PR tree-optimization/68517 diff --git a/gcc/testsuite/gcc.dg/pr68435.c b/gcc/testsuite/gcc.dg/pr68435.c new file mode 100644 index 00000000000..765699a19e7 --- /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" } } */ -- 2.30.2