From patchwork Sun Oct 27 23:41:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 2003032 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=jLlUltCv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XcCj65yggz1xwc for ; Mon, 28 Oct 2024 10:41:45 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5EDAB3858C56 for ; Sun, 27 Oct 2024 23:41:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by sourceware.org (Postfix) with ESMTPS id 727DF3858D26 for ; Sun, 27 Oct 2024 23:41:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 727DF3858D26 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=quicinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 727DF3858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730072481; cv=none; b=mDny0h8GvuPI3AP0QhBuLdJW64OnuJFU5ilebaelmoI+EYTQn/MRcGId71tFi7w2TzyY/jXgJW7VsqR/WLT9wnQOqE6UR95ei0iTQB416frXC+X47BOI+F1NVp5e4ewkTBaiS5TY+A2TJlMscHy8Ejri+/sOlMmVGlhOWm+uUgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730072481; c=relaxed/simple; bh=mX+YDfW5LEo/r9k6B7xTzSGzIka953pLEnswwcnIl/g=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=DjzOFbbCCzzt3083gX3SXD+yDeNryvRNEjhYlLtCqgTbmeSH+oDmQP7x6NBnAIFR4WJNLYTjdkrtsaSkUqED//icH9IHGEtPnIE9Yo7MKFZuOk6++dBOODsfemONgqGPhQR0PxFfRQW/XIzLq5f/voeX2V8o19POUyZzmZV0ZUM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49RNU16Y012525 for ; Sun, 27 Oct 2024 23:41:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=qcppdkim1; bh=vSqYZ2Ng/kzktIwck1TfQX FSHLr/vEcuBG4lK5clbfs=; b=jLlUltCvxbFNi0A8h6QizKHJMmOdUFrhZIL6xZ cAoFxgrK0Pg7UcErwESjIynV9lZL6fLzpAXFbjheN4SN1qA3wFEMh4/2mm+M+yq8 0TVv3dd8P1MjYuO4e/RZchFOwGEqla70aQdDdY/8G92kWx7peEZHnZ2BE2oPmEYM tCMFIJC085jlF6QQNSQiBpl2F4/EVkctCbe5D6147k42cAor1T02Dxa7ijEgLu8F +7b07tgDf93QmRzi/8j+ONAxZRDcg0UjZUO5gT9TNIs5vL35f0zfpAlmF1cW91C0 xyaz3MUT//HnYQrTpvV/lMM4jVjo6HeRqKWmKOh/LFo5gwDQ== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42grgub5m3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 27 Oct 2024 23:41:19 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA05.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 49RNfI8E024326 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 27 Oct 2024 23:41:18 GMT Received: from hu-apinski-lv.qualcomm.com (10.49.16.6) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Sun, 27 Oct 2024 16:41:18 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH] vec-lowering: Fix ABSU lowering [PR111285] Date: Sun, 27 Oct 2024 16:41:06 -0700 Message-ID: <20241027234106.218194-1-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: mIxafwauFjnxHv53m5xwBF4_CyEvXYvh X-Proofpoint-GUID: mIxafwauFjnxHv53m5xwBF4_CyEvXYvh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 lowpriorityscore=0 adultscore=0 mlxscore=0 bulkscore=0 suspectscore=0 phishscore=0 spamscore=0 malwarescore=0 mlxlogscore=557 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410270209 X-Spam-Status: No, score=-14.0 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_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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org ABSU_EXPR lowering incorrectly used the resulting type for the new expression but in the case of ABSU the resulting type is an unsigned type and with ABSU is folded away. The fix is to use a signed type for the expression instead. Bootstrapped and tested on x86_64-linux-gnu. PR middle-end/111285 gcc/ChangeLog: * tree-vect-generic.cc (do_unop): Use a signed type for the operand if the operation was ABSU_EXPR. gcc/testsuite/ChangeLog: * g++.dg/torture/vect-absu-1.C: New test. Signed-off-by: Andrew Pinski --- gcc/testsuite/g++.dg/torture/vect-absu-1.C | 29 ++++++++++++++++++++++ gcc/tree-vect-generic.cc | 10 +++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/torture/vect-absu-1.C diff --git a/gcc/testsuite/g++.dg/torture/vect-absu-1.C b/gcc/testsuite/g++.dg/torture/vect-absu-1.C new file mode 100644 index 00000000000..0b2035f638f --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/vect-absu-1.C @@ -0,0 +1,29 @@ +// { dg-do run } +// PR middle-end/111285 + +// The lowering of vect absu was done incorrectly + +#define vect1 __attribute__((vector_size(sizeof(int)))) + +#define negabs(a) a < 0 ? a : -a + +__attribute__((noinline)) +int s(int a) +{ + return negabs(a); +} +__attribute__((noinline)) +vect1 int v(vect1 int a) +{ + return negabs(a); +} + +int main(void) +{ + for(int i = -10; i < 10; i++) + { + vect1 int t = {i}; + if (v(t)[0] != s(i)) + __builtin_abort(); + } +} diff --git a/gcc/tree-vect-generic.cc b/gcc/tree-vect-generic.cc index ef7d2dd259d..21d906e9c55 100644 --- a/gcc/tree-vect-generic.cc +++ b/gcc/tree-vect-generic.cc @@ -168,7 +168,15 @@ do_unop (gimple_stmt_iterator *gsi, tree inner_type, tree a, tree b ATTRIBUTE_UNUSED, tree bitpos, tree bitsize, enum tree_code code, tree type ATTRIBUTE_UNUSED) { - a = tree_vec_extract (gsi, inner_type, a, bitsize, bitpos); + tree rhs_type = inner_type; + + /* For ABSU_EXPR, use the signed type for the rhs if the rhs was signed. */ + if (code == ABSU_EXPR + && ANY_INTEGRAL_TYPE_P (TREE_TYPE (a)) + && !TYPE_UNSIGNED (TREE_TYPE (a))) + rhs_type = signed_type_for (rhs_type); + + a = tree_vec_extract (gsi, rhs_type, a, bitsize, bitpos); return gimplify_build1 (gsi, code, inner_type, a); }