From 3f54004b095d1cd513e63753ee0f8f9f13698347 Mon Sep 17 00:00:00 2001 From: Bin Cheng Date: Fri, 27 Jan 2017 14:42:23 +0000 Subject: [PATCH] re PR rtl-optimization/78559 (wrong code due to tree if-conversion?) PR rtl-optimization/78559 * combine.c (try_combine): Discard REG_EQUAL and REG_EQUIV for other_insn in combine. gcc/testsuite PR rtl-optimization/78559 * gcc.c-torture/execute/pr78559.c: New test. From-SVN: r244979 --- gcc/ChangeLog | 6 ++++ gcc/combine.c | 11 +++++- gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/gcc.c-torture/execute/pr78559.c | 34 +++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr78559.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0a553789ccd..b70acef6953 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-01-27 Bin Cheng + + PR rtl-optimization/78559 + * combine.c (try_combine): Discard REG_EQUAL and REG_EQUIV for + other_insn in combine. + 2017-01-27 Pekka Jääskeläinen * builtin-types.def: Use unsigned_char_type_node for BT_UINT8. Use diff --git a/gcc/combine.c b/gcc/combine.c index c643a0eb28f..727299bdf50 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -4148,7 +4148,16 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0, PATTERN (undobuf.other_insn))) ||(REG_NOTE_KIND (note) == REG_UNUSED && !reg_set_p (XEXP (note, 0), - PATTERN (undobuf.other_insn)))) + PATTERN (undobuf.other_insn))) + /* Simply drop equal note since it may be no longer valid + for other_insn. It may be possible to record that CC + register is changed and only discard those notes, but + in practice it's unnecessary complication and doesn't + give any meaningful improvement. + + See PR78559. */ + || REG_NOTE_KIND (note) == REG_EQUAL + || REG_NOTE_KIND (note) == REG_EQUIV) remove_note (undobuf.other_insn, note); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e3ad4caca2b..2dce32ecd59 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-01-27 Bin Cheng + + PR rtl-optimization/78559 + * gcc.c-torture/execute/pr78559.c: New test. + 2017-01-27 Richard Biener PR tree-optimization/79245 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr78559.c b/gcc/testsuite/gcc.c-torture/execute/pr78559.c new file mode 100644 index 00000000000..8d7b8e3004b --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr78559.c @@ -0,0 +1,34 @@ +/* PR rtl-optimization/78559 */ + +int g = 20; +int d = 0; + +short +fn2 (int p1, int p2) +{ + return p2 >= 2 || 5 >> p2 ? p1 : p1 << p2; +} + +int +main () +{ + int result = 0; +lbl_2582: + if (g) + { + for (int c = -3; c; c++) + result = fn2 (1, g); + } + else + { + for (int i = 0; i < 2; i += 2) + if (d) + goto lbl_2582; + } + if (result != 1) + __builtin_abort (); + return 0; +} + + + -- 2.30.2