From patchwork Sat Nov 23 08:05:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Mi X-Patchwork-Id: 293636 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A65212C00B1 for ; Sat, 23 Nov 2013 19:05:35 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=MZhKPyV4CAgmYaJMkF dVNo9PG900x6l4/4/vaq+umnUT2LYorO8tdrLrIBvUrIt5o8w4Vt9XQL0lRy7XAc 7Obr+Kenj3ufK0S55O1TewSA26t42c9VPcbICXLPr5tvbtlNN0ZxVh2a6nquNNHl HjNqkMJZ55mHp3nHbeo8iuCGA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=Im5+XmJIwkLL1a3dG4gqaSTb Bxk=; b=nuva0vuJ6/3m0/JchuEwkvPw3jXBa+grG5uEXa3NmB91WbUxbeGcNXr6 6mbT66EzZ0xBJj5ffxVWX72QPRqqWGvPC/H55W1mBAv1a3TcIyxIA5gKkypGwrnz Egs67vnIwtubD42pt3b2TbfdUZIRUH3lLZHgqmTnE/Yx6bj48aE= Received: (qmail 3421 invoked by alias); 23 Nov 2013 08:05:22 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 3411 invoked by uid 89); 23 Nov 2013 08:05:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.5 required=5.0 tests=AWL, BAYES_99, RDNS_NONE, SPF_PASS, URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: mail-oa0-f48.google.com Received: from Unknown (HELO mail-oa0-f48.google.com) (209.85.219.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 23 Nov 2013 08:05:17 +0000 Received: by mail-oa0-f48.google.com with SMTP id l6so2391569oag.21 for ; Sat, 23 Nov 2013 00:05:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=DtsMDRxJ1QVDqo9nKh/hmpJ4wKqkH0ZZQGkx1AdyvkA=; b=ZxJinS5mZmGVgAuYFid5sOcNywcM5A1vc/AIDz8bR75oU/QalKYLZigsuAz3DJkuFL 2/mnS80blyrJZby62Exn29Ao4K53JigtJV9oZKtDrUImYQ3xmXazHxbygdMQIXIhFnLH ir4b4WjHp9klzl9n0y4TmZn9k6KP8h5PSu9drKk3/M2DNVS5e6d9wnPqb1GuwQWE/24r kApCdarmJXcnc3GQpT9le1kF3P6/y7gxG7c0IOabdT7g5LSSn02quj7fcFNlGIpj8F99 sjAlxgKKkwqB1wuSQoPvJtN3iSEADObmgM6AFc2PciZI99xWXo1evU6nHbzVOBlI6Z7o gQtg== X-Gm-Message-State: ALoCoQmF8POWYGPXRjSVuTwHtzwN1qDX3295Gca375pd7jJ7ctskMG2WgVcvakLkAqB/JX0zo0wc5zUQohbKI7GzSidHplDEgUY+eEI3LjP6zY6qJ06Ez7Mz42VvtKUCEhZjxC+rxxfdSrT8S7gS4Csyk1AISW0RoKe+iZbDhknWxuyjof4eYSySmK2KJx9peoBhnTo5yFFA1QU4FuMBPtHKNYOvhcYNsA== MIME-Version: 1.0 X-Received: by 10.60.94.164 with SMTP id dd4mr7753oeb.68.1385193909241; Sat, 23 Nov 2013 00:05:09 -0800 (PST) Received: by 10.76.75.3 with HTTP; Sat, 23 Nov 2013 00:05:09 -0800 (PST) In-Reply-To: <20131121081913.GB23315@kam.mff.cuni.cz> References: <20131121081913.GB23315@kam.mff.cuni.cz> Date: Sat, 23 Nov 2013 00:05:09 -0800 Message-ID: Subject: Re: [PATCH] Builtins handling in IVOPT From: Wei Mi To: Zdenek Dvorak Cc: GCC Patches , Richard Biener , David Li On Thu, Nov 21, 2013 at 12:19 AM, Zdenek Dvorak wrote: > Hi, > >> This patch works on the intrinsic calls handling issue in IVOPT mentioned here: >> http://gcc.gnu.org/ml/gcc-patches/2010-10/msg01295.html >> >> In find_interesting_uses_stmt, it changes >> >> arg = expr >> __builtin_xxx (arg) >> >> to >> >> arg = expr; >> tmp = addr_expr (mem_ref(arg)); >> __builtin_xxx (tmp, ...) > > this looks a bit confusing (and wasteful) to me. It would make more sense to > just record the argument as USE_ADDRESS and do the rewriting in rewrite_use_address. > > Zdenek I updated the patch. The gimple changing part is now moved to rewrite_use_address. Add support for plain address expr in addition to reference expr in find_interesting_uses_address. bootstrap and testing is going on. 2013-11-22 Wei Mi * expr.c (expand_expr_addr_expr_1): Not to split TMR. (expand_expr_real_1): Ditto. * targhooks.c (default_builtin_has_mem_ref_p): Default builtin. * tree-ssa-loop-ivopts.c (builtin_has_mem_ref_p): New function. (rewrite_use_address): Add TMR for builtin. (find_interesting_uses_stmt): Special handling of builtins. * gimple-expr.c (is_gimple_address): Add handling of TMR. * gimple-expr.h (is_gimple_addressable): Ditto. * config/i386/i386.c (ix86_builtin_has_mem_ref_p): New target hook. (ix86_atomic_assign_expand_fenv): Ditto. (ix86_expand_special_args_builtin): Special handling of TMR for builtin. * target.def (builtin_has_mem_ref_p): New hook. * doc/tm.texi.in: Ditto. * doc/tm.texi: Generated. 2013-11-22 Wei Mi * gcc.dg/tree-ssa/ivopt_5.c: New test. Index: testsuite/gcc.dg/tree-ssa/ivopt_5.c =================================================================== --- testsuite/gcc.dg/tree-ssa/ivopt_5.c (revision 0) +++ testsuite/gcc.dg/tree-ssa/ivopt_5.c (revision 0) @@ -0,0 +1,21 @@ +/* { dg-do compile { target {{ i?86-*-* x86_64-*-* } && lp64 } } } */ +/* { dg-options "-O2 -m64 -fdump-tree-ivopts-details" } */ + +/* Make sure only one iv is selected after IVOPT. */ + +#include +extern __m128i arr[], d[]; +void test (void) +{ + unsigned int b; + for (b = 0; b < 1000; b += 2) { + __m128i *p = (__m128i *)(&d[b]); + __m128i a = _mm_load_si128(&arr[4*b+3]); + __m128i v = _mm_loadu_si128(p); + v = _mm_xor_si128(v, a); + _mm_storeu_si128(p, v); + } +} + +/* { dg-final { scan-tree-dump-times "PHI stmt); tree base_hint = NULL_TREE; - tree ref, iv; + tree ref, iv, callee; bool ok; adjust_iv_update_pos (cand, use); @@ -6383,10 +6437,41 @@ rewrite_use_address (struct ivopts_data base_hint = var_at_stmt (data->current_loop, cand, use->stmt); iv = var_at_stmt (data->current_loop, cand, use->stmt); - ref = create_mem_ref (&bsi, TREE_TYPE (*use->op_p), &aff, - reference_alias_ptr_type (*use->op_p), - iv, base_hint, data->speed); - copy_ref_info (ref, *use->op_p); + + /* For builtin_call(addr_expr), change it to: + tmp = ADDR_EXPR(TMR(...)); + call (tmp); */ + if (is_gimple_call (use->stmt) + && (callee = gimple_call_fndecl (use->stmt)) + && is_builtin_fn (callee)) + { + gimple g; + gimple_seq seq = NULL; + tree addr; + tree type = TREE_TYPE (TREE_TYPE (*use->op_p)); + location_t loc = gimple_location (use->stmt); + gimple_stmt_iterator gsi = gsi_for_stmt (use->stmt); + + ref = create_mem_ref (&bsi, type, &aff, + TREE_TYPE (*use->op_p), + iv, base_hint, data->speed); + addr = build1 (ADDR_EXPR, TREE_TYPE (*use->op_p), ref); + g = gimple_build_assign_with_ops (ADDR_EXPR, + make_ssa_name (TREE_TYPE (*use->op_p), NULL), + addr, NULL); + gimple_set_location (g, loc); + gimple_seq_add_stmt_without_update (&seq, g); + gsi_insert_seq_before (&gsi, seq, GSI_SAME_STMT); + + ref = gimple_assign_lhs (g); + } + else + { + ref = create_mem_ref (&bsi, TREE_TYPE (*use->op_p), &aff, + reference_alias_ptr_type (*use->op_p), + iv, base_hint, data->speed); + copy_ref_info (ref, *use->op_p); + } *use->op_p = ref; } Index: config/i386/i386.c =================================================================== --- config/i386/i386.c (revision 204792) +++ config/i386/i386.c (working copy) @@ -29639,6 +29639,50 @@ ix86_init_mmx_sse_builtins (void) } } +/* Return whether the Ith param of the BUILTIN_FUNCTION + is a memory reference. If I == -1, return whether the + BUILTIN_FUNCTION contains any memory reference param. */ + +static bool +ix86_builtin_has_mem_ref_p (int builtin_function, int i) +{ + switch ((enum ix86_builtins) builtin_function) + { + /* LOAD. */ + case IX86_BUILTIN_LOADHPS: + case IX86_BUILTIN_LOADLPS: + case IX86_BUILTIN_LOADHPD: + case IX86_BUILTIN_LOADLPD: + if (i == -1 || i == 1) + return true; + break; + case IX86_BUILTIN_LOADUPS: + case IX86_BUILTIN_LOADUPD: + case IX86_BUILTIN_LOADDQU: + case IX86_BUILTIN_LOADUPD256: + case IX86_BUILTIN_LOADUPS256: + case IX86_BUILTIN_LOADDQU256: + case IX86_BUILTIN_LDDQU256: + if (i == -1 || i == 0) + return true; + break; + /* STORE. */ + case IX86_BUILTIN_STOREHPS: + case IX86_BUILTIN_STORELPS: + case IX86_BUILTIN_STOREUPS: + case IX86_BUILTIN_STOREUPD: + case IX86_BUILTIN_STOREDQU: + case IX86_BUILTIN_STOREUPD256: + case IX86_BUILTIN_STOREUPS256: + case IX86_BUILTIN_STOREDQU256: + if (i == -1 || i == 0) + return true; + default: + break; + } + return false; +} + /* This adds a condition to the basic_block NEW_BB in function FUNCTION_DECL to return a pointer to VERSION_DECL if the outcome of the expression formed by PREDICATE_CHAIN is true. This function will be called during @@ -32525,7 +32569,13 @@ ix86_expand_special_args_builtin (const if (i == memory) { /* This must be the memory operand. */ - op = force_reg (Pmode, convert_to_mode (Pmode, op, 1)); + + /* We expect the builtin could be expanded to rtl with memory + operand and proper addressing mode will be kept as specified + in TARGET_MEM_REF. */ + if (!(TREE_CODE (arg) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND (arg, 0)) == TARGET_MEM_REF)) + op = force_reg (Pmode, convert_to_mode (Pmode, op, 1)); op = gen_rtx_MEM (mode, op); gcc_assert (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode); @@ -43737,6 +43787,9 @@ ix86_atomic_assign_expand_fenv (tree *ho #undef TARGET_BUILTIN_RECIPROCAL #define TARGET_BUILTIN_RECIPROCAL ix86_builtin_reciprocal +#undef TARGET_BUILTIN_HAS_MEM_REF_P +#define TARGET_BUILTIN_HAS_MEM_REF_P ix86_builtin_has_mem_ref_p + #undef TARGET_ASM_FUNCTION_EPILOGUE #define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue Index: doc/tm.texi =================================================================== --- doc/tm.texi (revision 204792) +++ doc/tm.texi (working copy) @@ -709,6 +709,12 @@ If a target implements string objects th If a target implements string objects then this hook should should provide a facility to check the function arguments in @var{args_list} against the format specifiers in @var{format_arg} where the type of @var{format_arg} is one recognized as a valid string reference type. @end deftypefn +@deftypefn {Target Hook} bool TARGET_BUILTIN_HAS_MEM_REF_P (int @var{builtin_function}, int @var{i}) +This hook return whether the @var{i}th param of the @var{builtin_function} +is a memory reference. If @var{i} is -1, return whether the @var{builtin_function} +contains any memory reference type param. +@end deftypefn + @deftypefn {Target Hook} void TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE (void) This target function is similar to the hook @code{TARGET_OPTION_OVERRIDE} but is called when the optimize level is changed via an attribute or Index: doc/tm.texi.in =================================================================== --- doc/tm.texi.in (revision 204792) +++ doc/tm.texi.in (working copy) @@ -697,6 +697,8 @@ should use @code{TARGET_HANDLE_C_OPTION} @hook TARGET_CHECK_STRING_OBJECT_FORMAT_ARG +@hook TARGET_BUILTIN_HAS_MEM_REF_P + @hook TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE @defmac C_COMMON_OVERRIDE_OPTIONS