[RTL-ifcvt] PR rtl-optimization/68435 Allow (c ? x++ : x--) form
authorKyrylo Tkachov <kyrylo.tkachov@arm.com>
Wed, 25 Nov 2015 09:48:29 +0000 (09:48 +0000)
committerKyrylo Tkachov <ktkachov@gcc.gnu.org>
Wed, 25 Nov 2015 09:48:29 +0000 (09:48 +0000)
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
gcc/ifcvt.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr68435.c [new file with mode: 0644]

index ec493af77a83334e39124e18cff85769c8cdc9ee..49fa59bca057942285c1b22415dbb9a416f3962b 100644 (file)
@@ -1,3 +1,9 @@
+2015-11-25  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       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  <rguenther@suse.de>
 
        PR tree-optimization/68517
index eb5cae5a753924554f0c30e7714bf57498b068a1..212d320dadbd189dec7d4016fffcae3995041304 100644 (file)
@@ -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;
index 78e09048157b9fe68d45e09f5d2a4a31677df9d3..a1bbe87e3d728d7e1e8c5ddcb93e4fbda7794d8c 100644 (file)
@@ -1,3 +1,8 @@
+2015-11-25  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       PR rtl-optimization/68435
+       * gcc.dg/pr68435.c: New test.
+
 2015-11-25  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/68517
diff --git a/gcc/testsuite/gcc.dg/pr68435.c b/gcc/testsuite/gcc.dg/pr68435.c
new file mode 100644 (file)
index 0000000..765699a
--- /dev/null
@@ -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" } } */