From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 550073858D28 for ; Tue, 5 Sep 2023 21:41:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 550073858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-68a3e271491so1725733b3a.0 for ; Tue, 05 Sep 2023 14:41:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693950116; x=1694554916; darn=gcc.gnu.org; h=subject:to:from:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=RqJ1BRITpD58QO+hPn41qETOoQJ2ESBceaNe4VtAf/Y=; b=RS9OjGZtbWxPZ7+LDRxHqATA2jvPFxELEl7m+rXUl76T1hWsgIIHwaQY9TmV27nodP b7vvTWaLNsROdAyI79EhDWm5uOmATXMEUG+bY/8gMC2O52cuEuMVHb0qmVT44h4ZQcyd LhHsQRLci6O8+yOrgCTi+006iVeuh6XFxP1rXcYQw34nJfap2uPxMFzpv35yAYyYF8bA wKpymhag4o8i+hDLTPyLRw6CSNmJ3Ffe3kNr/GAhb3jkOSGyONtmPgAtRo/dbnJ9CiQJ UWNr2NC9SNP0YZ7UBnrgEX1t+505wifScoCr12QBCwUVjapBsX51IzdaLeGaABh43DTz 7HTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693950116; x=1694554916; h=subject:to:from:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RqJ1BRITpD58QO+hPn41qETOoQJ2ESBceaNe4VtAf/Y=; b=I52FD7gm9nxQchML1N7lked6qak9cxov81/gBN3To0nJDXlQwaiYVyjIbs4WPoqFSc D5LTCGsAlpxUuJyj/8QWs3d5hO9+9vnvaEUe99+oJQ4vFVV3mzNb832pmKaZLOUEM/xP WB2oRGUQPKnhWotKo2foyenGi3+hOlkJnuKfDh6xpr7xQOv215ZKjGz+uta4fJVUxq17 /exodiW8D1UhnJ1V4VYr9CmLS7XLKeCIa0BsZPJgrRGKH/NeuGDpkrIR1Ol4zXFxrMNM rn38UvHBPmDqJMJfVPiE2h8yhHiyet1ADZVRpVWx+95XGFu34UpXBrG2LsRmICI/gFhz 8koQ== X-Gm-Message-State: AOJu0Yw2pjqAg6Hn/0wFDlM/hlmsiLWF3jZmfV/lyAHZ+l2NFebs3MQx yPG27GW89LLJtv1tNFGqVskkqJrJ/SwpMA== X-Google-Smtp-Source: AGHT+IFQ5JKnKlKJRAwfdeDubYNQ3EprKACZxIlETNOxuC4JvWLgZGzgzVL3Ep4gf3WIddRBT2THYA== X-Received: by 2002:a05:6a20:939c:b0:144:2ea8:1a92 with SMTP id x28-20020a056a20939c00b001442ea81a92mr14961029pzh.12.1693950115711; Tue, 05 Sep 2023 14:41:55 -0700 (PDT) Received: from [172.31.0.109] ([136.36.130.248]) by smtp.gmail.com with ESMTPSA id v1-20020aa78501000000b0068703879d3esm9480041pfn.113.2023.09.05.14.41.53 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Sep 2023 14:41:55 -0700 (PDT) Content-Type: multipart/mixed; boundary="------------6AbrAC4vNRUJzZWV00Vvyp5w" Message-ID: <8a7a28fa-db2d-436a-80bb-ab4a290c746b@gmail.com> Date: Tue, 5 Sep 2023 15:41:50 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Jeff Law To: "gcc-patches@gcc.gnu.org" Subject: [committed] RISC-V: Expose bswapsi for TARGET_64BIT X-Spam-Status: No, score=-8.4 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This is a multi-part message in MIME format. --------------6AbrAC4vNRUJzZWV00Vvyp5w Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Various bswapsi tests are failing for rv64. More importantly, we're generating crappy code. Let's take the first test from bswapsi-1.c as an example. > typedef unsigned int uint32_t; > > #define __const_swab32(x) ((uint32_t)( \ > (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \ > (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \ > (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \ > (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24))) > > /* This byte swap implementation is used by the Linux kernel and the > GNU C library. */ > > uint32_t > swap32_a (uint32_t in) > { > return __const_swab32 (in); > } > > > We generate this for rv64gc_zba_zbb_zbs: > srliw a1,a0,24 > slliw a5,a0,24 > slliw a3,a0,8 > li a2,16711680 > li a4,65536 > or a5,a5,a1 > and a3,a3,a2 > addi a4,a4,-256 > srliw a0,a0,8 > or a5,a5,a3 > and a0,a0,a4 > or a0,a5,a0 > ret Urgh! After this patch we generate: > rev8 a0,a0 > srai a0,a0,32 > ret Clearly better. The stated rationale behind not exposing bswapsi2 for TARGET_64BIT is that the RTL expanders already know how to widen a bswap, which is definitely true. But it's the case that failure to expose a bswapsi will cause the 32bit bswap optimizations in gimple store merging to not trigger. Thus we get crappy code. To fix this we expose bswapsi on TARGET_64BIT. gimple-store-merging then detects the 32bit bswap idioms and generates suitable __builtin calls. The expander will "FAIL" expansion for TARGET_64BIT which forces the generic expander code to synthesize the operation (we could synthesize in here, but that'd result in duplicate code). Tested on rv64gc_zba_zbb_zbs, fixes all the bswapsi failures in the testsuite without any regressions. Pushed to the trunk, Jeff --------------6AbrAC4vNRUJzZWV00Vvyp5w Content-Type: text/plain; charset=UTF-8; name="P" Content-Disposition: attachment; filename="P" Content-Transfer-Encoding: base64 Y29tbWl0IGZiYzAxNzQ4YmE0NmViMjYwNzQzODhhOGZiN2I0NGQyNWE0MTRhNzIKQXV0aG9y OiBKZWZmIExhdyA8amxhd0B2ZW50YW5hbWljcm8uY29tPgpEYXRlOiAgIFR1ZSBTZXAgNSAx NTozOToxNiAyMDIzIC0wNjAwCgogICAgUklTQy1WOiBFeHBvc2UgYnN3YXBzaSBmb3IgVEFS R0VUXzY0QklUCiAgICAKICAgIFZhcmlvdXMgYnN3YXBzaSB0ZXN0cyBhcmUgZmFpbGluZyBm b3IgcnY2NC4gIE1vcmUgaW1wb3J0YW50bHksIHdlJ3JlIGdlbmVyYXRpbmcKICAgIGNyYXBw eSBjb2RlLgogICAgCiAgICBMZXQncyB0YWtlIHRoZSBmaXJzdCB0ZXN0IGZyb20gYnN3YXBz aS0xLmMgYXMgYW4gZXhhbXBsZS4KICAgIAogICAgPiB0eXBlZGVmIHVuc2lnbmVkIGludCB1 aW50MzJfdDsKICAgID4KICAgID4gI2RlZmluZSBfX2NvbnN0X3N3YWIzMih4KSAoKHVpbnQz Ml90KSggICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgID4gICAgICAgICAo KCh1aW50MzJfdCkoeCkgJiAodWludDMyX3QpMHgwMDAwMDBmZlVMKSA8PCAyNCkgfCAgICAg ICAgICAgIFwKICAgID4gICAgICAgICAoKCh1aW50MzJfdCkoeCkgJiAodWludDMyX3QpMHgw MDAwZmYwMFVMKSA8PCAgOCkgfCAgICAgICAgICAgIFwKICAgID4gICAgICAgICAoKCh1aW50 MzJfdCkoeCkgJiAodWludDMyX3QpMHgwMGZmMDAwMFVMKSA+PiAgOCkgfCAgICAgICAgICAg IFwKICAgID4gICAgICAgICAoKCh1aW50MzJfdCkoeCkgJiAodWludDMyX3QpMHhmZjAwMDAw MFVMKSA+PiAyNCkpKQogICAgPgogICAgPiAvKiBUaGlzIGJ5dGUgc3dhcCBpbXBsZW1lbnRh dGlvbiBpcyB1c2VkIGJ5IHRoZSBMaW51eCBrZXJuZWwgYW5kIHRoZQogICAgPiAgICBHTlUg QyBsaWJyYXJ5LiAgKi8KICAgID4KICAgID4gdWludDMyX3QKICAgID4gc3dhcDMyX2EgKHVp bnQzMl90IGluKQogICAgPiB7CiAgICA+ICAgcmV0dXJuIF9fY29uc3Rfc3dhYjMyIChpbik7 CiAgICA+IH0KICAgID4KICAgID4KICAgID4KICAgIAogICAgV2UgZ2VuZXJhdGUgdGhpcyBm b3IgcnY2NGdjX3piYV96YmJfemJzOgogICAgCiAgICA+ICAgICAgICAgc3JsaXcgICBhMSxh MCwyNAogICAgPiAgICAgICAgIHNsbGl3ICAgYTUsYTAsMjQKICAgID4gICAgICAgICBzbGxp dyAgIGEzLGEwLDgKICAgID4gICAgICAgICBsaSAgICAgIGEyLDE2NzExNjgwCiAgICA+ICAg ICAgICAgbGkgICAgICBhNCw2NTUzNgogICAgPiAgICAgICAgIG9yICAgICAgYTUsYTUsYTEK ICAgID4gICAgICAgICBhbmQgICAgIGEzLGEzLGEyCiAgICA+ICAgICAgICAgYWRkaSAgICBh NCxhNCwtMjU2CiAgICA+ICAgICAgICAgc3JsaXcgICBhMCxhMCw4CiAgICA+ICAgICAgICAg b3IgICAgICBhNSxhNSxhMwogICAgPiAgICAgICAgIGFuZCAgICAgYTAsYTAsYTQKICAgID4g ICAgICAgICBvciAgICAgIGEwLGE1LGEwCiAgICA+ICAgICAgICAgcmV0VXJnaCEKICAgIAog ICAgQWZ0ZXIgdGhpcyBwYXRjaCB3ZSBnZW5lcmF0ZToKICAgIAogICAgPiAgICAgICAgIHJl djggICAgYTAsYTAKICAgID4gICAgICAgICBzcmFpICAgIGEwLGEwLDMyCiAgICA+ICAgICAg ICAgcmV0CiAgICBDbGVhcmx5IGJldHRlci4KICAgIAogIC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