From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by sourceware.org (Postfix) with ESMTPS id 9C71A3858C2D for ; Fri, 22 Dec 2023 17:00:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9C71A3858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9C71A3858C2D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703264433; cv=none; b=fHolerYCGhQDEsOBLHm/6NF916uqsYUf4KLYDx6LaBgY72uSxS/YIXZBCdCMUNLvsV4JaCcbuTXC5+s/hvr02531a7HXu6fJYHQRmVwTF+tvC4wAF215WjDLagtJz24wHFs7yepOaDjp8kH0+BYs57JRT6S7Yk8R4/KNa9JfPWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703264433; c=relaxed/simple; bh=3rUtrBy+fQnhlYWCd5gxGfJfJs3gCIDWb22f0moDBoA=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=TcZCYUF92/W/8AfTthAu3XOp5KCBaYHKDDQc7Y98yg4VgKrfeIpMe8h70Yrv9Tppc3417zK/MyywZArV6D18srtvzFpVWsQVsDNXxnwmVOqjHpMwjTLi1W8AvGrUwxVFhVwAo4/EDpeitGE54qncWI8xxBZ+tUbBXjEKKuE5ifw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x131.google.com with SMTP id e9e14a558f8ab-35f519f3ea9so10433165ab.3 for ; Fri, 22 Dec 2023 09:00:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703264431; x=1703869231; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=O5fYA6u2t6tXrmzY1cCl40KWWZnbo7zn2XPFGN2u/7A=; b=WPaT6k0jvWwV8zYyAN5cDt6UXdD045Qtc7sTBigjwqreaUkC7wk/FUuykXWFC6ZgZ4 HtWICYt2+CA9DTG+w6yvcXPSwZQcBLjgyf0Z8mfvXs+Qf0RSxoAQLQz2dMbSw1+7fSd2 7UzFZ174PavoR8bdy1chjmdoCGEW1lCJyjQPG5Cbn7VD/t3YdDSEVgEfxBBSpAlgCbIZ 5TxLTnkMecbI7wtulM4SezTZ8H3HgC889tYspiNr4DuHIF01doysjRi1LRLcIIPihvuT WKq2uy0Atit/PX/ShNDzrdmVuX6P8s6gopkLRKC66rLtMSOtLnxp7UN1/CaOBYrdQZ7t b1RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703264431; x=1703869231; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=O5fYA6u2t6tXrmzY1cCl40KWWZnbo7zn2XPFGN2u/7A=; b=F7zPgCjZLyA8PYbcHue/bfU7YEpSRwVsHsDnMUezvSkp4OY8Mh+JBBvED+0JRLMshi TL4QBuWcN2LH1hdN8FkeVj0XPP2nflw8z0gXxpWVEeJMTh9NSO/sh8Xxecug1aTLR0dN EQGt1eWSVS9atLn6ITW9Nx5b1KN8/Mj/HEhcLPzCzUC7woAhSI0qe8/1dM9jWrQzo8aC PHIVcaq7D+qLgfT8jN8x4A+1P2L43XLOeqPTcJhdWZM8XO30Ji5gsT/oZzx9SoGMMlBM SvLE4Uhz4+pFoah0WDyFVCobBG+bhyq2ZDOcHXAUYnsFkDJjEAWqsHSk1NuEPoDibsTO Sykg== X-Gm-Message-State: AOJu0YxJNfdI7xZe9GuWQlrRZPpqMiSv+krtbPR/waQjSUEVqziyB/Rl 8/KWhbsvO8btc/wFJi62E6A= X-Google-Smtp-Source: AGHT+IE1PBZcJj+3gdQppJP4R+//yQ5CytOZcWREgG2JCgY2H9BDzUqqlwN3HZD1rbM8R7ZvGvGtFA== X-Received: by 2002:a05:6e02:1605:b0:35f:9920:1111 with SMTP id t5-20020a056e02160500b0035f99201111mr1668866ilu.129.1703264430554; Fri, 22 Dec 2023 09:00:30 -0800 (PST) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id b18-20020a92db12000000b0035f79e0a932sm1210162iln.41.2023.12.22.08.59.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Dec 2023 08:59:34 -0800 (PST) Message-ID: <6463dca3-3af6-4226-aa6a-46e56b05b338@gmail.com> Date: Fri, 22 Dec 2023 09:58:55 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] RISC-V: Make PHI initial value occupy live V_REG in dynamic LMUL cost model analysis Content-Language: en-US To: Juzhe-Zhong , gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, kito.cheng@sifive.com, rdapp.gcc@gmail.com References: <20231222095156.304068-1-juzhe.zhong@rivai.ai> From: Jeff Law In-Reply-To: <20231222095156.304068-1-juzhe.zhong@rivai.ai> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SCC_5_SHORT_WORD_LINES,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 12/22/23 02:51, Juzhe-Zhong wrote: > Consider this following case: > > foo: > ble a0,zero,.L11 > lui a2,%hi(.LANCHOR0) > addi sp,sp,-128 > addi a2,a2,%lo(.LANCHOR0) > mv a1,a0 > vsetvli a6,zero,e32,m8,ta,ma > vid.v v8 > vs8r.v v8,0(sp) ---> spill > .L3: > vl8re32.v v16,0(sp) ---> reload > vsetvli a4,a1,e8,m2,ta,ma > li a3,0 > vsetvli a5,zero,e32,m8,ta,ma > vmv8r.v v0,v16 > vmv.v.x v8,a4 > vmv.v.i v24,0 > vadd.vv v8,v16,v8 > vmv8r.v v16,v24 > vs8r.v v8,0(sp) ---> spill > .L4: > addiw a3,a3,1 > vadd.vv v8,v0,v16 > vadd.vi v16,v16,1 > vadd.vv v24,v24,v8 > bne a0,a3,.L4 > vsetvli zero,a4,e32,m8,ta,ma > sub a1,a1,a4 > vse32.v v24,0(a2) > slli a4,a4,2 > add a2,a2,a4 > bne a1,zero,.L3 > li a0,0 > addi sp,sp,128 > jr ra > .L11: > li a0,0 > ret > > Pick unexpected LMUL = 8. > > The root cause is we didn't involve PHI initial value in the dynamic LMUL calculation: > > # j_17 = PHI ---> # vect_vec_iv_.8_24 = PHI <_25(9), { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }(5)> > > We didn't count { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } in consuming vector register but it does allocate an vector register group for it. Yup. There's analogues in the scalar space. Depending on the context we might consider the value live on the edge, at the end of e->src or at the start of e->dest. In the scalar space we commonly have multiple constant values and we try to account for them as best as we can as each distinct constant can result in a constant load. We also try to find pseudos that happen to already have the value we want so that they participate in the coalescing process. I doubt either of these cases are particularly important for vector though. > > This patch fixes this missing count. Then after this patch we pick up perfect LMUL (LMUL = M4) > > foo: > ble a0,zero,.L9 > lui a4,%hi(.LANCHOR0) > addi a4,a4,%lo(.LANCHOR0) > mv a2,a0 > vsetivli zero,16,e32,m4,ta,ma > vid.v v20 > .L3: > vsetvli a3,a2,e8,m1,ta,ma > li a5,0 > vsetivli zero,16,e32,m4,ta,ma > vmv4r.v v16,v20 > vmv.v.i v12,0 > vmv.v.x v4,a3 > vmv4r.v v8,v12 > vadd.vv v20,v20,v4 > .L4: > addiw a5,a5,1 > vmv4r.v v4,v8 > vadd.vi v8,v8,1 > vadd.vv v4,v16,v4 > vadd.vv v12,v12,v4 > bne a0,a5,.L4 > slli a5,a3,2 > vsetvli zero,a3,e32,m4,ta,ma > sub a2,a2,a3 > vse32.v v12,0(a4) > add a4,a4,a5 > bne a2,zero,.L3 > .L9: > li a0,0 > ret > > Tested on --with-arch=gcv no regression. Ok for trunk ? > > PR target/113112 > > gcc/ChangeLog: > > * config/riscv/riscv-vector-costs.cc (max_number_of_live_regs): Refine dump information. > (preferred_new_lmul_p): Make PHI initial value into live regs calculation. > > gcc/testsuite/ChangeLog: > > * gcc.dg/vect/costmodel/riscv/rvv/pr113112-1.c: New test. OK assuming you've done the necessary regression testing. jeff