From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe2c.google.com (mail-vs1-xe2c.google.com [IPv6:2607:f8b0:4864:20::e2c]) by sourceware.org (Postfix) with ESMTPS id 3CB473858D37 for ; Mon, 23 Oct 2023 09:49:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3CB473858D37 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 3CB473858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::e2c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698054597; cv=none; b=ZNFqCeeguff4pm3ANK4im7mAfUGo6YXYSwOdTcHgtXrPHnz2C2M1Y3cnxEMzoIpKN3NxtBH0kM/P+SsC5HNn9bfl5hLo7d2rzHFfAN/3zktqstffB1Ig0P31Ty4SxpokCnAPimcD15QGkS6pTdW9zLdWybl+WVnkQ/SrxR2ahUQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698054597; c=relaxed/simple; bh=/bLBYyuXYdnFYfkKH0ZqT8l9QqzYcKcMR9WYJup2rcU=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=MPS7YeR1W+qMxFfQgrqOG6uACksyq8AnPYYH4oZnChRxqzn5qBIo7cH6LnBjT4cvkIIjhKUAkfWfi5xSg5jzK+gP3V70kmkm1ykvPiZeM2wWA0rE9iuNmEB6ieGS98bRJ5ihXlDWqGBwzRNzkSp2xfC1+ZaW2+/2c7IOXV46sdk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-vs1-xe2c.google.com with SMTP id ada2fe7eead31-457bac7c3f5so1262323137.2 for ; Mon, 23 Oct 2023 02:49:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698054594; x=1698659394; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ixL7g+4auHkhvP8xJI5hvgJcuOL6a/5RiEvDArdGlho=; b=WcBZa4jRTdAjphCOcEiAT21xMMui38C04XlFQ4dtg88KC6C4ZOu9uVO95uwEyyIznq EUd/gwTD2sl4wferJ9aDkoxuz4TBW4pYE7/5tU7iiZR6+owmnU4pteykPhbayw7GQWH3 4MEx0uU+vqDQrFpSvT/XM/vsg7s0jcv8NiMvDFCJ4J8UKDjobTRME/Ep1RmUNq8Z8sSE 3AMkjTwzLxaYtec94nh/bru7N4u3PfvjypfcpP4vPBxUXqW/FYMHH4+XUFgB7cwSU2Tb 96nPKodUmS3PwgG1tyUZji91o59kb1l9mKO1cr2wPUIuQ+jGnAShcUc1sg2LfK1v1veW DnYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698054594; x=1698659394; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ixL7g+4auHkhvP8xJI5hvgJcuOL6a/5RiEvDArdGlho=; b=mmXGRMQZXbSbsp4Ow6HkLaZqVaKpuk/4fRK5GzhmCk+iFVpz/HyB3ecekyDXbZFu3c Kpy5xMXOt1k6sD/4ZBqhFdO1dGwnf0buIytXnQeoYqwwhqMRfJVXdCYEI0u0ubeU1vw3 OCc0NQWRiqgjeA1GDz/2qHr+9aSW+IsMc36aVVslSMw/S3khYJ82lH245X4zPM9V7FHm r87cfkz7Splxs7TnudrbGd53EAjUrmcpIPfEcR5j6UgCJkjdZticJkRq3drFWjjGtnkL fniJvegH6jS0nx9bllZMldMQKDRljcCf+X5BuGoia561ZLXm1IFfKY3qgdtNUqkiKSIi XQRw== X-Gm-Message-State: AOJu0YwT3tSpnk1B84C1+dhDkaFgYwNupuU15Qi/FZ1i1b0au2Qn+o7K +/0DVKKNIv5KLLMuDEaZoSBIUK+2ER0qUq3X4QY4N50c X-Google-Smtp-Source: AGHT+IHea3ML59oSMNn9IQ0K4NrC1Vec+UzeF7QMCHVhqOFM1zBfRORR5fqU4lkhJbdK1snieJbKCDW8xVlKC25G/aQ= X-Received: by 2002:a67:e112:0:b0:457:6858:af77 with SMTP id d18-20020a67e112000000b004576858af77mr7145895vsl.26.1698054593772; Mon, 23 Oct 2023 02:49:53 -0700 (PDT) MIME-Version: 1.0 References: <20231023094034.1728130-1-juzhe.zhong@rivai.ai> In-Reply-To: <20231023094034.1728130-1-juzhe.zhong@rivai.ai> From: Kito Cheng Date: Mon, 23 Oct 2023 17:49:42 +0800 Message-ID: Subject: Re: [PATCH V2] RISC-V: Fix ICE for the fusion case from vsetvl to scalar move[PR111927] To: Juzhe-Zhong Cc: GCC Patches , Kito Cheng , Jeff Law , Robin Dapp Content-Type: multipart/alternative; boundary="000000000000df076506085f24cd" X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,WEIRD_PORT 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: --000000000000df076506085f24cd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable LGTM Juzhe-Zhong =E6=96=BC 2023=E5=B9=B410=E6=9C=8823=E6= =97=A5 =E9=80=B1=E4=B8=80 17:41 =E5=AF=AB=E9=81=93=EF=BC=9A > ICE: > > during RTL pass: vsetvl > : In function 'riscv_lms_f32': > :240:1: internal compiler error: in merge, at > config/riscv/riscv-vsetvl.cc:1997 > 240 | } > > In general compatible_p (avl_equal_p) has: > > if (next.has_vl () && next.vl_used_by_non_rvv_insn_p ()) > return false; > > Don't fuse AVL of vsetvl if the VL operand is used by non-RVV instruction= s. > > It is reasonable to add it into 'can_use_next_avl_p' since we don't want = to > fuse AVL of vsetvl into a scalar move instruction which doesn't demand AV= L. > And after the fusion, we will alway use compatible_p to check whether the > demand > is correct or not. > > PR target/111927 > > gcc/ChangeLog: > > * config/riscv/riscv-vsetvl.cc: Fix bug. > > gcc/testsuite/ChangeLog: > > * gcc.target/riscv/rvv/vsetvl/pr111927.c: New test. > > --- > gcc/config/riscv/riscv-vsetvl.cc | 23 +++ > .../gcc.target/riscv/rvv/vsetvl/pr111927.c | 170 ++++++++++++++++++ > 2 files changed, 193 insertions(+) > create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr111927.c > > diff --git a/gcc/config/riscv/riscv-vsetvl.cc > b/gcc/config/riscv/riscv-vsetvl.cc > index 47b459fddd4..f3922a051c5 100644 > --- a/gcc/config/riscv/riscv-vsetvl.cc > +++ b/gcc/config/riscv/riscv-vsetvl.cc > @@ -1541,6 +1541,29 @@ private: > inline bool can_use_next_avl_p (const vsetvl_info &prev, > const vsetvl_info &next) > { > + /* Forbid the AVL/VL propagation if VL of NEXT is used > + by non-RVV instructions. This is because: > + > + bb 2: > + PREV: scalar move (no AVL) > + bb 3: > + NEXT: vsetvl a5(VL), a4(AVL) ... > + branch a5,zero > + > + Since user vsetvl instruction is no side effect instruction > + which should be placed in the correct and optimal location > + of the program by the previous PASS, it is unreasonable that > + VSETVL PASS tries to move it to another places if it used by > + non-RVV instructions. > + > + Note: We only forbid the cases that VL is used by the following > + non-RVV instructions which will cause issues. We don't forbid > + other cases since it won't cause correctness issues and we still > + more demand info are fused backward. The later LCM algorithm > + should know the optimal location of the vsetvl. */ > + if (next.has_vl () && next.vl_used_by_non_rvv_insn_p ()) > + return false; > + > if (!next.has_nonvlmax_reg_avl () && !next.has_vl ()) > return true; > > diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr111927.c > b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr111927.c > new file mode 100644 > index 00000000000..ab599add57f > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr111927.c > @@ -0,0 +1,170 @@ > +/* { dg-do compile } */ > +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64d -O3" } */ > + > +#include "riscv_vector.h" > + > +#define RISCV_MATH_LOOPUNROLL > +#define RISCV_MATH_VECTOR > +typedef float float32_t; > + > + typedef struct > + { > + uint16_t numTaps; /**< number of coefficients in the filter. > */ > + float32_t *pState; /**< points to the state variable array. > The array is of length numTaps+blockSize-1. */ > + float32_t *pCoeffs; /**< points to the coefficient array. The > array is of length numTaps. */ > + float32_t mu; /**< step size that controls filter > coefficient updates. */ > + } riscv_lms_instance_f32; > + > + > +void riscv_lms_f32( > + const riscv_lms_instance_f32 * S, > + const float32_t * pSrc, > + float32_t * pRef, > + float32_t * pOut, > + float32_t * pErr, > + uint32_t blockSize) > +{ > + float32_t *pState =3D S->pState; /* State pointe= r */ > + float32_t *pCoeffs =3D S->pCoeffs; /* Coefficient > pointer */ > + float32_t *pStateCurnt; /* Points to the > current sample of the state */ > + float32_t *px, *pb; /* Temporary > pointers for state and coefficient buffers */ > + float32_t mu =3D S->mu; /* Adaptive fac= tor > */ > + float32_t acc, e; /* Accumulator, > error */ > + float32_t w; /* Weight factor = */ > + uint32_t numTaps =3D S->numTaps; /* Number of > filter coefficients in the filter */ > + uint32_t tapCnt, blkCnt; /* Loop counters = */ > + > + /* Initializations of error, difference, Coefficient update */ > + e =3D 0.0f; > + w =3D 0.0f; > + > + /* S->pState points to state array which contains previous frame > (numTaps - 1) samples */ > + /* pStateCurnt points to the location where the new input data should > be written */ > + pStateCurnt =3D &(S->pState[(numTaps - 1U)]); > + > + /* initialise loop count */ > + blkCnt =3D blockSize; > + > + while (blkCnt > 0U) > + { > + /* Copy the new input sample into the state buffer */ > + *pStateCurnt++ =3D *pSrc++; > + > + /* Initialize pState pointer */ > + px =3D pState; > + > + /* Initialize coefficient pointer */ > + pb =3D pCoeffs; > + > + /* Set the accumulator to zero */ > + acc =3D 0.0f; > + uint32_t vblkCnt =3D numTaps; /* Loop > counter */ > + size_t l; > + vfloat32m8_t vx, vy; > + vfloat32m1_t temp00m1; > + l =3D __riscv_vsetvl_e32m1(1); > + temp00m1 =3D __riscv_vfmv_v_f_f32m1(0, l); > + for (; (l =3D __riscv_vsetvl_e32m8(vblkCnt)) > 0; vblkCnt -=3D l) { > + vx =3D __riscv_vle32_v_f32m8(px, l); > + px +=3D l; > + vy =3D __riscv_vle32_v_f32m8(pb, l); > + pb +=3D l; > + temp00m1 =3D > __riscv_vfredusum_vs_f32m8_f32m1(__riscv_vfmul_vv_f32m8(vx, vy, l), > temp00m1, l); > + } > + acc +=3D __riscv_vfmv_f_s_f32m1_f32(temp00m1); > + > + while (tapCnt > 0U) > + { > + /* Perform the multiply-accumulate */ > + acc +=3D (*px++) * (*pb++); > + > + /* Decrement the loop counter */ > + tapCnt--; > + } > + /* Store the result from accumulator into the destination buffer. */ > + *pOut++ =3D acc; > + > + /* Compute and store error */ > + e =3D (float32_t) *pRef++ - acc; > + *pErr++ =3D e; > + > + /* Calculation of Weighting factor for updating filter coefficients = */ > + w =3D e * mu; > + > + /* Initialize pState pointer */ > + /* Advance state pointer by 1 for the next sample */ > + px =3D pState++; > + > + /* Initialize coefficient pointer */ > + pb =3D pCoeffs; > + > + vblkCnt =3D numTaps; > + for (; (l =3D __riscv_vsetvl_e32m8(vblkCnt)) > 0; vblkCnt -=3D l) { > + vx =3D __riscv_vle32_v_f32m8(px, l); > + px +=3D l; > + __riscv_vse32_v_f32m8(pb, > __riscv_vfadd_vv_f32m8(__riscv_vfmul_vf_f32m8(vx, w, l), > __riscv_vle32_v_f32m8(pb, l), l) , l); > + pb +=3D l; > + } > + while (tapCnt > 0U) > + { > + /* Perform the multiply-accumulate */ > + *pb +=3D w * (*px++); > + pb++; > + > + /* Decrement loop counter */ > + tapCnt--; > + } > + /* Decrement loop counter */ > + blkCnt--; > + } > + > + /* Processing is complete. > + Now copy the last numTaps - 1 samples to the start of the state > buffer. > + This prepares the state buffer for the next function call. */ > + > + /* Points to the start of the pState buffer */ > + pStateCurnt =3D S->pState; > + > + /* copy data */ > + > + uint32_t vblkCnt =3D (numTaps - 1U); /* > Loop counter */ > + size_t l; > + for (; (l =3D __riscv_vsetvl_e32m8(vblkCnt)) > 0; vblkCnt -=3D l) { > + __riscv_vse32_v_f32m8(pStateCurnt, __riscv_vle32_v_f32m8(pState, l) > , l); > + pState +=3D l; > + pStateCurnt +=3D l; > + } > + > + > + /* Loop unrolling: Compute 4 taps at a time. */ > + tapCnt =3D (numTaps - 1U) >> 2U; > + > + while (tapCnt > 0U) > + { > + *pStateCurnt++ =3D *pState++; > + *pStateCurnt++ =3D *pState++; > + *pStateCurnt++ =3D *pState++; > + *pStateCurnt++ =3D *pState++; > + > + /* Decrement loop counter */ > + tapCnt--; > + } > + > + /* Loop unrolling: Compute remaining taps */ > + tapCnt =3D (numTaps - 1U) & 0x3U; > + > + > + > + /* Initialize tapCnt with number of samples */ > + tapCnt =3D (numTaps - 1U); > + > + > + > + while (tapCnt > 0U) > + { > + *pStateCurnt++ =3D *pState++; > + > + /* Decrement loop counter */ > + tapCnt--; > + } > +} > -- > 2.36.3 > > --000000000000df076506085f24cd--