From patchwork Wed Aug 21 13:14:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Bergner X-Patchwork-Id: 1974948 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=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=mhClDt9p; 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 4WpmyS68pGz1yXf for ; Wed, 21 Aug 2024 23:14:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CFD02386F47F for ; Wed, 21 Aug 2024 13:14:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id A4134385DC3C for ; Wed, 21 Aug 2024 13:14:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A4134385DC3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A4134385DC3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724246057; cv=none; b=ok9dFpl1AGMUbiwGyf+9U9MRSap6wnTx2fOR/WeqbsaZwk7keckidKOpunm3eEfToxjLtccqlOpAqTR0STruZ8gdX+ghLUZiL5bE+BNm/A69Ca1DK1oSLNZKV4CHPfmB/r4okrDKgAMZmu5fafQimZ62+1hWJHG0LmYc4EUzd4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724246057; c=relaxed/simple; bh=lHVRr3ZFE0qlvhZ2V2IYy0p0g8FUe4wH0ksE6iVAhfY=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=XjfKK5FPym7ur21gdSq8PjneEEYc/BfWnO8SWjrA7gypaXa73f9WBY/AO+EfkFMbQI2/h7d8FbCUZZJuqhz7NLYllfPeeM2AtfCLG5SKitkwa+NUZfsTAVE3fFR1OJ3VE8esvWsyrvgXlQEpZ7ovxq4u7l/Jghcul+4ajgHxsac= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47L3ffoE011178; Wed, 21 Aug 2024 13:14:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h= message-id:date:mime-version:to:cc:from:subject:content-type :content-transfer-encoding; s=pp1; bh=FPJzcSQJV6Gl41vKoI01tyX29h igjHEZ+rfTgKiWnlQ=; b=mhClDt9phig2lpyRJPg51CoPr+y9FjE9fYSviWoUhL EJ2spzUPmvByE1EHh8WN4SfwO+Q8p6rEzvRzGeEXYUoKi8A2p4E/hxt9NvI37W6B bKUOlJGAyERN0oWIvaCus4zgvRJXW5upejM9NHydQsxWigigwAX6XiQJat5UKUn9 xpZ+MKz6aIMnV3L2Koeo3fZcmpOjjIc7A2GLaG4phMJWItWgCvdf9ZJKP+OSuL45 uj9qhmJc8jCIHNL0vyTel/Wm8q5b9A5qqMycOib6XJ/pe7eMobyx08o3zHMbJJVl tY0avQ4+jbw8CDY6Te70ZapXORsYUB8eWBWnzwmZ5dGw== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 412mc4t81s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Aug 2024 13:14:14 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 47L9WMTY014167; Wed, 21 Aug 2024 13:14:14 GMT Received: from smtprelay02.dal12v.mail.ibm.com ([172.16.1.4]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4137pmyruc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Aug 2024 13:14:14 +0000 Received: from smtpav05.dal12v.mail.ibm.com (smtpav05.dal12v.mail.ibm.com [10.241.53.104]) by smtprelay02.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 47LDEBdf38470282 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Aug 2024 13:14:13 GMT Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3F2CC58056; Wed, 21 Aug 2024 13:14:11 +0000 (GMT) Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E27B358052; Wed, 21 Aug 2024 13:14:10 +0000 (GMT) Received: from [9.61.244.112] (unknown [9.61.244.112]) by smtpav05.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 21 Aug 2024 13:14:10 +0000 (GMT) Message-ID: <27941701-c6f0-4b44-8482-3567213584f4@linux.ibm.com> Date: Wed, 21 Aug 2024 08:14:10 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: "Kewen.Lin" , Segher Boessenkool Cc: GCC Patches From: Peter Bergner Subject: [PATCH] rs6000: Fix PTImode handling in power8 swap optimization pass [PR116415] X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: ctYOXYvPwQm7mDNgS9cqayR5S-OrM9Pw X-Proofpoint-GUID: ctYOXYvPwQm7mDNgS9cqayR5S-OrM9Pw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-21_10,2024-08-19_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=999 adultscore=0 phishscore=0 impostorscore=0 suspectscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2408210095 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, 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.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 Our power8 swap optimization pass has some special handling for optimizing swaps of TImode variables. The test case reported in bugzilla uses a call to __atomic_compare_exchange, which introduces a variable of PTImode and that does not get the same treatment as TImode leading to wrong code generation. The simple fix is to treat PTImode identically to TImode. This passed bootstrap and regtesting on powerpc64le-linux with no regressions. I also confirmed the testcase is correctly not run on -m32 BE and passes on -m64 BE. Ok for trunk? This is broken back to GCC 12, so ok for the releases branches after some bake-in time on trunk? Peter gcc/ PR target/116415 * config/rs6000/rs6000-p8swap.cc (rs6000_analyze_swaps): Handle PTImode identically to TImode. gcc/testsuite/ PR target/116415 * gcc.target/powerpc/pr116415.c: New test. diff --git a/gcc/config/rs6000/rs6000-p8swap.cc b/gcc/config/rs6000/rs6000-p8swap.cc index 639f477d782..15e44bb63a6 100644 --- a/gcc/config/rs6000/rs6000-p8swap.cc +++ b/gcc/config/rs6000/rs6000-p8swap.cc @@ -2469,10 +2469,11 @@ rs6000_analyze_swaps (function *fun) mode = V4SImode; } - if (ALTIVEC_OR_VSX_VECTOR_MODE (mode) || mode == TImode) + if (ALTIVEC_OR_VSX_VECTOR_MODE (mode) || mode == TImode + || mode == PTImode) { insn_entry[uid].is_relevant = 1; - if (mode == TImode || mode == V1TImode + if (mode == TImode || mode == PTImode || mode == V1TImode || FLOAT128_VECTOR_P (mode)) insn_entry[uid].is_128_int = 1; if (DF_REF_INSN_INFO (mention)) @@ -2497,10 +2498,11 @@ rs6000_analyze_swaps (function *fun) && ALTIVEC_OR_VSX_VECTOR_MODE (GET_MODE (SET_DEST (insn)))) mode = GET_MODE (SET_DEST (insn)); - if (ALTIVEC_OR_VSX_VECTOR_MODE (mode) || mode == TImode) + if (ALTIVEC_OR_VSX_VECTOR_MODE (mode) || mode == TImode + || mode == PTImode) { insn_entry[uid].is_relevant = 1; - if (mode == TImode || mode == V1TImode + if (mode == TImode || mode == PTImode || mode == V1TImode || FLOAT128_VECTOR_P (mode)) insn_entry[uid].is_128_int = 1; if (DF_REF_INSN_INFO (mention)) diff --git a/gcc/testsuite/gcc.target/powerpc/pr116415.c b/gcc/testsuite/gcc.target/powerpc/pr116415.c new file mode 100644 index 00000000000..5fad810ceb0 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr116415.c @@ -0,0 +1,43 @@ +/* { dg-do run } */ +/* { dg-skip-if "" { powerpc*-*-darwin* } } */ +/* { dg-require-effective-target p8vector_hw } */ +/* { dg-require-effective-target int128 } */ +/* { dg-options "-O2 -mdejagnu-cpu=power8" } */ + +/* PR 116415: Verify our Power8 swap optimization pass doesn't incorrectly swap + PTImode values. They should be handled identically to TImode values. */ + +#include +#include +#include + +typedef union { + struct { + uint64_t a; + uint64_t b; + } t; + __uint128_t data; +} Value; +Value value, next; + +void +bug (Value *val, Value *nxt) +{ + for (;;) { + nxt->t.a = val->t.a + 1; + nxt->t.b = val->t.b + 2; + if (__atomic_compare_exchange (&val->data, &val->data, &nxt->data, + 0, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE)) + break; + } +} + +int +main (void) +{ + bug (&value, &next); + printf ("%lu %lu\n", value.t.a, value.t.b); + if (value.t.a != 1 || value.t.b != 2) + abort (); + return 0; +}