From patchwork Tue Aug 24 19:19:26 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Avoid creating invalid gimple in eliminate_redundant_comparison (PR tree-optimization/45059) Date: Tue, 24 Aug 2010 09:19:26 -0000 From: Jakub Jelinek X-Patchwork-Id: 62620 Message-Id: <20100824191926.GS702@tyan-ft48-01.lab.bos.redhat.com> To: gcc-patches@gcc.gnu.org Hi! In some cases the operands of the comparison won't have the desired type, e.g. if there were any (useless) differences in types of the operands. Having a NOP_EXPR as gimple comparison's operand is invalid though. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux. Ok for trunk? 2010-08-24 Jakub Jelinek PR tree-optimization/45059 * tree-ssa-reassoc.c (eliminate_redundant_comparison): Strip useless type conversions from newop{1,2}. Assert t is a comparison and newop{1,2} after the stripping are gimple vals. * gcc.c-torture/compile/pr45059.c: New test. Jakub --- gcc/tree-ssa-reassoc.c.jj 2010-08-20 16:05:41.000000000 +0200 +++ gcc/tree-ssa-reassoc.c 2010-08-24 19:16:57.000000000 +0200 @@ -1314,9 +1314,14 @@ eliminate_redundant_comparison (enum tre enum tree_code subcode; tree newop1; tree newop2; + gcc_assert (COMPARISON_CLASS_P (t)); tmpvar = create_tmp_var (TREE_TYPE (t), NULL); add_referenced_var (tmpvar); extract_ops_from_tree (t, &subcode, &newop1, &newop2); + STRIP_USELESS_TYPE_CONVERSION (newop1); + STRIP_USELESS_TYPE_CONVERSION (newop2); + gcc_checking_assert (is_gimple_val (newop1) + && is_gimple_val (newop2)); sum = build_and_add_sum (tmpvar, newop1, newop2, subcode); curr->op = gimple_get_lhs (sum); } --- gcc/testsuite/gcc.c-torture/compile/pr45059.c.jj 2010-08-24 19:05:44.000000000 +0200 +++ gcc/testsuite/gcc.c-torture/compile/pr45059.c 2010-08-24 19:05:25.000000000 +0200 @@ -0,0 +1,23 @@ +/* PR tree-optimization/45059 */ + +typedef unsigned int T; +extern void foo (signed char *, int); + +static signed char a; +static T b[1] = { -1 }; +static unsigned char c; + +static inline short int +bar (short v) +{ + c |= a < b[0]; + return 0; +} + +int +main () +{ + signed char *e = &a; + foo (e, bar (bar (c))); + return 0; +}