From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by sourceware.org (Postfix) with ESMTPS id 7C9A63858016 for ; Wed, 28 Sep 2022 17:25:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7C9A63858016 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-io1-xd31.google.com with SMTP id z191so10686656iof.10 for ; Wed, 28 Sep 2022 10:25:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date; bh=uNNaLh1yLPrEwPkHd6vxIgR+d3FE15nAap4o1BcfN/E=; b=LHH4fEL84l+qoxY4p4apa80R8kVbz+6TeTupk3/BjQiy25K51m3uVHz1xnQPEkF2LQ W0ZM+Jnouoazf8iXslFyYte8efoFz/t4QP7Deq0caZWVUqqMlZ00khQwl5kYgtvnDH8n PEX8SX3c5qqjkfvzYQRfRQdzufK2U6O8lI/hMF1cAkqulTp0a3Fr19IS8dUucxu4IvpH fVirY/L3fN66PqRZ9OSExUiizihm+EDRU+JQtip7b+P7fgCM+2woiZq76iFOLGOaCtNi vKBHFTX27m0qug4tMQbDl2PYhB9SQjahydvZRYRYokjMMdaW77StWmShmYixwOashrUz 4DzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=uNNaLh1yLPrEwPkHd6vxIgR+d3FE15nAap4o1BcfN/E=; b=1BlRwoHSW5TljCPGeASWgMoZ6FpCq48G+rqSrpHvrNBuqcbdOuwFVwa66GwVpKAlRU 2xZfm/mYq3sSZDdJAJmlHJnJ6BL1jwYuge5a5aq7ErVF6vQHWd1cCCHEcU+rwknEFE5f lZrcaRShZKr1WWnLJG6oppCwcnFtgf8ZgE/ixU/L8H4xTb3cdkVnTahgUlc3j0yAiBJz yeOmpdd66D0pP/uU0cqQTMQYeM6YKBCkMdVdSsRM3ybcNqK9EZHfI9lWVz0mI6ckFzFV TJ96kMmeGo2uZifbyTGRUHVcQVDaIm2Nma6ijSvHLfPnWrxkiiAh3QxokECcxxO9Uekh vbFg== X-Gm-Message-State: ACrzQf1D2LqZqHeS/6mR/zGe75O1absCTJLqCHIB8Qb8kSV1GiXvEGUH 7i4JNixoPKPbUjItndj1hyU= X-Google-Smtp-Source: AMsMyM4pterliEfbn3x5EhtTvkIbfpMBY72fhdqtyzP6ozg4pN3uRw3KwG9izT0bOkGCw7hnauc3MA== X-Received: by 2002:a05:6638:24c8:b0:35a:41e1:856b with SMTP id y8-20020a05663824c800b0035a41e1856bmr17979411jat.99.1664385937608; Wed, 28 Sep 2022 10:25:37 -0700 (PDT) Received: from [192.168.0.58] (65-130-23-164.slkc.qwest.net. [65.130.23.164]) by smtp.gmail.com with ESMTPSA id f9-20020a92b509000000b002e949936411sm867415ile.26.2022.09.28.10.25.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Sep 2022 10:25:36 -0700 (PDT) Message-ID: <208d1b9e-7222-23c6-e83a-0741c2445d4c@gmail.com> Date: Wed, 28 Sep 2022 11:25:35 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: [PATCH 1/2]middle-end Fold BIT_FIELD_REF and Shifts into BIT_FIELD_REFs alone Content-Language: en-US To: Tamar Christina , "gcc-patches@gcc.gnu.org" Cc: nd , "rguenther@suse.de" References: <094ad28e-ac7f-686c-2e1c-6dc21a129173@gmail.com> From: Jeff Law In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A,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: On 9/28/22 07:19, Tamar Christina wrote: >> -----Original Message----- >> From: Jeff Law >> Sent: Saturday, September 24, 2022 8:38 PM >> To: Tamar Christina ; gcc-patches@gcc.gnu.org >> Cc: nd ; rguenther@suse.de >> Subject: Re: [PATCH 1/2]middle-end Fold BIT_FIELD_REF and Shifts into >> BIT_FIELD_REFs alone >> >> >> On 9/23/22 05:42, Tamar Christina wrote: >>> Hi All, >>> >>> This adds a match.pd rule that can fold right shifts and >>> bit_field_refs of integers into just a bit_field_ref by adjusting the >>> offset and the size of the extract and adds an extend to the previous size. >>> >>> Concretely turns: >>> >>> #include >>> >>> unsigned int foor (uint32x4_t x) >>> { >>> return x[1] >> 16; >>> } >>> >>> which used to generate: >>> >>> _1 = BIT_FIELD_REF ; >>> _3 = _1 >> 16; >>> >>> into >>> >>> _4 = BIT_FIELD_REF ; >>> _2 = (unsigned int) _4; >>> >>> I currently limit the rewrite to only doing it if the resulting >>> extract is in a mode the target supports. i.e. it won't rewrite it to >>> extract say 13-bits because I worry that for targets that won't have a >>> bitfield extract instruction this may be a de-optimization. >>> >>> Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu >>> and no issues. >>> >>> Testcase are added in patch 2/2. >>> >>> Ok for master? >>> >>> Thanks, >>> Tamar >>> >>> gcc/ChangeLog: >>> >>> * match.pd: Add bitfield and shift folding. >> Were you planning to handle left shifts as well?  It looks like it since you've >> got iterations for the shift opcode and corresponding adjustment to the field, >> but they currently only handle rshift/plus. >> > Hmm do left shifts work here? Since a left shift would increase the size of the > resulting value by adding zeros to the end of the number, so you can't increase > the size of the bitfield to do the same. Dunno, I hadn't really thought about it.  It just looked like you were prepared to handle more cases with those iterators. > > I did however realize that truncating casts have the same effect as a right shift, > so I have added that now. ACK. jeff