Hi! This patch propagates attributes, including opt and target nodes, from the containing function to the OMP/OACC outlined region functions.
Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2017-10-04 Jakub Jelinek <ja...@redhat.com> PR tree-optimization/82374 * omp-low.c (create_omp_child_function): Copy DECL_ATTRIBUTES, DECL_FUNCTION_SPECIFIC_OPTIMIZATION, DECL_FUNCTION_SPECIFIC_TARGET and DECL_FUNCTION_VERSIONED from current_function_decl to the new decl. * gcc.dg/gomp/pr82374.c: New test. --- gcc/omp-low.c.jj 2017-09-05 23:32:02.000000000 +0200 +++ gcc/omp-low.c 2017-10-03 12:25:13.956261522 +0200 @@ -1626,6 +1626,14 @@ create_omp_child_function (omp_context * DECL_CONTEXT (decl) = NULL_TREE; DECL_INITIAL (decl) = make_node (BLOCK); BLOCK_SUPERCONTEXT (DECL_INITIAL (decl)) = decl; + DECL_ATTRIBUTES (decl) = DECL_ATTRIBUTES (current_function_decl); + DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl) + = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (current_function_decl); + DECL_FUNCTION_SPECIFIC_TARGET (decl) + = DECL_FUNCTION_SPECIFIC_TARGET (current_function_decl); + DECL_FUNCTION_VERSIONED (decl) + = DECL_FUNCTION_VERSIONED (current_function_decl); + if (omp_maybe_offloaded_ctx (ctx)) { cgraph_node::get_create (decl)->offloadable = 1; --- gcc/testsuite/gcc.dg/gomp/pr82374.c.jj 2017-10-03 13:09:15.515879118 +0200 +++ gcc/testsuite/gcc.dg/gomp/pr82374.c 2017-10-03 13:08:56.000000000 +0200 @@ -0,0 +1,31 @@ +/* PR tree-optimization/82374 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-tree-vectorize -fdump-tree-vect-details" } */ +/* { dg-additional-options "-mavx -mno-avx2" { target i?86-*-* x86_64-*-* } } */ +/* { dg-additional-options "-mvsx" { target powerpc_vsx_ok } } */ + +#define SIZE (1024 * 1024 * 1024) + +float a[SIZE]; +float b[SIZE]; +float c[SIZE]; +float d[SIZE]; + +__attribute__((optimize ("O2", "tree-vectorize"))) void +foo (void) +{ + int i; +#pragma omp parallel for + for (i = 0; i < SIZE; i++) + c[i] = a[i] + b[i]; +} + +__attribute__((optimize ("O2", "tree-vectorize"))) void +bar (void) +{ + int i; + for (i = 0; i < SIZE; i++) + d[i] = a[i] + b[i]; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" { target { { i?86-*-* x86_64-*-* } || { powerpc_vsx_ok } } } } } */ Jakub