Index: builtins.c =================================================================== --- builtins.c (revision 228094) +++ builtins.c (working copy) @@ -5866,6 +5866,8 @@ expand_stack_save (void) static rtx expand_builtin_acc_on_device (tree exp, rtx target) { + gcc_unreachable (); + #ifndef ACCEL_COMPILER gcc_assert (!get_oacc_fn_attrib (current_function_decl)); #endif @@ -10272,6 +10274,27 @@ fold_builtin_1 (location_t loc, tree fnd return build_empty_stmt (loc); break; + case BUILT_IN_ACC_ON_DEVICE: + /* Don't fold on_device until we know which compiler is active. */ + if (symtab->state == EXPANSION) + { + unsigned val_host = GOMP_DEVICE_HOST; + unsigned val_dev = GOMP_DEVICE_NONE; + +#ifdef ACCEL_COMPILER + val_host = GOMP_DEVICE_NOT_HOST; + val_dev = ACCEL_COMPILER_acc_device; +#endif + tree host = build2 (EQ_EXPR, boolean_type_node, arg0, + build_int_cst (integer_type_node, val_host)); + tree dev = build2 (EQ_EXPR, boolean_type_node, arg0, + build_int_cst (integer_type_node, val_dev)); + + tree result = build2 (TRUTH_OR_EXPR, boolean_type_node, host, dev); + return fold_convert (integer_type_node, result); + } + break; + default: break; } Index: omp-low.c =================================================================== --- omp-low.c (revision 228094) +++ omp-low.c (working copy) @@ -14725,21 +14725,20 @@ static void oacc_xform_on_device (gcall *call) { tree arg = gimple_call_arg (call, 0); - unsigned val = GOMP_DEVICE_HOST; - -#ifdef ACCEL_COMPILER - val = GOMP_DEVICE_NOT_HOST; -#endif - tree result = build2 (EQ_EXPR, boolean_type_node, arg, - build_int_cst (integer_type_node, val)); + unsigned val_host = GOMP_DEVICE_HOST; + unsigned val_dev = GOMP_DEVICE_NONE; + #ifdef ACCEL_COMPILER - { - tree dev = build2 (EQ_EXPR, boolean_type_node, arg, - build_int_cst (integer_type_node, - ACCEL_COMPILER_acc_device)); - result = build2 (TRUTH_OR_EXPR, boolean_type_node, result, dev); - } + val_host = GOMP_DEVICE_NOT_HOST; + val_dev = ACCEL_COMPILER_acc_device; #endif + + tree host = build2 (EQ_EXPR, boolean_type_node, arg, + build_int_cst (integer_type_node, val_host)); + tree dev = build2 (EQ_EXPR, boolean_type_node, arg, + build_int_cst (integer_type_node, val_dev)); + + tree result = build2 (TRUTH_OR_EXPR, boolean_type_node, host, dev); result = fold_convert (integer_type_node, result); tree lhs = gimple_call_lhs (call); gimple_seq seq = NULL; @@ -14879,7 +14878,7 @@ execute_oacc_transform () gcall *call = as_a (stmt); - if (gimple_call_builtin_p (call, BUILT_IN_ACC_ON_DEVICE)) + if (0 && gimple_call_builtin_p (call, BUILT_IN_ACC_ON_DEVICE)) /* acc_on_device must be evaluated at compile time for constant arguments. */ {