From patchwork Tue Jun 6 08:21:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 103627 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3233440vqr; Tue, 6 Jun 2023 01:24:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5yaMsr0wXoVqVwaRAI0i3nJM983li5VmBdDoD6fqy4aDHvIGu4bh/vEOWmGSrJcolEj5p0 X-Received: by 2002:a17:906:6a0b:b0:970:1b2d:45bf with SMTP id qw11-20020a1709066a0b00b009701b2d45bfmr1737024ejc.61.1686039889804; Tue, 06 Jun 2023 01:24:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686039889; cv=none; d=google.com; s=arc-20160816; b=Vf1PPoF1ZQPUKmMxVqh5aD4jIUTN1SnTeDWY6vlJP00hyecI7be+Z72lH/T24HVDLl 9canXY1ZXIZO4QjbmRFp/Tu3NM9P7azr/G6dBLkRsA+NhagXDiP4/bAnMe5eVdvdBXa6 YTcEhBuIrH+GJhelB6rlVmN9zK+i5FpE4L09j44TBeLaUTWpc/DI/WCTSY1h755Vk4Cj jKxztwPIfTm37300821VkITRc68eoLbVjgg3qWKzpiwnIA6tlRZ90zTGFst7jbDbU5KT ZnhHVs76smerL34e7mcqmtNz2u2oTDPhYWXn+unTPCWce7OUWzVWRfBMyLMEdo3CDWaN LAyg== 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-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=ubZO2pb/D1tNIUPz26B69o2VzvSUYvI3BwGTGlvbJ54=; b=ID6n0MJEbkgWJvZ7PJTY3G1i/+rpiMtuyJOlFZZaYRLk6US/qwHuxXKLVDGfJnEJq/ 1GvXs6p3DZjMpDUnyCtdpa/2ZIf3NBh9Nqo3kr4jDp9HCqpjlMLJV6tGwqk+QPNjVarW GGTxOhr8mIEd9THelXijCh+CGLjCVwSG5Q8nvbzgIzTtwyOaBJ6zwxJX5S4ZeNSdXSZ3 9Bg9aeePX/7whv8MBVqmqBBhs/tVoncQuxGT7Cz6QnKQZAa0i53zIpUht15/l/MpRtIZ MmAVXnXNrlPh67uQ1VXokJPU+UzB9iNIlYdYNshqobIlFJG2Q4Q5RCRIYbB59kfz8+MI ZlLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=JpJAmOSW; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id h3-20020a17090791c300b00977cc168e2csi3593977ejz.262.2023.06.06.01.24.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 01:24:49 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=JpJAmOSW; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 877E93858032 for ; Tue, 6 Jun 2023 08:24:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 877E93858032 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686039888; bh=ubZO2pb/D1tNIUPz26B69o2VzvSUYvI3BwGTGlvbJ54=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=JpJAmOSWlXFp9VFYN6wFWI1eOj7f7ujT9WsYLFbE3ThfYUgpwzUI2/jgISLG/h88i vrhGxBX7qnBhtvwZISWj9jpyJutLlPd9XfviKXm7hGkeRtEeZci5n2PljSW9EoDtGe F+VVO2KSlZGE13JOwZD/MXVQOQaBZi9VZP3Dljak= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by sourceware.org (Postfix) with ESMTPS id 8EA9E3858416 for ; Tue, 6 Jun 2023 08:23:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8EA9E3858416 X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="384910126" X-IronPort-AV: E=Sophos;i="6.00,219,1681196400"; d="scan'208";a="384910126" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jun 2023 01:23:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="1039096761" X-IronPort-AV: E=Sophos;i="6.00,219,1681196400"; d="scan'208";a="1039096761" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmsmga005.fm.intel.com with ESMTP; 06 Jun 2023 01:23:50 -0700 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 2D599100562A; Tue, 6 Jun 2023 16:23:50 +0800 (CST) To: gcc-patches@gcc.gnu.org Cc: crazylht@gmail.com, hjl.tools@gmail.com Subject: [PATCH v2] Explicitly view_convert_expr mask to signed type when folding pblendvb builtins. Date: Tue, 6 Jun 2023 16:21:50 +0800 Message-Id: <20230606082150.657119-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.39.1.388.g2fc9e9ca3c In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 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: liuhongt via Gcc-patches From: liuhongt Reply-To: liuhongt 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?1767940963098638493?= X-GMAIL-MSGID: =?utf-8?q?1767940963098638493?= > I think this is a better patch and will always be correct and still > get folded at the gimple level (correctly): > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc > index d4ff56ee8dd..02bf5ba93a5 100644 > --- a/gcc/config/i386/i386.cc > +++ b/gcc/config/i386/i386.cc > @@ -18561,8 +18561,10 @@ ix86_gimple_fold_builtin (gimple_stmt_iterator *gsi) > tree itype = GET_MODE_INNER (TYPE_MODE (type)) == E_SFmode > ? intSI_type_node : intDI_type_node; > type = get_same_sized_vectype (itype, type); > - arg2 = gimple_build (&stmts, VIEW_CONVERT_EXPR, type, arg2); > } > + else > + type = signed_type_for (type); > + arg2 = gimple_build (&stmts, VIEW_CONVERT_EXPR, type, arg2); > tree zero_vec = build_zero_cst (type); > tree cmp_type = truth_type_for (type); > tree cmp = gimple_build (&stmts, LT_EXPR, cmp_type, arg2, zero_vec); > > Yes, thanks. Here's the updated patch: Since mask < 0 will be always false for vector char when -funsigned-char, but vpblendvb needs to check the most significant bit. The patch explicitly VCE to vector signed char. gcc/ChangeLog: PR target/110108 * config/i386/i386.cc (ix86_gimple_fold_builtin): Explicitly view_convert_expr mask to signed type when folding pblendvb builtins. gcc/testsuite/ChangeLog: * gcc.target/i386/pr110108-2.c: New test. --- gcc/config/i386/i386.cc | 4 +++- gcc/testsuite/gcc.target/i386/pr110108-2.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr110108-2.c diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index da20c2c49de..4e594a9c88e 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -18561,8 +18561,10 @@ ix86_gimple_fold_builtin (gimple_stmt_iterator *gsi) tree itype = GET_MODE_INNER (TYPE_MODE (type)) == E_SFmode ? intSI_type_node : intDI_type_node; type = get_same_sized_vectype (itype, type); - arg2 = gimple_build (&stmts, VIEW_CONVERT_EXPR, type, arg2); } + else + type = signed_type_for (type); + arg2 = gimple_build (&stmts, VIEW_CONVERT_EXPR, type, arg2); tree zero_vec = build_zero_cst (type); tree cmp_type = truth_type_for (type); tree cmp = gimple_build (&stmts, LT_EXPR, cmp_type, arg2, zero_vec); diff --git a/gcc/testsuite/gcc.target/i386/pr110108-2.c b/gcc/testsuite/gcc.target/i386/pr110108-2.c new file mode 100644 index 00000000000..2d1d2fd4991 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr110108-2.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-mavx2 -O2 -funsigned-char" } */ +/* { dg-final { scan-assembler-times "vpblendvb" 2 } } */ + +#include +__m128i do_stuff_128(__m128i X0, __m128i X1, __m128i X2) { + __m128i Result = _mm_blendv_epi8(X0, X1, X2); + return Result; +} + +__m256i do_stuff_256(__m256i X0, __m256i X1, __m256i X2) { + __m256i Result = _mm256_blendv_epi8(X0, X1, X2); + return Result; +}