From patchwork Tue Jan 31 08:01:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 50673 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2619888wrn; Tue, 31 Jan 2023 00:02:54 -0800 (PST) X-Google-Smtp-Source: AK7set/b7WedJYuBXA2BSASNqsXu7MYX38BRqBDS+5WQ7sAbcI7DnOYD+lrOew1oEo1vGaL40EDx X-Received: by 2002:a17:906:25d1:b0:87f:1d80:cda8 with SMTP id n17-20020a17090625d100b0087f1d80cda8mr14320746ejb.25.1675152173742; Tue, 31 Jan 2023 00:02:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675152173; cv=none; d=google.com; s=arc-20160816; b=CMlA34P4MzesC+zueCbX5xUc1mTZ2d5OS8FfoEgxUlznqGBlAI1vaXI2w9YbVmoOmF hKfug4D0vA9zevJmp29moUJHMLSOAOvSc7FPXutnxYiR4m1tmj2Y81R6y8F6TXXIIIJP xp9Ba0HEGOienW2GQlcsePw6yXYh2LTWeGrtUg86PMTW9ZLAubzds7vcWmJbcYQ6UPnn AhYHnodblhQOSJnGp+jYjr1rz0qr4AWFhJ1n/G/nP6UOvhYtmMAjLsDxHlqmf6IKn1js GjoGPmVtHVkD9F6WASPthK4yxVnMeqhvuO1ZfH8AwHIDCdbf3mZgx+TatdjZExcXPFmK k8FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=u7VozFY6TpIx/sH0BrU4E+mG1bAJFg1ZQbq8iX2aJgo=; b=02gc1KqOAfTLX8GfIHn77PTa0y5pY4kXGmuOsk5zTQ8DIRPzTpAq6oA2Ej0lUGD5Uc /4xZBrW/OHcbgJabsIbig9cn5+mqfa1rR2NqnCv9qYGfd9wZmJwz7kENp6m2Vs2pEenK XOPmg2lzAPU7NDHjBCeYlgJYBtW3kOMgxtaNb9O+sHf3pJAu4AqPOvtqttfDduIQOYeN RLnWkfc0ragvsV/Y05XXxbf0Ibfe/JhH3s/jyDSS8H7qp85nhlJ4pxvDnsH2qIFiZtJK KeFiNrTaxNhqoPKZxE+qlmxxkzZAP0ti2ZzYhfoMPtKjr8xyksbHXYfFhfm9OZ4ytNO0 kp5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LlzNudOV; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 18-20020a170906001200b007ba713e241dsi20045412eja.894.2023.01.31.00.02.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 00:02:53 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LlzNudOV; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8945C385840D for ; Tue, 31 Jan 2023 08:02:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8945C385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675152172; bh=u7VozFY6TpIx/sH0BrU4E+mG1bAJFg1ZQbq8iX2aJgo=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=LlzNudOVNvy97r/qAOi5V6Mod/1HHM/zFDxP3UmI562V6IiINSZTHX423AIde0UTy 079THQzNaC9toDHHslDiUzE7uNAcSrGjYJwkmO/zovb1FW6eMUsMFXkL2HsBUNXsr1 cb3H1xbsPtffeysKKHOZc8DzI+8zAkUd2pFZ8pr8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 365E73858D1E for ; Tue, 31 Jan 2023 08:01:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 365E73858D1E Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-637-s5wnT0jmONi9_gDE7s2aVg-1; Tue, 31 Jan 2023 03:01:57 -0500 X-MC-Unique: s5wnT0jmONi9_gDE7s2aVg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3CD6E800B30; Tue, 31 Jan 2023 08:01:57 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EC15A175A2; Tue, 31 Jan 2023 08:01:56 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 30V81sFv1011545 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 31 Jan 2023 09:01:54 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 30V81r751011544; Tue, 31 Jan 2023 09:01:53 +0100 Date: Tue, 31 Jan 2023 09:01:52 +0100 To: Hongtao Liu , Uros Bizjak Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] i386: Fix up ix86_convert_const_wide_int_to_broadcast [PR108599] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756524365990734931?= X-GMAIL-MSGID: =?utf-8?q?1756524365990734931?= Hi! The following testcase is miscompiled. The problem is that during RTL DSE we see a V4DI register is being loaded { 16, 16, 0, 0 } value and DSE mostly works in terms of scalar modes, so it calls movoi to set an OImode REG to (const_wide_int 0x100000000000000010) and ix86_convert_const_wide_int_to_broadcast thinks it can compute that value by broadcasting DImode 0x10. While it is true that for TImode result the broadcast could be used, for OImode/XImode it can't be, because all but the lowest 2 HOST_WIDE_INTs aren't present (so are 0 or -1 depending on sign), not 0x10 in this case. The function checks if the least significant HOST_WIDE_INT elt of the CONST_WIDE_INT is broadcastable from QI/HI/SI/DImode and then /* Check if OP can be broadcasted from VAL. */ for (int i = 1; i < CONST_WIDE_INT_NUNITS (op); i++) if (val != CONST_WIDE_INT_ELT (op, i)) return nullptr; That is needed of course, but nothing checks that CONST_WIDE_INT_NUNITS (op) isn't too small for the mode in question. I think if op would be 0 or -1, it ought to be never CONST_WIDE_INT, but CONST_INT and so we can just punt whenever the number of CONST_WIDE_INT elts is not the expected one. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-01-31 Jakub Jelinek PR target/108599 * config/i386/i386-expand.cc (ix86_convert_const_wide_int_to_broadcast): Return nullptr if CONST_WIDE_INT_NUNITS (op) times HOST_BITS_PER_WIDE_INT isn't equal to bitsize of mode. * gcc.target/i386/avx2-pr108599.c: New test. Jakub --- gcc/config/i386/i386-expand.cc.jj 2023-01-19 23:22:05.306066616 +0100 +++ gcc/config/i386/i386-expand.cc 2023-01-30 15:33:43.418598714 +0100 @@ -291,7 +291,9 @@ ix86_convert_const_wide_int_to_broadcast broadcast only if vector broadcast is available. */ if (!TARGET_AVX || !CONST_WIDE_INT_P (op) - || standard_sse_constant_p (op, mode)) + || standard_sse_constant_p (op, mode) + || (CONST_WIDE_INT_NUNITS (op) * HOST_BITS_PER_WIDE_INT + != GET_MODE_BITSIZE (mode))) return nullptr; HOST_WIDE_INT val = CONST_WIDE_INT_ELT (op, 0); --- gcc/testsuite/gcc.target/i386/avx2-pr108599.c.jj 2023-01-30 16:04:31.984429702 +0100 +++ gcc/testsuite/gcc.target/i386/avx2-pr108599.c 2023-01-30 16:04:24.459540223 +0100 @@ -0,0 +1,32 @@ +/* PR target/108599 */ +/* { dg-do run { target avx2 } } */ +/* { dg-options "-O2 -mavx2 -mtune=skylake-avx512" } */ + +#include "avx2-check.h" + +struct S { unsigned long long a, b, c, d; }; + +__attribute__((noipa)) void +foo (unsigned long long x, unsigned long long y, + unsigned long long z, unsigned long long w, const struct S s) +{ + if (s.a != x || s.b != y || s.c != z || s.d != w) + abort (); +} + +typedef unsigned long long V __attribute__((may_alias, vector_size (4 * sizeof (unsigned long long)))); + +static void +avx2_test (void) +{ + { + struct S s; + *(V *)&s = (V) { 16, 0, 0, 0 }; + foo (16, 0, 0, 0, s); + } + { + struct S s; + *(V *)&s = (V) { 16, 16, 0, 0 }; + foo (16, 16, 0, 0, s); + } +}