From a4710e09ed089313e3d4189d00fcfc487262e05a Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 21 Dec 2017 20:26:34 +0100 Subject: [PATCH] re PR tree-optimization/83521 (ICE: verify_gimple failed (error: invalid operand in unary operation)) PR tree-optimization/83521 * tree-ssa-phiopt.c (factor_out_conditional_conversion): Use gimple_build_assign without code on result of fold_build1 (VIEW_CONVERT_EXPR, ...), as it might not create a VIEW_CONVERT_EXPR. * gcc.dg/pr83521.c: New test. From-SVN: r255952 --- gcc/ChangeLog | 8 ++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr83521.c | 10 ++++++++++ gcc/tree-ssa-phiopt.c | 8 ++++++-- 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr83521.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9bc3ba31d90..2b1aa73775a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2017-12-21 Jakub Jelinek + + PR tree-optimization/83521 + * tree-ssa-phiopt.c (factor_out_conditional_conversion): Use + gimple_build_assign without code on result of + fold_build1 (VIEW_CONVERT_EXPR, ...), as it might not create + a VIEW_CONVERT_EXPR. + 2017-12-21 Andrew Pinski Steve Ellcey diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d6928f00fbd..566efde7a33 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-12-21 Jakub Jelinek + + PR tree-optimization/83521 + * gcc.dg/pr83521.c: New test. + 2017-12-21 Nathan Sidwell PR c++/83406 diff --git a/gcc/testsuite/gcc.dg/pr83521.c b/gcc/testsuite/gcc.dg/pr83521.c new file mode 100644 index 00000000000..fc7ca04d1b4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr83521.c @@ -0,0 +1,10 @@ +/* PR tree-optimization/83521 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fno-tree-forwprop" } */ + +int +foo (unsigned int x, int y) +{ + int *z = (int *)&x; + return (y == 0) ? y : *z; +} diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c index 71e7b67bf52..9e6eb9c41dd 100644 --- a/gcc/tree-ssa-phiopt.c +++ b/gcc/tree-ssa-phiopt.c @@ -548,8 +548,12 @@ factor_out_conditional_conversion (edge e0, edge e1, gphi *phi, /* Create the conversion stmt and insert it. */ if (convert_code == VIEW_CONVERT_EXPR) - temp = fold_build1 (VIEW_CONVERT_EXPR, TREE_TYPE (result), temp); - new_stmt = gimple_build_assign (result, convert_code, temp); + { + temp = fold_build1 (VIEW_CONVERT_EXPR, TREE_TYPE (result), temp); + new_stmt = gimple_build_assign (result, temp); + } + else + new_stmt = gimple_build_assign (result, convert_code, temp); gsi = gsi_after_labels (gimple_bb (phi)); gsi_insert_before (&gsi, new_stmt, GSI_SAME_STMT); -- 2.30.2