From patchwork Sun Sep 24 16:24:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 144117 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp742286vqu; Sun, 24 Sep 2023 09:24:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH6iVtkuxysGvWWls2LbRHVLHmBRp2FsYXFT7nd0uUC0a8BgHzQPd8lj5HawUekwValmrtd X-Received: by 2002:a05:6402:134d:b0:530:9e58:db59 with SMTP id y13-20020a056402134d00b005309e58db59mr3738769edw.3.1695572697084; Sun, 24 Sep 2023 09:24:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695572697; cv=none; d=google.com; s=arc-20160816; b=AbPCOY0i52evxgSBQEwuVJZ2J9tRUicHGrz8olk1WXnSwNipyZJTc4Ekb4eIEAM+ai v2v/yzk/pzz3L597ieeInKjdyHwnfn5JwNzdR6TZ3uhTQ6G3l1ePdUUHbP19O9txY7ke 6x3gMVnjVi4XjjtAyZrErjxFsXtvNorjkBiuaWjgP8iJzREsH57H3lgiFk0RDBPKvr0s bDclSl5Jg1HWNxxKN1BoLrGqQnrZ/+UFz+M9dsxaCIUM9UZdbRFTl6hYLNnxrBvvVUTm qUfoHfuHDdvtVhnX4kdFGEjY4Z+IdA2/RwszwzUpBdY7OKqXOmxM3fUI4jCO8P2kYirO ebOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=Dk/mrJ1olZKW6T2lfcwQuGsOwqBaE+MUCFt+1Tnpnp0=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=b4fUnr/KbJPOrntV+iF0aSruBsIht/ZU/mXngNc/PMjrpa6PrlCl9Ai56s5rGMQc+u m0HdmSwViZ2VBLVR5fOeg3V0yzV7L+hcaxHVW4PY1EeDM93IPx3r7UUGxqJgh7beUkFf gaPDL+3itRRr5MPDtOd/DlisFSEM5sBnhvRniedYQi+G4wRzgfgcRiADmSqDzN8BjY0Q l5RTW0kEQBz7sXFO4q2FAvOYEGGcEvN5nm+VT/Yb4qbcdhGDa5NO/UidjTwuiBqfHHso gQ3UXYCGqy4Pk1AD0/I4IpN5J7fbiGPbHltbm3DuwS+W1bGoOur2OoTvHJfpU1Bbv4U3 ie1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marvell.com header.s=pfpt0220 header.b=FVYpgn2M; 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=REJECT dis=NONE) header.from=marvell.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id x19-20020aa7d393000000b005333c5cd07dsi6914758edq.282.2023.09.24.09.24.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 09:24:57 -0700 (PDT) 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=@marvell.com header.s=pfpt0220 header.b=FVYpgn2M; 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=REJECT dis=NONE) header.from=marvell.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E8FB03857355 for ; Sun, 24 Sep 2023 16:24:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 5AFD53858D32 for ; Sun, 24 Sep 2023 16:24:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5AFD53858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=marvell.com Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38OFrkkX002508 for ; Sun, 24 Sep 2023 09:24:21 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=Dk/mrJ1olZKW6T2lfcwQuGsOwqBaE+MUCFt+1Tnpnp0=; b=FVYpgn2MjVAsMXSA7lit9i+wD8/abWDbl7jxEkTgcjcQiWuVMf98z4DQVCto3yh4VzoR bMmoM2zCxb9NMsDwIyySwAQAQuv+Nw36PZScKX6kDylJWbenusAKrvntAE8UMobfuUuO 2QyFYiv//W5pMMUPJv0rpqJOwkdAkUVloGeaAlwpHg7p2oSCXcStnpiNPBddk47DfEcf ruNR4f5M6rdkGV8uIbDXma82D6Tyi2A0qFODQxm5kEiMD1sR5+Lnd2ZJtCodeojgcPr5 DAyQFw3TGnPG9FqObG9EKBKOR8zqzqieyy2ktxcGhVoXtLpCKgfSfQUQmbKgol2Y6OoN LQ== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3t9wcqk23x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 24 Sep 2023 09:24:20 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sun, 24 Sep 2023 09:24:19 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Sun, 24 Sep 2023 09:24:19 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id A0F163F70B4; Sun, 24 Sep 2023 09:24:17 -0700 (PDT) From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH] Fix PR 110386: backprop vs ABSU_EXPR Date: Sun, 24 Sep 2023 09:24:09 -0700 Message-ID: <20230924162409.2151727-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: a0XhrvVDnGCtpgnv8lqo7u34R9_aP0p9 X-Proofpoint-GUID: a0XhrvVDnGCtpgnv8lqo7u34R9_aP0p9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-24_13,2023-09-21_01,2023-05-22_02 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777936835991574485 X-GMAIL-MSGID: 1777936835991574485 The issue here is that when backprop tries to go and strip sign ops, it skips over ABSU_EXPR but ABSU_EXPR not only does an ABS, it also changes the type to unsigned. Since strip_sign_op_1 is only supposed to strip off sign changing operands and not ones that change types, removing ABSU_EXPR here is correct. We don't handle nop conversions so this does cause any missed optimizations either. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/110386 gcc/ChangeLog: * gimple-ssa-backprop.cc (strip_sign_op_1): Remove ABSU_EXPR. gcc/testsuite/ChangeLog: * gcc.c-torture/compile/pr110386-1.c: New test. * gcc.c-torture/compile/pr110386-2.c: New test. --- gcc/gimple-ssa-backprop.cc | 1 - gcc/testsuite/gcc.c-torture/compile/pr110386-1.c | 9 +++++++++ gcc/testsuite/gcc.c-torture/compile/pr110386-2.c | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr110386-1.c create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr110386-2.c diff --git a/gcc/gimple-ssa-backprop.cc b/gcc/gimple-ssa-backprop.cc index 65a65590017..dcb15ed4f61 100644 --- a/gcc/gimple-ssa-backprop.cc +++ b/gcc/gimple-ssa-backprop.cc @@ -694,7 +694,6 @@ strip_sign_op_1 (tree rhs) switch (gimple_assign_rhs_code (assign)) { case ABS_EXPR: - case ABSU_EXPR: case NEGATE_EXPR: return gimple_assign_rhs1 (assign); diff --git a/gcc/testsuite/gcc.c-torture/compile/pr110386-1.c b/gcc/testsuite/gcc.c-torture/compile/pr110386-1.c new file mode 100644 index 00000000000..4fcc977ad16 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr110386-1.c @@ -0,0 +1,9 @@ + +int f(int a) +{ + int c = c < 0 ? c : -c; + c = -c; + unsigned b = c; + unsigned t = b*a; + return t*t; +} diff --git a/gcc/testsuite/gcc.c-torture/compile/pr110386-2.c b/gcc/testsuite/gcc.c-torture/compile/pr110386-2.c new file mode 100644 index 00000000000..c60e1b6994b --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr110386-2.c @@ -0,0 +1,11 @@ +/* { dg-do compile { target i?86-*-* x86_64-*-* } } */ +/* { dg-options "-mavx" } */ + +#include + +__m128i do_stuff(__m128i XMM0) { + __m128i ABS0 = _mm_abs_epi32(XMM0); + __m128i MUL0 = _mm_mullo_epi32(ABS0, XMM0); + __m128i MUL1 = _mm_mullo_epi32(MUL0, MUL0); + return MUL1; +}