From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 6D1043858402 for ; Fri, 12 Nov 2021 13:13:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6D1043858402 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 77C561FD5B; Fri, 12 Nov 2021 13:13:00 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5364613C26; Fri, 12 Nov 2021 13:13:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2CU0ElxojmFpHAAAMHmgww (envelope-from ); Fri, 12 Nov 2021 13:13:00 +0000 Date: Fri, 12 Nov 2021 14:12:59 +0100 (CET) From: Richard Biener To: "Andre Vieira (lists)" cc: "gcc-patches@gcc.gnu.org" , richard.sandiford@arm.com Subject: Re: [PATCH 1v2/3][vect] Add main vectorized loop unrolling In-Reply-To: <33cb143e-bb2e-e214-cd5f-66fd2d1bd20b@arm.com> Message-ID: <5op15ns-4sq8-2sn3-41qs-49q44417sp6@fhfr.qr> References: <4a2e6dde-cc5c-97fe-7a43-bd59d542c2ce@arm.com> <27777876-4201-5e86-bf9a-063143d38641@arm.com> <4272814n-8538-p793-157q-5n6q16r48n51@fhfr.qr> <623fbfd9-b97c-8c6e-0348-07d6c4496592@arm.com> <5c887c48-7f7e-c02b-2998-7a7c41b11af8@arm.com> <33cb143e-bb2e-e214-cd5f-66fd2d1bd20b@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Nov 2021 13:13:04 -0000 On Thu, 11 Nov 2021, Andre Vieira (lists) wrote: > Hi, > > This is the rebased and reworked version of the unroll patch.  I wasn't > entirely sure whether I should compare the costs of the unrolled loop_vinfo > with the original loop_vinfo it was unrolled of. I did now, but I wasn't too > sure whether it was a good idea to... Any thoughts on this? + /* Apply the suggested unrolling factor, this was determined by the backend + during finish_cost the first time we ran the analyzis for this + vector mode. */ + if (loop_vinfo->suggested_unroll_factor > 1) + { + poly_uint64 unrolled_vf + = LOOP_VINFO_VECT_FACTOR (loop_vinfo) * loop_vinfo->suggested_unroll_factor; + /* Make sure the unrolled vectorization factor is less than the max + vectorization factor. */ + unsigned HOST_WIDE_INT max_vf = LOOP_VINFO_MAX_VECT_FACTOR (loop_vinfo); + if (max_vf == MAX_VECTORIZATION_FACTOR || known_le (unrolled_vf, max_vf)) + LOOP_VINFO_VECT_FACTOR (loop_vinfo) = unrolled_vf; + else + return opt_result::failure_at (vect_location, + "unrolling failed: unrolled" + " vectorization factor larger than" + " maximum vectorization factor: %d\n", + LOOP_VINFO_MAX_VECT_FACTOR (loop_vinfo)); + } + /* This is the point where we can re-start analysis with SLP forced off. */ start_over: So we're honoring suggested_unroll_factor here but you still have the now unused hunk +vect_analyze_loop_2 (loop_vec_info loop_vinfo, bool &fatal, + unsigned *suggested_unroll_factor, poly_uint64 min_vf = 2) { I also wonder whether vect_analyze_loop_2 could at least prune suggested_unroll_factor as set by vect_analyze_loop_costing with its knowledge of max_vf itself? That would avoid using the at the moment unused LOOP_VINFO_MAX_VECT_FACTOR? I think all the things you do in vect_can_unroll should be figured out with the re-analysis, and I'd just amend vect_analyze_loop_1 with a suggested unroll factor parameter like it has main_loop_vinfo for the epilogue case. The main loop adjustment would the be in the if (first_loop_vinfo == NULL) { first_loop_vinfo = loop_vinfo; first_loop_i = loop_vinfo_i; first_loop_next_i = mode_i; } spot only, adding if (loop_vinfo->suggested_unroll_factor != 1) { suggested_unroll_factor = loop_vinfo->suggested_unroll_factor; mode_i = first_loop_i; if (dump) dump_print ("Trying unrolling by %d\n"); continue; } and a reset of suggested_unroll_factor after the vect_analyze_loop_1 call? (that's basically pushing another analysis case to the poor-mans "worklist") Richard. > Regards, > > Andre > > > gcc/ChangeLog: > >         * tree-vect-loop.c (vect_estimate_min_profitable_iters): Add > suggested_unroll_factor parameter. >         (vect_analyze_loop_costing): Likewise. >         (vect_determine_partial_vectors_and_peeling): Don't mask an > unrolled loop. >         (vect_analyze_loop_2): Support unrolling of loops. >         (vect_can_unroll): New function. >         (vect_try_unrolling): New function. >         (vect_analyze_loop_1): Add suggested_unroll_factor parameter > and use it. >         (vect_analyze_loop): Call vect_try_unrolling when unrolling suggested. >         (vectorizable_reduction): Don't single_defuse_cycle when unrolling. >         * tree-vectorizer.h (_loop_vec_info::_loop_vec_info):  Add > suggested_unroll_factor member. >         (vector_costs::vector_costs): Add m_suggested_unroll_factor member. >         (vector_costs::suggested_unroll_factor): New getter. >         (finish_cost): Add suggested_unroll_factor out parameter and > set it. > > -- Richard Biener SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany; GF: Felix Imend