From patchwork Tue Oct 13 08:40:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongtao Liu X-Patchwork-Id: 1381404 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=bDmMYxZF; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C9TWZ4Sgqz9sTv for ; Tue, 13 Oct 2020 19:40:10 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 59A5A3842419; Tue, 13 Oct 2020 08:39:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 59A5A3842419 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1602578396; bh=7yxwbpMxR5zi6CDu8s1+mm7IO0mUVWWQcqcZzOd3ezs=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=bDmMYxZFcD4ojaeehq6sXR+Mo4enNlLalKViZgDmjnXYd3kigv7FTzrfoEly6vU59 PZhAGQ78Hv4IJjZWopf6XdmEBC8p8X6DDRzjAPBez9y3RC1NFSOIwBs7r61Mba5fmO eMVnZYcvxX/H1RNzh2mveNrKG0K+gczi/VXVfAFE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ua1-x932.google.com (mail-ua1-x932.google.com [IPv6:2607:f8b0:4864:20::932]) by sourceware.org (Postfix) with ESMTPS id 7F7B43857003 for ; Tue, 13 Oct 2020 08:39:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7F7B43857003 Received: by mail-ua1-x932.google.com with SMTP id y1so4709845uac.13 for ; Tue, 13 Oct 2020 01:39:53 -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:from:date:message-id:subject:to:cc; bh=7yxwbpMxR5zi6CDu8s1+mm7IO0mUVWWQcqcZzOd3ezs=; b=qVueEvlZ1tZ0rWFQhz/FEP6SrOHgHrEXJjla1V4lA9AY2l0Av5gIlnpz4oj/Mq4hFG 8fjS8ldUbypCI6DejgUBTRRgW5+n2rRfT9xEZJ+Qat+qHjsK5ZhCNsqyHwHna0C0A3JR PueiK8TC1vNaMAtP0sW+C/f/FH9E4UJeZo71IvD7dujeYpxWVVKsVOGp1uZ0rXPNG+bE Vx5TJNXmmvRA955JbXNZD+01fPvZFQZMfuQ8TNWJCHW5Ebp/rYxneayhwFyDCiEPjhmN jX/HKxMHiYnaWCMA8J4qRKcBG+I/JAA844KaXAJii2ILhr41s2eMXV0LH/zkW1DaN8v+ VHHw== X-Gm-Message-State: AOAM533akHWtxVj0J1r7b46936la8elYhSuoI/tyCniZx0iWQfJS1bkQ q3diux2FsKWzEGzgS47tdFlwdkmP/GjJQq1M6/q+5yUoLDlZJA== X-Google-Smtp-Source: ABdhPJxhydGUlenB9YBJC54x1f175kqAGinxS8WhHJlY7u0Rz50sN3RjhJd/M8FPWMEKxSHGPMTpQTcFMv8PYDxz0mc= X-Received: by 2002:ab0:2a02:: with SMTP id o2mr4936110uar.35.1602578392937; Tue, 13 Oct 2020 01:39:52 -0700 (PDT) MIME-Version: 1.0 Date: Tue, 13 Oct 2020 16:40:53 +0800 Message-ID: Subject: [PATCH] [PR rtl-optimization/97249]Simplify vec_select of paradoxical subreg. To: GCC Patches , Segher Boessenkool X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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-Patchwork-Original-From: Hongtao Liu via Gcc-patches From: Hongtao Liu Reply-To: Hongtao Liu Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi: For rtx like (vec_select:V2SI (subreg:V4SI (inner:V2SI) 0) (parallel [(const_int 0) (const_int 1)])) it could be simplified as inner. Bootstrap is ok, regression test on i386 backend is ok. gcc/ChangeLog PR rtl-optimization/97249 * simplify-rtx.c (simplify_binary_operation_1): Simplify vec_select of paradoxical subreg. gcc/testsuite/ChangeLog * gcc.target/i386/pr97249-1.c: New test. From c00369aa36d2e169b59287c58872c915953dd2a2 Mon Sep 17 00:00:00 2001 From: liuhongt Date: Tue, 13 Oct 2020 15:35:29 +0800 Subject: [PATCH] Simplify vec_select of paradoxical subreg. For rtx like (vec_select:V2SI (subreg:V4SI (inner:V2SI) 0) (parallel [(const_int 0) (const_int 1)])) it could be simplified as inner. gcc/ChangeLog PR rtl-optimization/97249 * simplify-rtx.c (simplify_binary_operation_1): Simplify vec_select of paradoxical subreg. gcc/testsuite/ChangeLog * gcc.target/i386/pr97249-1.c: New test. --- gcc/simplify-rtx.c | 27 ++++++++++++++++++++ gcc/testsuite/gcc.target/i386/pr97249-1.c | 30 +++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/pr97249-1.c diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 869f0d11b2e..9c397157f28 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -4170,6 +4170,33 @@ simplify_binary_operation_1 (enum rtx_code code, machine_mode mode, return subop1; } } + + /* For cases like + (vec_select:V2SI (subreg:V4SI (inner:V2SI) 0) + (parallel [(const_int 0) (const_int 1)])). + return inner directly. */ + if (GET_CODE (trueop0) == SUBREG + && paradoxical_subreg_p (trueop0) + && mode == GET_MODE (XEXP (trueop0, 0)) + && (GET_MODE_NUNITS (GET_MODE (trueop0))).is_constant (&l0) + && (GET_MODE_NUNITS (mode)).is_constant (&l1) + && l0 % l1 == 0) + { + gcc_assert (known_eq (XVECLEN (trueop1, 0), l1)); + unsigned HOST_WIDE_INT expect = (HOST_WIDE_INT_1U << l1) - 1; + unsigned HOST_WIDE_INT sel = 0; + int i = 0; + for (;i != l1; i++) + { + rtx j = XVECEXP (trueop1, 0, i); + if (!CONST_INT_P (j)) + break; + sel |= HOST_WIDE_INT_1U << UINTVAL (j); + } + /* ??? Need to simplify XEXP (trueop0, 0) here. */ + if (sel == expect) + return XEXP (trueop0, 0); + } } if (XVECLEN (trueop1, 0) == 1 diff --git a/gcc/testsuite/gcc.target/i386/pr97249-1.c b/gcc/testsuite/gcc.target/i386/pr97249-1.c new file mode 100644 index 00000000000..bc34aa8baa6 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr97249-1.c @@ -0,0 +1,30 @@ +/* PR target/97249 */ +/* { dg-do compile } */ +/* { dg-options "-mavx2 -O3 -masm=att" } */ +/* { dg-final { scan-assembler-times "vpmovzxbw\[ \t\]+\\\(\[^\n\]*%xmm\[0-9\](?:\n|\[ \t\]+#)" 2 } } */ +/* { dg-final { scan-assembler-times "vpmovzxwd\[ \t\]+\\\(\[^\n\]*%xmm\[0-9\](?:\n|\[ \t\]+#)" 2 } } */ +/* { dg-final { scan-assembler-times "vpmovzxdq\[ \t\]+\\\(\[^\n\]*%xmm\[0-9\](?:\n|\[ \t\]+#)" 2 } } */ + +void +foo (unsigned char* p1, unsigned char* p2, short* __restrict p3) +{ + for (int i = 0 ; i != 8; i++) + p3[i] = p1[i] + p2[i]; + return; +} + +void +foo1 (unsigned short* p1, unsigned short* p2, int* __restrict p3) +{ + for (int i = 0 ; i != 4; i++) + p3[i] = p1[i] + p2[i]; + return; +} + +void +foo2 (unsigned int* p1, unsigned int* p2, long long* __restrict p3) +{ + for (int i = 0 ; i != 2; i++) + p3[i] = (long long)p1[i] + (long long)p2[i]; + return; +} -- 2.18.1