With the x86 vectorizer cost-model rewrite we ended up costing scalar conversions as nothing. After my patch using the proper target cost estimates for the scalar version this now exposes underestimating scalar cost and thus no longer vectorizing the testcase in this PR. This fix is to restrict zero-costing to sign-conversions, all other conversions are possibly value-changing. I guess some zero-extensions are free as well but I didn't want to get too fancy as I'm not sure about QImode -> SImode conversions for example since whether that's free (can just use %eax instead of %ax) likely depends on context.
Bootstrap and regtest running on x86_64-unknown-linux-gnu. OK? Thanks, Richard. 2018-03-20 Richard Biener <rguent...@suse.de> PR target/84986 * config/i386/i386.c (ix86_add_stmt_cost): Only cost sign-conversions as zero, fall back to standard scalar_stmt cost for the rest. * gcc.dg/vect/costmodel/x86_64/costmodel-pr84986.c: New testcase. Index: gcc/config/i386/i386.c =================================================================== --- gcc/config/i386/i386.c (revision 258674) +++ gcc/config/i386/i386.c (working copy) @@ -50462,7 +50462,11 @@ ix86_add_stmt_cost (void *data, int coun } break; case NOP_EXPR: - stmt_cost = 0; + /* Only sign-conversions are free. */ + if (tree_nop_conversion_p + (TREE_TYPE (gimple_assign_lhs (stmt_info->stmt)), + TREE_TYPE (gimple_assign_rhs1 (stmt_info->stmt)))) + stmt_cost = 0; break; case BIT_IOR_EXPR: Index: gcc/testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-pr84986.c =================================================================== --- gcc/testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-pr84986.c (nonexistent) +++ gcc/testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-pr84986.c (working copy) @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_long } */ + +int N; +long fn1(void) { + short i; + long a; + i = a = 0; + while (i < N) + a -= i++; + return a; +} + +/* { dg-final { scan-tree-dump "vectorized 1 loops" "vect" } } */