The following makes copyprop simplify conditions properly (it's now also copy-propagating constants, thus more opportunities arise). That fixes the testcase which previously failed to constant-propagate the __builtin_constant_p result into the asm.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2014-07-14 Richard Biener <rguent...@suse.de> * tree-ssa-copy.c (copy_prop_visit_cond_stmt): Always try simplifying a condition. * gcc.dg/tree-ssa/ssa-copyprop-2.c: New testcase. Index: gcc/tree-ssa-copy.c =================================================================== --- gcc/tree-ssa-copy.c (revision 212514) +++ gcc/tree-ssa-copy.c (working copy) @@ -237,38 +237,26 @@ copy_prop_visit_cond_stmt (gimple stmt, enum ssa_prop_result retval = SSA_PROP_VARYING; location_t loc = gimple_location (stmt); - tree op0 = gimple_cond_lhs (stmt); - tree op1 = gimple_cond_rhs (stmt); + tree op0 = valueize_val (gimple_cond_lhs (stmt)); + tree op1 = valueize_val (gimple_cond_rhs (stmt)); - /* The only conditionals that we may be able to compute statically - are predicates involving two SSA_NAMEs. */ - if (TREE_CODE (op0) == SSA_NAME && TREE_CODE (op1) == SSA_NAME) + /* See if we can determine the predicate's value. */ + if (dump_file && (dump_flags & TDF_DETAILS)) { - op0 = valueize_val (op0); - op1 = valueize_val (op1); - - /* See if we can determine the predicate's value. */ - if (dump_file && (dump_flags & TDF_DETAILS)) - { - fprintf (dump_file, "Trying to determine truth value of "); - fprintf (dump_file, "predicate "); - print_gimple_stmt (dump_file, stmt, 0, 0); - } + fprintf (dump_file, "Trying to determine truth value of "); + fprintf (dump_file, "predicate "); + print_gimple_stmt (dump_file, stmt, 0, 0); + } - /* We can fold COND and get a useful result only when we have - the same SSA_NAME on both sides of a comparison operator. */ - if (op0 == op1) - { - tree folded_cond = fold_binary_loc (loc, gimple_cond_code (stmt), - boolean_type_node, op0, op1); - if (folded_cond) - { - basic_block bb = gimple_bb (stmt); - *taken_edge_p = find_taken_edge (bb, folded_cond); - if (*taken_edge_p) - retval = SSA_PROP_INTERESTING; - } - } + /* Fold COND and see whether we get a useful result. */ + tree folded_cond = fold_binary_loc (loc, gimple_cond_code (stmt), + boolean_type_node, op0, op1); + if (folded_cond) + { + basic_block bb = gimple_bb (stmt); + *taken_edge_p = find_taken_edge (bb, folded_cond); + if (*taken_edge_p) + retval = SSA_PROP_INTERESTING; } if (dump_file && (dump_flags & TDF_DETAILS) && *taken_edge_p) Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-copyprop-2.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/ssa-copyprop-2.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/ssa-copyprop-2.c (working copy) @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-Og -fdump-tree-optimized" } */ + +extern long long __sdt_unsp; +void +f(void) +{ + for (;;) + __asm__ ("%0" :: "i" (((!__extension__ (__builtin_constant_p ((((unsigned long long) (__typeof (__builtin_choose_expr (((__builtin_classify_type (0) + 3) & -4) == 4, (0), 0U))) __sdt_unsp) ) == 0) )) ? 1 : -1) )); +} + +/* { dg-final { scan-tree-dump-not "PHI" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */