From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by sourceware.org (Postfix) with ESMTPS id AE2093858CDB for ; Mon, 5 Feb 2024 03:26:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE2093858CDB 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 AE2093858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d30 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707103616; cv=none; b=IzV7+Jvves+rIdLYYSp23dwzGF/EEuwbfGCSvo3cwy/FHpHoXb2RFznhzEGJWCJaUR5m0aaqfKfqGOK6MzI+vTfYHIw+yJBvqyaJntgC1cnAUKBT6cM7iErJFffAG6ttLMgkDgLLKlyUYr/3Svy93eBG+qbQtbdnNP6CgRhVPQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707103616; c=relaxed/simple; bh=8VeLsrBUwqBWh6iNhsg0oW0WYBOL74Jzz6tbh8hLemU=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=fL4lOiqnpJhcEC4ohrJsbBFIMKV4smJnvyGBz71MY0B9SanQkUxCWeqHV+sPutYoS8Gb8yTyhdWBWJSUfn7Z3/iF70sYdQeeCJxfx/qQI0xU4TyMstx8o95Y2tLsk9sBxJwY2ZjDemaB82h3LZ8Ln3GR7l3wVOcBai0/hVusZWA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-7baa8097064so250600039f.3 for ; Sun, 04 Feb 2024 19:26:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707103614; x=1707708414; 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=sxtj84DeW2dCaIIJTT8gGiwiRm48aHk6reHCQAw2Sgs=; b=e/XKSrb+BqLbcs1ncE8CYMt6/bRp1MarHz54e6s8soy2kodBHpSosTwBLbtgVXMY4T sYl+eb0CTv85ls/0n6lHSs1KFbfWw8wMY7BXl0DrTVjWRSTCoeN0CbtLDSIzdB4l5LFu q6b6bEf9mXG/qvgTLjJOM45pAXCF8+IgHQUqIbWcjATsWqA5tnbEfANpOfmmpiLGPJn2 DSXawh+V8DJCTj0WX9hRg/FZP1cahExTV8VX8tN3C3xd+wuDo8+bddRVlt8ZSZD+Jf1o dqu3kZfA06huyjACPbauAaD4vX1dRZLIR2s6MPiz6xEjn8SRduKfo0Hb1Go1G0s/S9Pw l7DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707103614; x=1707708414; 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=sxtj84DeW2dCaIIJTT8gGiwiRm48aHk6reHCQAw2Sgs=; b=o0FzUqF+L2idszQqkay9fHwBgJ4Tr+nViiKYIoJPM6LqNEhuB+qfsKSveMl9tizse7 n810VdRRpfmg0WGh/ePaj29iLgqRNKdGyKnyBE19KoKiFjf9hZB8MT++7dkYvZdKZEXl g1p0drw+8cVm0yLoCd0z+zs0rIXQ26gK29gChOnwFmStru0y9qrGVcS0Rq62OLEy0OCn uOh1yeJ6HmrFsWeIouZK2y/jfriDGfNZ9zgPoFvhkmTw/4q8kRy9NN0kbqX5YRJAP3V0 +juTEWoBjRfirdeF3lvMW8SNd8LrPVkh2YLK7hguWOKc5acMASkdFWXaagPxJiq6ax1k jIXQ== X-Gm-Message-State: AOJu0Yxn6GQMu7qM9ljJf3uXE8gBTLDFOCP9TLIj95B9y+zBMPBZ/mon jNEKwe+nMLVU7uiYwp1Dx3a2QWvluZQnxqJxORQUoNUFal9rsfTL X-Google-Smtp-Source: AGHT+IHMDBz5P8e/B5zZzM9RaeQJRnYOSQulLbNimwh1Nq+GCZPwjPkopDkGXRk1rP+ygndY9BaTUA== X-Received: by 2002:a92:cb48:0:b0:363:c4b9:d931 with SMTP id f8-20020a92cb48000000b00363c4b9d931mr2981806ilq.20.1707103613780; Sun, 04 Feb 2024 19:26:53 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCX+eI2QC5AiAN/YCjGUC7iJ3ier0uUA04WLV/wyyO4ZBRzvRqumcYwUUvy1i1fgH0vNiI60L3ZWAPop/TXp1n1M2OKPaqewmQ6BYpoEubANb9n68AIlTeXCSKDQ4iE7Ic+MdsTuT6g8fPXhW+Xp9YR8bBQ9 Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id p1-20020a0566380e8100b00470ef7f3ec1sm1836477jas.1.2024.02.04.19.26.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 04 Feb 2024 19:26:53 -0800 (PST) Message-ID: <8d5529d6-df50-4ac2-9bdb-a7525142b956@gmail.com> Date: Sun, 4 Feb 2024 20:26:52 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] RISC-V: Expand VLMAX scalar move in reduction 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: <20240202015659.54072-1-juzhe.zhong@rivai.ai> From: Jeff Law In-Reply-To: <20240202015659.54072-1-juzhe.zhong@rivai.ai> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham 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 2/1/24 18:56, Juzhe-Zhong wrote: > This patch fixes the following: > > vsetvli a5,a1,e32,m1,tu,ma > slli a4,a5,2 > sub a1,a1,a5 > vle32.v v2,0(a0) > add a0,a0,a4 > vadd.vv v1,v2,v1 > bne a1,zero,.L3 > vsetivli zero,1,e32,m1,ta,ma > vmv.s.x v2,zero > vsetvli a5,zero,e32,m1,ta,ma ---> Redundant vsetvl. > vredsum.vs v1,v1,v2 > vmv.x.s a0,v1 > ret > > VSETVL PASS is able to fuse avl = 1 of scalar move and VLMAX avl of reduction. > > However, this following RTL blocks the fusion in dependence analysis in VSETVL PASS: > > (insn 49 24 50 5 (set (reg:RVVM1SI 98 v2 [148]) > (if_then_else:RVVM1SI (unspec:RVVMF32BI [ > (const_vector:RVVMF32BI [ > (const_int 1 [0x1]) > repeat [ > (const_int 0 [0]) > ] > ]) > (const_int 1 [0x1]) > (const_int 2 [0x2]) repeated x2 > (const_int 0 [0]) > (reg:SI 66 vl) > (reg:SI 67 vtype) > ] UNSPEC_VPREDICATE) > (const_vector:RVVM1SI repeat [ > (const_int 0 [0]) > ]) > (unspec:RVVM1SI [ > (reg:DI 0 zero) > ] UNSPEC_VUNDEF))) 3813 {*pred_broadcastrvvm1si_zero} > (nil)) > (insn 50 49 51 5 (set (reg:DI 15 a5 [151]) ----> It set a5, blocks the following VLMAX into the scalar move above. > (unspec:DI [ > (const_int 32 [0x20]) > ] UNSPEC_VLMAX)) 2566 {vlmax_avldi} > (expr_list:REG_EQUIV (unspec:DI [ > (const_int 32 [0x20]) > ] UNSPEC_VLMAX) > (nil))) > (insn 51 50 52 5 (set (reg:RVVM1SI 97 v1 [150]) > (unspec:RVVM1SI [ > (unspec:RVVMF32BI [ > (const_vector:RVVMF32BI repeat [ > (const_int 1 [0x1]) > ]) > (reg:DI 15 a5 [151]) > (const_int 2 [0x2]) > (const_int 1 [0x1]) > (reg:SI 66 vl) > (reg:SI 67 vtype) > ] UNSPEC_VPREDICATE) > (unspec:RVVM1SI [ > (reg:RVVM1SI 97 v1 [orig:134 vect_result_14.6 ] [134]) > (reg:RVVM1SI 98 v2 [148]) > ] UNSPEC_REDUC_SUM) > (unspec:RVVM1SI [ > (reg:DI 0 zero) > ] UNSPEC_VUNDEF) > ] UNSPEC_REDUC)) 17541 {pred_redsumrvvm1si} > (expr_list:REG_DEAD (reg:RVVM1SI 98 v2 [148]) > (expr_list:REG_DEAD (reg:SI 66 vl) > (expr_list:REG_DEAD (reg:DI 15 a5 [151]) > (expr_list:REG_DEAD (reg:DI 0 zero) > (nil)))))) > > Such situation can only happen on auto-vectorization, never happen on intrinsic codes. > Since the reduction is passed VLMAX AVL, it should be more natural to pass VLMAX to the scalar move which initial the value of the reduction. > > After this patch: > > vsetvli a5,a1,e32,m1,tu,ma > slli a4,a5,2 > sub a1,a1,a5 > vle32.v v2,0(a0) > add a0,a0,a4 > vadd.vv v1,v2,v1 > bne a1,zero,.L3 > vsetvli a5,zero,e32,m1,ta,ma > vmv.s.x v2,zero > vredsum.vs v1,v1,v2 > vmv.x.s a0,v1 > ret > > Tested on both RV32/RV64 no regression. > > PR target/113697 > > gcc/ChangeLog: > > * config/riscv/riscv-v.cc (expand_reduction): Pass VLMAX avl to scalar move. > > gcc/testsuite/ChangeLog: > > * gcc.target/riscv/rvv/autovec/pr113697.c: New test. I suspect this broke 502.gcc in spec2017. Basically it's hanging during the build phase. I'm not sure if I'm going to have time this week to dive into it. Optimization options used: > GCC Flags: -Ofast -flto -fsched-pressure -fno-strict-aliasing -fgnu89-inline -fcommon -fno-finite-math-only -fno-unsafe-math-optimizations Given this appears to be a minor optimization issue, I wouldn't lose any sleep if it was reverted and deferred to gcc-15. Anyway, good luck. Sorry I can't do more on the debugging/reduction front. Jeff