From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id C173E3850413 for ; Wed, 23 Jun 2021 09:08:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C173E3850413 Received: by mail-ej1-x62a.google.com with SMTP id bu12so2980408ejb.0 for ; Wed, 23 Jun 2021 02:08:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=CRyTx05EkkT8aXJvJAfFwuFga0qeFmQ6k5GZJ2piBNc=; b=fD44lKCwsyI//Rfi9JNI8dKGTYhjqGUxjyEbA9z6KNCR34q0J4sMByIWL2o0uYfvw0 ZNI7N6jKA0rip1NlTQJp9TIOpTM4BR6KO5MngJqo7TkNX2g1sdxk3Oi36M79M8ScK6/Q 8QQtL8JC3VxPMukELZc1lqd7NXc2trACUxohz+6w8Zlx6qAfFhKa4dCRj1KiMgcT9jJu WNJx8dLEGA9xXxKPO9w8YDwsYdlggo0qWVfUp57t+TDFkzPwU7meaR9R0eM3W1Iy3I5M EW2S9A8VAycWlTZqZZlpm/j8sMP+6bVJNl91tvMZJqdPbAZKKBhEXP2EAjFoe6csXxog OaDQ== X-Gm-Message-State: AOAM530BM9uWuWX5iCo/ti/6NGFTqE0sl6MdnaLMEFAPk/07NqBlqEmp cyucMUz8p311EQ+S4lEQ/JLn9Fe2bvIHgb43WsM= X-Google-Smtp-Source: ABdhPJymb2WT2/+/YVANVaBhYggA94J4K87fXoty9iNavLfOsMATSynzWoFCpIJV8lLlrZ/iBUxxaWgJdiGV+62YrTY= X-Received: by 2002:a17:906:914a:: with SMTP id y10mr9186702ejw.235.1624439283731; Wed, 23 Jun 2021 02:08:03 -0700 (PDT) MIME-Version: 1.0 References: <20210623080103.GG7746@tucnak> In-Reply-To: <20210623080103.GG7746@tucnak> From: Richard Biener Date: Wed, 23 Jun 2021 11:07:52 +0200 Message-ID: Subject: Re: [PATCH] [i386] Support avx512 vector shift with vector [PR98434] To: Jakub Jelinek Cc: Hongtao Liu , GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Jun 2021 09:08:06 -0000 On Wed, Jun 23, 2021 at 10:01 AM Jakub Jelinek wrote: > > On Wed, Jun 23, 2021 at 09:53:27AM +0200, Richard Biener via Gcc-patches wrote: > > On Wed, Jun 23, 2021 at 9:19 AM Hongtao Liu via Gcc-patches > > wrote: > > > > > > Here's the patch I'm going to check in. > > > > > > The patch will regress pr91838.C with extra options: -march=cascadelake > > > > > > using T = unsigned char; // or ushort, or uint > > > using V [[gnu::vector_size(8)]] = T; > > > V f(V x) { return x >> 8 * sizeof(T); } > > > > > > Basically, the testcase is UB with logic right shift more than 8 bits > > > > I don't see any UB here, it's just x >> 8 but we indeed fail to constant > > fold this. For scalars bit CCP does this, but we seem to lack a > > For scalar T y = ...; y >> 8 is not UB because of integral promotion to > int, but we do not perform such integral promotions for vector types, > so arguably x >> 8 is UB. But this vector shift is a GCC extension and we dont document this UB which means the natural reading would be that the shift is applied to the promoted element and then the result truncated? We document: It is possible to use shifting operators @code{<<}, @code{>>} on integer-type vectors. The operation is defined as following: @code{@{a0, a1, @dots{}, an@} >> @{b0, b1, @dots{}, bn@} == @{a0 >> b0, a1 >> b1, @dots{}, an >> bn@}}@. Vector operands must have the same number of elements. so IMHO it's not UB and nothing optimizes it since VRP and bit CCP only operate on scalars, not vectors. Of course it would take quite some work in those passes to also fold sth like __builtin_convertvector (v4qi, v4si) >> 8 thus where a unsigned char vector is widened to int and the int vector shifted. Richard. > Jakub >