Message ID | 3356a2e0-b402-de07-9374-6e5b5c59a2f2@rivosinc.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 99802385842B for <patchwork@sourceware.org>; Tue, 21 Feb 2023 23:02:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by sourceware.org (Postfix) with ESMTPS id 181ED3858C39 for <gcc-patches@gcc.gnu.org>; Tue, 21 Feb 2023 23:02:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 181ED3858C39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-qt1-x830.google.com with SMTP id h16so5935235qta.8 for <gcc-patches@gcc.gnu.org>; Tue, 21 Feb 2023 15:02:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=rCHgx1CtZWWJq1Qoy4KqEp5rUnMOWRznmFUrxiNZlKI=; b=eUsCCIpYjI0vcs6lFBXZIuxloR+m+C/8hwd0nTcyUS+HmQ+lbMdrxe8bn1l5eDPDIu c1vG/cdL6sH9s4Kmi0IbFQjs0qNXO5NQbWNnk5kRI8CkdJpUSeAvFHk916YylT1W/wCS Kk3EuvR62aGg+WdQJ5pe+xf11aexj2ZDZWUkFTkKg6KIRF1G+lgtg2MjIXOUoUVCCOvJ yyhM46nuozgf+n1adIqDksGqgu9i9RMcltzt3PsPmcNRmeef/biM0h6ng2d+htfkIgDq bDD05ayqUG7Fub5YssMQjwHl/75RoMgqV9jf2lOCnJuplvG+j+cZehcDYhG9mKbPe4X+ WRZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=rCHgx1CtZWWJq1Qoy4KqEp5rUnMOWRznmFUrxiNZlKI=; b=1/eglnxsLF50q1I3NAYDzVrLvPNVAfUWRSgiu1gnhS9Vbxfwe7XHsO+6Z0sDBaGv5a cVZWugz+OMXL+xftD/DhG1Z+yanIorQSGlZE5xp3S2zjIxhMto5y4Mntv22wiO/CQIA4 TO/atN9ZASJSNopTxyl9X4/mfMVH4eqeu2HvGGlsS5amcVndMkBv+L5xOOVIT9Th2Qk4 zn7ufRybm3Td11UCeEm42ofVcrDozNvkOvqROq+UqKdUBmDMFDOhw57cixtVoMRMoruO mCVGlkW3/2ZYAU67cRm/2c9x+2r+xSOivA4piz35elTfABRbUPnrDYppRxQYuohtBJll HKBA== X-Gm-Message-State: AO0yUKUzY2hsFXTcB274eEP55EfBgLVLA6N1f4wVedfZgeK32HoC2vfW 9AOye1d65YGYgDci8qI5UL6Ke+YXhLq1jnmUI4c= X-Google-Smtp-Source: AK7set8Xkrr3lQdHt77CyjHgKICYqvwc5R3SXa31PvkQaMSIMkJblVI7pwr8VPii5Y09LMc87C0oVA== X-Received: by 2002:a05:622a:18d:b0:3b6:3a12:2bf9 with SMTP id s13-20020a05622a018d00b003b63a122bf9mr23762170qtw.2.1677020554250; Tue, 21 Feb 2023 15:02:34 -0800 (PST) Received: from [192.168.86.117] ([136.57.172.92]) by smtp.gmail.com with ESMTPSA id i123-20020a378681000000b0074233b15a72sm430396qkd.116.2023.02.21.15.02.32 for <gcc-patches@gcc.gnu.org> (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Feb 2023 15:02:32 -0800 (PST) Message-ID: <3356a2e0-b402-de07-9374-6e5b5c59a2f2@rivosinc.com> Date: Tue, 21 Feb 2023 18:02:32 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Content-Language: en-US To: gcc-patches@gcc.gnu.org From: Michael Collison <collison@rivosinc.com> Subject: [PATCH] vect: Check that vector factor is a compile-time constant Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
vect: Check that vector factor is a compile-time constant
|
|
Commit Message
Michael Collison
Feb. 21, 2023, 11:02 p.m. UTC
While working on autovectorizing for the RISCV port I encountered an issue where vect_do_peeling assumes that the vectorization factor is a compile-time constant. The vectorization is not a compile-time constant on RISCV. Tested on RISCV and x86_64-linux-gnu. Okay? Michael gcc/ * tree-vect-loop-manip.cc (vect_do_peeling): Verify that vectorization factor is a compile-time constant. --- gcc/tree-vect-loop-manip.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) wi::to_wide (build_int_cst (type, vf)),
Comments
On Wed, Feb 22, 2023 at 12:03 AM Michael Collison <collison@rivosinc.com> wrote: > > While working on autovectorizing for the RISCV port I encountered an > issue where vect_do_peeling assumes that the vectorization factor is a > compile-time constant. The vectorization is not a compile-time constant > on RISCV. > > Tested on RISCV and x86_64-linux-gnu. Okay? I wonder how you arrive at prologue peeling with a non-constant VF? In any case it would probably be better to use constant_lower_bound (vf) here? Also it looks wrong to apply this limit in case we are using a fully masked main vector loop. But as said, the specific case of non-constant VF and prologue peeling probably wasn't supposed to happen, instead the prologue usually is applied via an offset to a fully masked loop? Richard? Thanks, Richard. > Michael > > gcc/ > > * tree-vect-loop-manip.cc (vect_do_peeling): Verify > that vectorization factor is a compile-time constant. > > --- > gcc/tree-vect-loop-manip.cc | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc > index 6aa3d2ed0bf..1ad1961c788 100644 > --- a/gcc/tree-vect-loop-manip.cc > +++ b/gcc/tree-vect-loop-manip.cc > @@ -2930,7 +2930,7 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree > niters, tree nitersm1, > niters = vect_build_loop_niters (loop_vinfo, &new_var_p); > /* It's guaranteed that vector loop bound before vectorization is at > least VF, so set range information for newly generated var. */ > - if (new_var_p) > + if (new_var_p && vf.is_constant ()) > { > value_range vr (type, > wi::to_wide (build_int_cst (type, vf)), > -- > 2.34.1 >
Richard how would I check for a full masked main vector loop? On 2/22/23 03:20, Richard Biener wrote: > On Wed, Feb 22, 2023 at 12:03 AM Michael Collison <collison@rivosinc.com> wrote: >> While working on autovectorizing for the RISCV port I encountered an >> issue where vect_do_peeling assumes that the vectorization factor is a >> compile-time constant. The vectorization is not a compile-time constant >> on RISCV. >> >> Tested on RISCV and x86_64-linux-gnu. Okay? > I wonder how you arrive at prologue peeling with a non-constant VF? > In any case it would probably be better to use constant_lower_bound (vf) > here? Also it looks wrong to apply this limit in case we are using > a fully masked main vector loop. But as said, the specific case of > non-constant VF and prologue peeling probably wasn't supposed to happen, > instead the prologue usually is applied via an offset to a fully masked loop? > > Richard? > > Thanks, > Richard. > >> Michael >> >> gcc/ >> >> * tree-vect-loop-manip.cc (vect_do_peeling): Verify >> that vectorization factor is a compile-time constant. >> >> --- >> gcc/tree-vect-loop-manip.cc | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc >> index 6aa3d2ed0bf..1ad1961c788 100644 >> --- a/gcc/tree-vect-loop-manip.cc >> +++ b/gcc/tree-vect-loop-manip.cc >> @@ -2930,7 +2930,7 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree >> niters, tree nitersm1, >> niters = vect_build_loop_niters (loop_vinfo, &new_var_p); >> /* It's guaranteed that vector loop bound before vectorization is at >> least VF, so set range information for newly generated var. */ >> - if (new_var_p) >> + if (new_var_p && vf.is_constant ()) >> { >> value_range vr (type, >> wi::to_wide (build_int_cst (type, vf)), >> -- >> 2.34.1 >>
On Wed, Feb 22, 2023 at 5:42 PM Michael Collison <collison@rivosinc.com> wrote: > > Richard how would I check for a full masked main vector loop? It's LOOP_VINFO_FULLY_MASKED_P I think. For the odd prologue peeling you see you might want to check why vect_use_loop_mask_for_alignment_p isn't true (possibly because exactly LOOP_VINFO_FULLY_MASKED_P is not true ...) > On 2/22/23 03:20, Richard Biener wrote: > > On Wed, Feb 22, 2023 at 12:03 AM Michael Collison <collison@rivosinc.com> wrote: > >> While working on autovectorizing for the RISCV port I encountered an > >> issue where vect_do_peeling assumes that the vectorization factor is a > >> compile-time constant. The vectorization is not a compile-time constant > >> on RISCV. > >> > >> Tested on RISCV and x86_64-linux-gnu. Okay? > > I wonder how you arrive at prologue peeling with a non-constant VF? > > In any case it would probably be better to use constant_lower_bound (vf) > > here? Also it looks wrong to apply this limit in case we are using > > a fully masked main vector loop. But as said, the specific case of > > non-constant VF and prologue peeling probably wasn't supposed to happen, > > instead the prologue usually is applied via an offset to a fully masked loop? > > > > Richard? > > > > Thanks, > > Richard. > > > >> Michael > >> > >> gcc/ > >> > >> * tree-vect-loop-manip.cc (vect_do_peeling): Verify > >> that vectorization factor is a compile-time constant. > >> > >> --- > >> gcc/tree-vect-loop-manip.cc | 2 +- > >> 1 file changed, 1 insertion(+), 1 deletion(-) > >> > >> diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc > >> index 6aa3d2ed0bf..1ad1961c788 100644 > >> --- a/gcc/tree-vect-loop-manip.cc > >> +++ b/gcc/tree-vect-loop-manip.cc > >> @@ -2930,7 +2930,7 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree > >> niters, tree nitersm1, > >> niters = vect_build_loop_niters (loop_vinfo, &new_var_p); > >> /* It's guaranteed that vector loop bound before vectorization is at > >> least VF, so set range information for newly generated var. */ > >> - if (new_var_p) > >> + if (new_var_p && vf.is_constant ()) > >> { > >> value_range vr (type, > >> wi::to_wide (build_int_cst (type, vf)), > >> -- > >> 2.34.1 > >>
FWIW, this patch looks good to me. I'd argue it's a regression fix of kinds, in that the current code was correct before variable VF and became incorrect after variable VF. It might be possible to trigger the problem on SVE too, with a sufficiently convoluted test case. (Haven't tried though.) Richard Biener <richard.guenther@gmail.com> writes: > On Wed, Feb 22, 2023 at 12:03 AM Michael Collison <collison@rivosinc.com> wrote: >> >> While working on autovectorizing for the RISCV port I encountered an >> issue where vect_do_peeling assumes that the vectorization factor is a >> compile-time constant. The vectorization is not a compile-time constant >> on RISCV. >> >> Tested on RISCV and x86_64-linux-gnu. Okay? > > I wonder how you arrive at prologue peeling with a non-constant VF? Not sure about the RVV case, but I think it makes sense in principle. E.g. if some ISA takes the LOAD_LEN rather than fully-predicated approach, it can't easily use the first iteration of the vector loop to do peeling for alignment. (At least, the IV steps would then no longer match VF for all iterations.) I guess it could use a *different* vector loop, but we don't support that yet. There are also some corner cases for which we still don't support predicated loops and instead fall back on an unpredicated VLA loop followed by a scalar epilogue. Peeling for alignment would then require a scalar prologue too. > In any case it would probably be better to use constant_lower_bound (vf) > here? Also it looks wrong to apply this limit in case we are using > a fully masked main vector loop. But as said, the specific case of > non-constant VF and prologue peeling probably wasn't supposed to happen, > instead the prologue usually is applied via an offset to a fully masked loop? Hmm, yeah, agree constant_lower_bound should work too. Thanks, Richard > Richard? > > Thanks, > Richard. > >> Michael >> >> gcc/ >> >> * tree-vect-loop-manip.cc (vect_do_peeling): Verify >> that vectorization factor is a compile-time constant. >> >> --- >> gcc/tree-vect-loop-manip.cc | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc >> index 6aa3d2ed0bf..1ad1961c788 100644 >> --- a/gcc/tree-vect-loop-manip.cc >> +++ b/gcc/tree-vect-loop-manip.cc >> @@ -2930,7 +2930,7 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree >> niters, tree nitersm1, >> niters = vect_build_loop_niters (loop_vinfo, &new_var_p); >> /* It's guaranteed that vector loop bound before vectorization is at >> least VF, so set range information for newly generated var. */ >> - if (new_var_p) >> + if (new_var_p && vf.is_constant ()) >> { >> value_range vr (type, >> wi::to_wide (build_int_cst (type, vf)), >> -- >> 2.34.1 >>
Okay there seems to be consensus on using constant_lower_bound (vf), but I don't understand how that is a replacement for "vf.is_constant ()"? In one case we are checking if "vf" is a constant, on the other we are asking for the lower bound. For the crash in question "constant_lower_bound (vf) " returns the integer value of two. On 2/27/23 09:51, Richard Sandiford wrote: > FWIW, this patch looks good to me. I'd argue it's a regression fix > of kinds, in that the current code was correct before variable VF and > became incorrect after variable VF. It might be possible to trigger > the problem on SVE too, with a sufficiently convoluted test case. > (Haven't tried though.) > > Richard Biener <richard.guenther@gmail.com> writes: >> On Wed, Feb 22, 2023 at 12:03 AM Michael Collison <collison@rivosinc.com> wrote: >>> While working on autovectorizing for the RISCV port I encountered an >>> issue where vect_do_peeling assumes that the vectorization factor is a >>> compile-time constant. The vectorization is not a compile-time constant >>> on RISCV. >>> >>> Tested on RISCV and x86_64-linux-gnu. Okay? >> I wonder how you arrive at prologue peeling with a non-constant VF? > Not sure about the RVV case, but I think it makes sense in principle. > E.g. if some ISA takes the LOAD_LEN rather than fully-predicated > approach, it can't easily use the first iteration of the vector loop > to do peeling for alignment. (At least, the IV steps would then > no longer match VF for all iterations.) I guess it could use a > *different* vector loop, but we don't support that yet. > > There are also some corner cases for which we still don't support > predicated loops and instead fall back on an unpredicated VLA loop > followed by a scalar epilogue. Peeling for alignment would then > require a scalar prologue too. > >> In any case it would probably be better to use constant_lower_bound (vf) >> here? Also it looks wrong to apply this limit in case we are using >> a fully masked main vector loop. But as said, the specific case of >> non-constant VF and prologue peeling probably wasn't supposed to happen, >> instead the prologue usually is applied via an offset to a fully masked loop? > Hmm, yeah, agree constant_lower_bound should work too. > > Thanks, > Richard > >> Richard? >> >> Thanks, >> Richard. >> >>> Michael >>> >>> gcc/ >>> >>> * tree-vect-loop-manip.cc (vect_do_peeling): Verify >>> that vectorization factor is a compile-time constant. >>> >>> --- >>> gcc/tree-vect-loop-manip.cc | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc >>> index 6aa3d2ed0bf..1ad1961c788 100644 >>> --- a/gcc/tree-vect-loop-manip.cc >>> +++ b/gcc/tree-vect-loop-manip.cc >>> @@ -2930,7 +2930,7 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree >>> niters, tree nitersm1, >>> niters = vect_build_loop_niters (loop_vinfo, &new_var_p); >>> /* It's guaranteed that vector loop bound before vectorization is at >>> least VF, so set range information for newly generated var. */ >>> - if (new_var_p) >>> + if (new_var_p && vf.is_constant ()) >>> { >>> value_range vr (type, >>> wi::to_wide (build_int_cst (type, vf)), >>> -- >>> 2.34.1 >>>
On Wed, Mar 1, 2023 at 10:00 PM Michael Collison <collison@rivosinc.com> wrote: > > Okay there seems to be consensus on using constant_lower_bound (vf), but > I don't understand how that is a replacement for "vf.is_constant ()"? In > one case we are checking if "vf" is a constant, on the other we are > asking for the lower bound. For the crash in question > "constant_lower_bound (vf) " returns the integer value of two. Use the result of constant_lower_bound (vf) in place of 'vf' when build_int_cst. That should be correct for both poly and non-poly int VF. > On 2/27/23 09:51, Richard Sandiford wrote: > > FWIW, this patch looks good to me. I'd argue it's a regression fix > > of kinds, in that the current code was correct before variable VF and > > became incorrect after variable VF. It might be possible to trigger > > the problem on SVE too, with a sufficiently convoluted test case. > > (Haven't tried though.) > > > > Richard Biener <richard.guenther@gmail.com> writes: > >> On Wed, Feb 22, 2023 at 12:03 AM Michael Collison <collison@rivosinc.com> wrote: > >>> While working on autovectorizing for the RISCV port I encountered an > >>> issue where vect_do_peeling assumes that the vectorization factor is a > >>> compile-time constant. The vectorization is not a compile-time constant > >>> on RISCV. > >>> > >>> Tested on RISCV and x86_64-linux-gnu. Okay? > >> I wonder how you arrive at prologue peeling with a non-constant VF? > > Not sure about the RVV case, but I think it makes sense in principle. > > E.g. if some ISA takes the LOAD_LEN rather than fully-predicated > > approach, it can't easily use the first iteration of the vector loop > > to do peeling for alignment. (At least, the IV steps would then > > no longer match VF for all iterations.) I guess it could use a > > *different* vector loop, but we don't support that yet. > > > > There are also some corner cases for which we still don't support > > predicated loops and instead fall back on an unpredicated VLA loop > > followed by a scalar epilogue. Peeling for alignment would then > > require a scalar prologue too. > > > >> In any case it would probably be better to use constant_lower_bound (vf) > >> here? Also it looks wrong to apply this limit in case we are using > >> a fully masked main vector loop. But as said, the specific case of > >> non-constant VF and prologue peeling probably wasn't supposed to happen, > >> instead the prologue usually is applied via an offset to a fully masked loop? > > Hmm, yeah, agree constant_lower_bound should work too. > > > > Thanks, > > Richard > > > >> Richard? > >> > >> Thanks, > >> Richard. > >> > >>> Michael > >>> > >>> gcc/ > >>> > >>> * tree-vect-loop-manip.cc (vect_do_peeling): Verify > >>> that vectorization factor is a compile-time constant. > >>> > >>> --- > >>> gcc/tree-vect-loop-manip.cc | 2 +- > >>> 1 file changed, 1 insertion(+), 1 deletion(-) > >>> > >>> diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc > >>> index 6aa3d2ed0bf..1ad1961c788 100644 > >>> --- a/gcc/tree-vect-loop-manip.cc > >>> +++ b/gcc/tree-vect-loop-manip.cc > >>> @@ -2930,7 +2930,7 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree > >>> niters, tree nitersm1, > >>> niters = vect_build_loop_niters (loop_vinfo, &new_var_p); > >>> /* It's guaranteed that vector loop bound before vectorization is at > >>> least VF, so set range information for newly generated var. */ > >>> - if (new_var_p) > >>> + if (new_var_p && vf.is_constant ()) > >>> { > >>> value_range vr (type, > >>> wi::to_wide (build_int_cst (type, vf)), > >>> -- > >>> 2.34.1 > >>>
diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc index 6aa3d2ed0bf..1ad1961c788 100644 --- a/gcc/tree-vect-loop-manip.cc +++ b/gcc/tree-vect-loop-manip.cc @@ -2930,7 +2930,7 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, tree nitersm1, niters = vect_build_loop_niters (loop_vinfo, &new_var_p); /* It's guaranteed that vector loop bound before vectorization is at least VF, so set range information for newly generated var. */ - if (new_var_p) + if (new_var_p && vf.is_constant ()) { value_range vr (type,