From 256768d44736da4b5dc68c838ace22feeeaf770c Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 22 Jun 2018 22:38:25 +0200 Subject: [PATCH] backport: re PR middle-end/84834 (ICE: tree check: expected integer_cst, have complex_cst in to_wide, at tree.h:5527) Backported from mainline 2018-03-13 Jakub Jelinek PR middle-end/84834 * match.pd ((A & C) != 0 ? D : 0): Use INTEGER_CST@2 instead of integer_pow2p@2 and test integer_pow2p in condition. (A < 0 ? C : 0): Similarly for @1. * gcc.dg/pr84834.c: New test. From-SVN: r261921 --- gcc/ChangeLog | 5 +++++ gcc/match.pd | 25 ++++++++++++++----------- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/gcc.dg/pr84834.c | 15 +++++++++++++++ 4 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr84834.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f8789d266831..841815df05ac 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -3,6 +3,11 @@ Backported from mainline 2018-03-13 Jakub Jelinek + PR middle-end/84834 + * match.pd ((A & C) != 0 ? D : 0): Use INTEGER_CST@2 instead of + integer_pow2p@2 and test integer_pow2p in condition. + (A < 0 ? C : 0): Similarly for @1. + PR target/84827 * config/i386/i386.md (round2): For 387 fancy math, disable pattern if -ftrapping-math -fno-fp-int-builtin-inexact. diff --git a/gcc/match.pd b/gcc/match.pd index 100e188ea2c9..3a44ea7f628a 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2789,15 +2789,17 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (cond (ne (bit_and @0 integer_pow2p@1) integer_zerop) - integer_pow2p@2 integer_zerop) - (with { - int shift = wi::exact_log2 (@2) - wi::exact_log2 (@1); - } - (if (shift > 0) - (bit_and - (lshift (convert @0) { build_int_cst (integer_type_node, shift); }) @2) - (bit_and - (convert (rshift @0 { build_int_cst (integer_type_node, -shift); })) @2)))) + INTEGER_CST@2 integer_zerop) + (if (integer_pow2p (@2)) + (with { + int shift = wi::exact_log2 (@2) - wi::exact_log2 (@1); + } + (if (shift > 0) + (bit_and + (lshift (convert @0) { build_int_cst (integer_type_node, shift); }) @2) + (bit_and + (convert (rshift @0 { build_int_cst (integer_type_node, -shift); })) + @2))))) /* If we have (A & C) != 0 where C is the sign bit of A, convert this into A < 0. Similarly for (A & C) == 0 into A >= 0. */ @@ -2818,8 +2820,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (cond (lt @0 integer_zerop) - integer_pow2p@1 integer_zerop) - (if (!TYPE_UNSIGNED (TREE_TYPE (@0))) + INTEGER_CST@1 integer_zerop) + (if (integer_pow2p (@1) + && !TYPE_UNSIGNED (TREE_TYPE (@0))) (with { int shift = element_precision (@0) - wi::exact_log2 (@1) - 1; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b4e4fec70fb4..98fa2654761f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -3,6 +3,9 @@ Backported from mainline 2018-03-13 Jakub Jelinek + PR middle-end/84834 + * gcc.dg/pr84834.c: New test. + PR target/84827 * gcc.target/i386/pr84827.c: New test. diff --git a/gcc/testsuite/gcc.dg/pr84834.c b/gcc/testsuite/gcc.dg/pr84834.c new file mode 100644 index 000000000000..38c056bb4ca5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr84834.c @@ -0,0 +1,15 @@ +/* PR middle-end/84834 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +_Complex int +foo (int a) +{ + return a < 0; +} + +_Complex int +bar (int a) +{ + return (a & 8) ? (_Complex int) 16 : (_Complex int) 0; +} -- 2.47.2