已合并
[Backport] i386: Enable vector cost comparison by default #389
[Backport] i386: Enable vector cost comparison by default #389
已合并
haibaoo创建于 8月13日
共 7 个文件变更+66-3
@@ -23034,7 +23034,7 @@ ix86_autovectorize_vector_modes (vector_modes *modes, bool all)
23034 if (TARGET_SSE2)23034 if (TARGET_SSE2)
23035 modes->safe_push (V4QImode);23035 modes->safe_push (V4QImode);
23036 23036 
23037- return 0;23037+ return ix86_vect_compare_costs ? VECT_COMPARE_COSTS : 0;
23038}23038}
23039 23039 
23040/* Implemenation of targetm.vectorize.get_mask_mode. */23040/* Implemenation of targetm.vectorize.get_mask_mode. */
@@ -23289,6 +23289,23 @@ ix86_vector_costs::add_stmt_cost (int count, vect_cost_for_stmt kind,
23289 stmt_cost = ix86_cost->add;23289 stmt_cost = ix86_cost->add;
23290 break;23290 break;
23291 default:23291 default:
23292+ if (truth_value_p (subcode))
23293+ {
23294+ if (SSE_FLOAT_MODE_SSEMATH_OR_HF_P (mode))
23295+ /* CMPccS? instructions are cheap, so use sse_op. While they
23296+ produce a mask which may need to be turned to 0/1 by and,
23297+ expect that this will be optimized away in a common case. */
23298+ stmt_cost = ix86_cost->sse_op;
23299+ else if (X87_FLOAT_MODE_P (mode))
23300+ /* fcmp + setcc. */
23301+ stmt_cost = ix86_cost->fadd + ix86_cost->add;
23302+ else if (VECTOR_MODE_P (mode))
23303+ stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
23304+ else
23305+ /* setcc. */
23306+ stmt_cost = ix86_cost->add;
23307+ break;
23308+ }
23292 break;23309 break;
23293 }23310 }
23294 }23311 }
@@ -1219,6 +1219,10 @@ Do not use GOT to access external symbols.
1219Target Joined UInteger Var(x86_stlf_window_ninsns) Init(64) Param1219Target Joined UInteger Var(x86_stlf_window_ninsns) Init(64) Param
1220Instructions number above which STFL stall penalty can be compensated.1220Instructions number above which STFL stall penalty can be compensated.
1221 1221 
1222+-param=ix86-vect-compare-costs=
1223+Target Joined UInteger Var(ix86_vect_compare_costs) Init(1) IntegerRange(0, 1) Param Optimization
1224+Whether x86 vectorizer cost modeling compares costs of different vector sizes.
1225+ 
1222munroll-only-small-loops1226munroll-only-small-loops
1223Target Var(ix86_unroll_only_small_loops) Init(0) Save1227Target Var(ix86_unroll_only_small_loops) Init(0) Save
1224Enable conservative small loop unrolling.1228Enable conservative small loop unrolling.
@@ -15271,6 +15271,11 @@ The following choices of @var{name} are available on i386 and x86_64 targets:
15271@item x86-stlf-window-ninsns15271@item x86-stlf-window-ninsns
15272Instructions number above which STFL stall penalty can be compensated.15272Instructions number above which STFL stall penalty can be compensated.
15273 15273 
15274+@item ix86-vect-compare-costs
15275+Whether x86 vectorizer cost modeling compares costs of different vector sizes.
15276+The value may be 0 or 1. The default is 1; set it to 0 to restore the
15277+previous behavior.
15278+ 
15274@end table15279@end table
15275 15280 
15276@end table15281@end table
@@ -0,0 +1,21 @@
1+/* { dg-do compile } */
2+ 
3+static float
4+muladd (float x, float y, float z)
5+{
6+ return x * y + z;
7+}
8+ 
9+float
10+g (float x[], long n)
11+{
12+ float r0 = 0, r1 = 0;
13+ for (; n; x += 2, n--)
14+ {
15+ r0 = muladd (x[0], x[0], r0);
16+ r1 = muladd (x[1], x[1], r1);
17+ }
18+ return r0 + r1;
19+}
20+ 
21+/* { dg-final { scan-tree-dump "Choosing vector mode V8QI" "vect" } } */
@@ -0,0 +1,16 @@
1+/* { dg-do compile } */
2+/* This test relies on the EulerGCC-specific c86-4g-m7 cost model. */
3+/* { dg-additional-options "-mtune=c86-4g-m7" } */
4+ 
5+void foo (int *block)
6+{
7+ for (int i = 0; i < 3; ++i)
8+ {
9+ int a = block[i * 9];
10+ int b = block[i * 9 + 1];
11+ block[i * 9] = a + 10;
12+ block[i * 9 + 1] = b + 10;
13+ }
14+}
15+ 
16+/* { dg-final { scan-tree-dump "optimized: loop vectorized using 8 byte vectors" "vect" } } */
@@ -85,6 +85,6 @@ int main()
85 __builtin_abort ();85 __builtin_abort ();
86}86}
87 87 
88-/* { dg-final { scan-tree-dump-times "Alignment of access forced using peeling" 4 "vect" } } */ 88+/* { dg-final { scan-tree-dump-times "Alignment of access forced using peeling" 7 "vect" } } */
89/* Verify all vector accesses are emitted as aligned. */89/* Verify all vector accesses are emitted as aligned. */
90/* { dg-final { scan-assembler-not "movup" } } */90/* { dg-final { scan-assembler-not "movup" } } */
@@ -85,6 +85,6 @@ int main()
85 __builtin_abort ();85 __builtin_abort ();
86}86}
87 87 
88-/* { dg-final { scan-tree-dump-times "Alignment of access forced using peeling" 4 "vect" } } */ 88+/* { dg-final { scan-tree-dump-times "Alignment of access forced using peeling" 7 "vect" } } */
89/* Verify all vector accesses are emitted as aligned. */89/* Verify all vector accesses are emitted as aligned. */
90/* { dg-final { scan-assembler-not "movup" } } */90/* { dg-final { scan-assembler-not "movup" } } */