From patchwork Thu May 19 14:15:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 1633274 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=l3fScNK3; dkim-atps=neutral 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+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.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 (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L3sYQ26tJz9s0w for ; Fri, 20 May 2022 00:24:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 55303385734D for ; Thu, 19 May 2022 14:24:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 55303385734D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652970248; bh=Jyfmg5tuqCIwOEuNTV6obKVz1mzL0I2/F5CwlkX1QoU=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=l3fScNK3PmT7CR++JAVSv3XJX6/GEs68WbIzY2yHqo3OJV4IX8jtOCNMGOgVUZ0xe C6IBXUTOasjjJAtsZCbgnqcmyU80KyL7xcrEPqDtE8LIC1r2DFgPhrzpn1abcR25vS UTtkaur6PpPddrmcsBljWXAu02k6Tz07XOksE7Cc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 84BCC383D830 for ; Thu, 19 May 2022 14:16:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 84BCC383D830 Received: by mail-wr1-x434.google.com with SMTP id r30so7355840wra.13 for ; Thu, 19 May 2022 07:16:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=Jyfmg5tuqCIwOEuNTV6obKVz1mzL0I2/F5CwlkX1QoU=; b=a8IQyb9NDimRk6PRblh4tLFeOwOempfFxAvPI211A7ALekDQRkCAwj/U2uRptDRhxR KiM21nmtJ5GqPH/AwQKWSaVZLpOhKk6IvhQMEXFyrMnOBUo+8lsV/LijoeGYu2+PW+k3 ItS1pZ3IxryjdxE4GinJlf7U0HjWbFsyR3EWpCUmylW0G+JmL78lFPV1NGzZlXs42/jN 6cQytoUQ/9gGIHim/a3kunBhvVhMmb/WWATwbr/IIkGCdFHMfO3RHx3I2souZgpaZWth uDv0TJgnH1KSbwIwLw9jEGjSDryiQrqDd4GaEN03kzCWjdCnImacKN5I33vOauQuCUhZ 3SNA== X-Gm-Message-State: AOAM533Bmn5BuFzqs7sxcZajANQaucKdPHEf8RHJ4HBgUe2hafxmJomX /7JSYUpc7Kld4dPRyDfnckp0uWqZQWY1rg== X-Google-Smtp-Source: ABdhPJxCEguqUhUH0BDuCrjV/zaIPcRFae0ynxiafKdEuqweBSYx6SA3ni2C6tragqtOjzqChmCNxg== X-Received: by 2002:a5d:4cd0:0:b0:20d:5f6:8383 with SMTP id c16-20020a5d4cd0000000b0020d05f68383mr4182249wrt.149.1652969759279; Thu, 19 May 2022 07:15:59 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id g14-20020adfbc8e000000b0020e66dbb9dbsm3201747wrh.81.2022.05.19.07.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 May 2022 07:15:58 -0700 (PDT) Date: Thu, 19 May 2022 14:15:58 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Improve optimization of "=" on bit-packed arrays Message-ID: <20220519141558.GA3723142@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Bob Duff Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch fixes a performance regression, introduced by a previous bug fix. That fix had the unintended side effect of removing the optimization in cases where the two operands are of two different compiler-generated modular types. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_pakd.adb (Expand_Packed_Eq): Replace the check for *same* modular type, with a check for any modular type, and assert that the two types have the same modulus and so on. * exp_pakd.ads: Minor comment improvements. diff --git a/gcc/ada/exp_pakd.adb b/gcc/ada/exp_pakd.adb --- a/gcc/ada/exp_pakd.adb +++ b/gcc/ada/exp_pakd.adb @@ -1930,9 +1930,17 @@ package body Exp_Pakd is -- modular case we guarantee that the unused bits are always zeroes. -- We do have to compare the lengths because we could be comparing -- two different subtypes of the same base type. We can only do this - -- if the PATs on both sides are the same. + -- if the PATs on both sides are modular (in which case they are + -- necessarily structurally the same -- same Modulus and so on); + -- otherwise, we have a case where the right operand is not of + -- compile time known size. + + if Is_Modular_Integer_Type (PAT) + and then Is_Modular_Integer_Type (Etype (R)) + then + pragma Assert (RM_Size (Etype (R)) = RM_Size (PAT)); + pragma Assert (Modulus (Etype (R)) = Modulus (PAT)); - if Is_Modular_Integer_Type (PAT) and then PAT = Etype (R) then Rewrite (N, Make_And_Then (Loc, Left_Opnd => diff --git a/gcc/ada/exp_pakd.ads b/gcc/ada/exp_pakd.ads --- a/gcc/ada/exp_pakd.ads +++ b/gcc/ada/exp_pakd.ads @@ -41,7 +41,8 @@ package Exp_Pakd is -- This packed array type has the name xxxPn, where xxx is the name -- of the packed type, and n is the component size. The expanded - -- declaration declares a type that is one of the following: + -- declaration declares a type that is one of the following (sizes + -- below are in bytes): -- For an unconstrained array with component size 1,2,4 or any other -- odd component size. These are the cases in which we do not need @@ -49,10 +50,10 @@ package Exp_Pakd is -- type xxxPn is new Packed_Bytes1; - -- For an unconstrained array with component size that is divisible - -- by 2, but not divisible by 4 (other than 2 itself). These are the - -- cases in which we can generate better code if the underlying array - -- is 2-byte aligned (see System.Pack_14 in file s-pack14 for example). + -- For an unconstrained array with component size greater than 2, that is + -- divisible by 2, but not divisible by 4. These are the cases in which + -- we can generate better code if the underlying array is 2-byte aligned + -- (see System.Pack_14 in file s-pack14 for example). -- type xxxPn is new Packed_Bytes2; @@ -942,7 +943,7 @@ package Exp_Pakd is -- N is an N_Op_Eq node where the operands are packed arrays whose -- representation is an array-of-bytes type (the case where a modular -- type is used for the representation does not require any special - -- handling, because in the modular case, unused bits are zeroes. + -- handling, because in the modular case, unused bits are zeroes). procedure Expand_Packed_Not (N : Node_Id); -- N is an N_Op_Not node where the operand is packed array of Boolean