From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 58115 invoked by alias); 31 May 2017 08:15:58 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 58105 invoked by uid 89); 31 May 2017 08:15:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=H*Ad:U*law, Hx-languages-length:1433 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 31 May 2017 08:15:56 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 50EAF8123D; Wed, 31 May 2017 08:15:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 50EAF8123D Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jakub@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 50EAF8123D Received: from tucnak.zalov.cz (unknown [10.36.118.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E7F157E5DE; Wed, 31 May 2017 08:15:58 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v4V8FuTK016995; Wed, 31 May 2017 10:15:56 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v4V8Fs3c016994; Wed, 31 May 2017 10:15:54 +0200 Date: Wed, 31 May 2017 08:19:00 -0000 From: Jakub Jelinek To: Georg-Johann Lay Cc: Jeff Law , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Optimize divmod expansion (PR middle-end/79665) Message-ID: <20170531081554.GP24023@tucnak> Reply-To: Jakub Jelinek References: <20170222214046.GA1849@tucnak> <99048e22-aedc-df95-f1fe-dc1eaffd58b1@gjlay.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <99048e22-aedc-df95-f1fe-dc1eaffd58b1@gjlay.de> User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes X-SW-Source: 2017-05/txt/msg02318.txt.bz2 On Wed, May 31, 2017 at 10:06:34AM +0200, Georg-Johann Lay wrote: > Hi, this causes a performance degradation for avr. > > When optimizing for speed, and with a known denominatior, then v6 uses > s/umulMM3_highpart insn to avoid division because no div instruction is > available. > > unsigned scale256 (unsigned val) > { > return value / 255; > } > > With this patch, v7 now uses __divmodhi4 which is very expensive but > the costs are not computed because rtlanal.c:seq_cost assumes a cost of > ONE: > > for (; seq; seq = NEXT_INSN (seq)) > { > set = single_set (seq); > if (set) > cost += set_rtx_cost (set, speed); > else > cost++; > } > > because divmod in not a single_set: > (gdb) p seq > $10 = (const rtx_insn *) 0x7ffff730d500 > (gdb) pr > warning: Expression is not an assignment (and might have no effect) > (insn 14 13 0 (parallel [ > (set (reg:HI 52) > (div:HI (reg:HI 47) > (reg:HI 54))) > (set (reg:HI 53) > (mod:HI (reg:HI 47) > (reg:HI 54))) > (clobber (reg:QI 21 r21)) > (clobber (reg:HI 22 r22)) > (clobber (reg:HI 24 r24)) > (clobber (reg:HI 26 r26)) > ]) "scale.c":7 -1 > (nil)) > (gdb) > > Hence the divmod appears to be much less expensive than the unsigned > variant that computed the costs for mult_highpart. Then you should fix the cost computation - be able to use a target hook on insns that are not a single set or something similar. Jakub