From patchwork Thu Aug 29 23:28:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xinliang David Li X-Patchwork-Id: 270999 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "www.sourceware.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 68A342C00A4 for ; Fri, 30 Aug 2013 09:28:41 +1000 (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:date:message-id:subject:from:to:cc:content-type; q=dns; s=default; b=cr6I51u2NnRrC0nyz4da7YHBMRrGbesYxUzlSBHhZa7 8q8XqC5PrySe+umbQaVqqh5etbgc6L973lwoerE3sPpl3oWaq9El8kSBR2hgLjOD 65LPCDJZnnGCMSTDsnS/NiPyhqrMubImWri2IISMCimHNJ7+MZ7cLyn+eYtdW88s = 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:date:message-id:subject:from:to:cc:content-type; s=default; bh=nSG2JXk1iPXSxaQqhE7x7fToOVc=; b=OInZ9dfCOXqEmAGDB QM6wO7ApbsPtxvfwjBaEq/SM1O3TtQlgClhMUl3mlgb0ZNwny7YAVN6gtlMreEKF zz5vg2rcOkLhkk253JaPpQAWIIPTujwP632sKzLLHLf196q4lbB6eZMQvbKxOi77 SKUewCokTJ97XpBSZOkPXOW5ko= Received: (qmail 19929 invoked by alias); 29 Aug 2013 23:28:35 -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 19916 invoked by uid 89); 29 Aug 2013 23:28:34 -0000 Received: from mail-pb0-f50.google.com (HELO mail-pb0-f50.google.com) (209.85.160.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 29 Aug 2013 23:28:34 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, BAYES_00, NO_RELAYS autolearn=ham version=3.3.2 X-HELO: mail-pb0-f50.google.com Received: by mail-pb0-f50.google.com with SMTP id uo5so1085472pbc.37 for ; Thu, 29 Aug 2013 16:28:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc :content-type; bh=FndRszVclBewU2mH2nOCiVrLe4fXqbVxA71SfzDFfKo=; b=EMIfbTbi5m7llfTsUh1dPnTHPxrkpRJXtNiEzVsW5JI1FlY7xgZI9xxdDMa9043V0m OxwJrEEy/wBulmtOM1Hhfgnpq8nVIkQyf4hk7lLaGbb5mmXjvHtgT74jkEM5cHN5Vqfe YO8ePECdS/64q91/1e8bBIh66rVIka+GvBj4Lf+RSAB5leidhyE0Ff+3IINREbGTWzDY J9/DASb7RYPyJ1Cds8ZukPw5BiuZr+RKjmbgHuCjwdOMv2r3W+bMxH1kOgyn2wH2O/KG eottomB2l6Xl/ukOnzYSgDRwM1CMzzleMijmrD055+t3J2IMSXt4s4Pk+ttJr75VBHVz 5inw== X-Gm-Message-State: ALoCoQnm4TwZ0r2IiMm7/YkZT1QYUvuwit+pTxT7sSzZGe9iDBqiGfcLlw9GlZcnwG0uet2GXLHxTBGSZtY30U7fMQKVDRIhp5Ghh/jQXZ3gmbK22eYJ6Sktg4QADAaa0qv9VT7GrS8h/QM19jc+KhhDoJrlQdi6QCwdkEDd28yiirrpCMkQg9TBBCvFNA67YHY7D4nH/tc3N3IsC0JcErahWKzVl854pA== MIME-Version: 1.0 X-Received: by 10.66.178.143 with SMTP id cy15mr7129724pac.105.1377818911827; Thu, 29 Aug 2013 16:28:31 -0700 (PDT) Received: by 10.70.11.3 with HTTP; Thu, 29 Aug 2013 16:28:31 -0700 (PDT) Date: Thu, 29 Aug 2013 16:28:31 -0700 Message-ID: Subject: Eliminate vectorizer analysis side effects From: Xinliang David Li To: GCC Patches Cc: Richard Guenther I was debugging a runtime failure of SPEC06 xalancbmk built with LIPO. Using -fdisable- option pinpoints the problem in slp vectorize pass on a particular function. dbgcnt support is added to to track down the individual BB, but it fails even when the dbg count is set to 0. It turns out that no BB was actually vectorized for that function, but turning on/off slp-vectorize does make a difference in generated code -- the only difference between the good and bad case is stack layout. The problem is in the alignment analysis phase -- which speculatively changes the base declaration's alignment regardless whether the vectorization transformation will be performed or not later. The attached patch fixes the problem. Testing is ok. Ok for trunk? thanks, David Index: ChangeLog =================================================================== --- ChangeLog (revision 202088) +++ ChangeLog (working copy) @@ -1,5 +1,17 @@ 2013-08-29 Xinliang David Li + * tree-vect-data-refs.c (vect_compute_data_ref_alignment): + Delay base decl alignment adjustment. + * tree-vectorizer.c (ensure_base_alignment): New function. + (vectorize_loops): Add dbg_cnt support. Perform alignment + adjustment. + (execute_vect_slp): Ditto. + * dbgcnt.def: New debug counter. + * tree-data-ref.h: New fields. + * Makefile: New dependency. + +2013-08-29 Xinliang David Li + * loop-unroll.c (report_unroll_peel): Minor message change. * tree-vect-loop-manip.c (vect_do_peeling_for_alignment): Index: tree-vect-data-refs.c =================================================================== --- tree-vect-data-refs.c (revision 202088) +++ tree-vect-data-refs.c (working copy) @@ -763,15 +763,10 @@ vect_compute_data_ref_alignment (struct dump_generic_expr (MSG_NOTE, TDF_SLIM, ref); } - DECL_ALIGN (base) = TYPE_ALIGN (vectype); - DECL_USER_ALIGN (base) = 1; + DR_BASE_DECL (dr) = base; + DR_BASE_MISALIGNED (dr) = true; } - /* At this point we assume that the base is aligned. */ - gcc_assert (base_aligned - || (TREE_CODE (base) == VAR_DECL - && DECL_ALIGN (base) >= TYPE_ALIGN (vectype))); - /* If this is a backward running DR then first access in the larger vectype actually is N-1 elements before the address in the DR. Adjust misalign accordingly. */ Index: dbgcnt.def =================================================================== --- dbgcnt.def (revision 202088) +++ dbgcnt.def (working copy) @@ -172,6 +172,8 @@ DEBUG_COUNTER (pre_insn) DEBUG_COUNTER (treepre_insert) DEBUG_COUNTER (tree_sra) DEBUG_COUNTER (eipa_sra) +DEBUG_COUNTER (vect_loop) +DEBUG_COUNTER (vect_slp) DEBUG_COUNTER (sched2_func) DEBUG_COUNTER (sched_block) DEBUG_COUNTER (sched_func) Index: tree-vectorizer.c =================================================================== --- tree-vectorizer.c (revision 202088) +++ tree-vectorizer.c (working copy) @@ -68,6 +68,7 @@ along with GCC; see the file COPYING3. #include "tree-pass.h" #include "hash-table.h" #include "tree-ssa-propagate.h" +#include "dbgcnt.h" /* Loop or bb location. */ LOC vect_location; @@ -279,6 +280,37 @@ note_simd_array_uses (hash_table datarefs; + struct data_reference *dr; + unsigned int i; + + if (loop_vinfo) + datarefs = LOOP_VINFO_DATAREFS (loop_vinfo); + else + datarefs = BB_VINFO_DATAREFS (bb_vinfo); + + FOR_EACH_VEC_ELT (datarefs, i, dr) + { + tree base_decl = DR_BASE_DECL (dr); + if (base_decl && DR_BASE_MISALIGNED (dr)) + { + gimple stmt = DR_STMT (dr); + stmt_vec_info stmt_info = vinfo_for_stmt (stmt); + tree vectype = STMT_VINFO_VECTYPE (stmt_info); + DECL_ALIGN (base_decl) = TYPE_ALIGN (vectype); + DECL_USER_ALIGN (base_decl) = 1; + DR_BASE_MISALIGNED (dr) = false; + } + } +} + + /* Function vectorize_loops. Entry point to loop vectorization phase. */ @@ -331,10 +363,14 @@ vectorize_loops (void) if (!loop_vinfo || !LOOP_VINFO_VECTORIZABLE_P (loop_vinfo)) continue; + if (!dbg_cnt (vect_loop)) + break; + if (LOCATION_LOCUS (vect_location) != UNKNOWN_LOC && dump_enabled_p ()) dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, vect_location, "loop vectorized\n"); + ensure_base_alignment (loop_vinfo, NULL); vect_transform_loop (loop_vinfo); num_vectorized_loops++; /* Now that the loop has been vectorized, allow it to be unrolled @@ -431,6 +467,7 @@ static unsigned int execute_vect_slp (void) { basic_block bb; + bb_vec_info bb_vinfo; init_stmt_vec_info_vec (); @@ -438,8 +475,12 @@ execute_vect_slp (void) { vect_location = find_bb_location (bb); - if (vect_slp_analyze_bb (bb)) + if ((bb_vinfo = vect_slp_analyze_bb (bb))) { + if (!dbg_cnt (vect_slp)) + break; + + ensure_base_alignment (NULL, bb_vinfo); vect_slp_transform_bb (bb); if (dump_enabled_p ()) dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, vect_location, Index: tree-data-ref.h =================================================================== --- tree-data-ref.h (revision 202088) +++ tree-data-ref.h (working copy) @@ -176,6 +176,12 @@ struct data_reference /* Auxiliary info specific to a pass. */ void *aux; + /* Base var decl. */ + tree base_decl; + + /* A boolean indicating if the base decl is misaligned. */ + bool base_misaligned; + /* True when the data reference is in RHS of a stmt. */ bool is_read; @@ -193,6 +199,8 @@ struct data_reference }; #define DR_STMT(DR) (DR)->stmt +#define DR_BASE_DECL(DR) (DR)->base_decl +#define DR_BASE_MISALIGNED(DR) (DR)->base_misaligned #define DR_REF(DR) (DR)->ref #define DR_BASE_OBJECT(DR) (DR)->indices.base_object #define DR_UNCONSTRAINED_BASE(DR) (DR)->indices.unconstrained_base