From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by sourceware.org (Postfix) with ESMTPS id 046C33858D35 for ; Thu, 16 Mar 2023 16:41:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 046C33858D35 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-pj1-x102b.google.com with SMTP id e15-20020a17090ac20f00b0023d1b009f52so5996882pjt.2 for ; Thu, 16 Mar 2023 09:41:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678984865; 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:message-id:reply-to; bh=8HOR1fW7JbfAWP1j7/2KiuW2BEG+kGMysuJJXsY5BS4=; b=F+fp47gLbulSk0f1YU6HIk5skJ/MtbJsuZKNM4Rwbcpfi7fILcWJFwI7kAykP8najA BiP43IAEdl7u6ARUDxywkVLFo1P3FF26Wjt+zh2nrizABQcumVv6PHDI9hBRfCSsf1fL +egRufYwm00tf1E5fmVT91yP80qEQSi2ss6bfSQ3wlqoIPasgtQby4siMp8NVE3mOeC6 LogQ9OynS5aIoFZ5N+BKcfD1VwmmRuWQsQbXRsIdp4UGpqjIOyVV+SRCPRNHdPGDRVtv D5aKlTTv+QKkSIHkOF72UobGe9peYwpwBKIGuiCa/92WSA8gpLmx4BbBtDX3XFFm5vg1 bKxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678984865; 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:message-id:reply-to; bh=8HOR1fW7JbfAWP1j7/2KiuW2BEG+kGMysuJJXsY5BS4=; b=Qu/J9HFRHIMa+JllHsdAU5XyJwldbwO14e1KsupNIU22mG697/mPsSaxVgMqc4FwfR ab0ylUmkMXcHbO+7jbKn2weiFc+47GKoN+1LJdaU3KddPYvqlkbsVlhGanRDHHglmcoZ zFaeas/A/Rf/fHD5a63u7UQ8UwlRm/14smwcaLiS/ww6HujisbZPjxXD4nJXJqc3tJjx oZleZBFzbRSEbV7Emb9qiSOwxXVcq+vQMkrWbUYSq1QPN9erTb8hEbfclzeVV1N0p6Rm k6dMh+AVFU73Rjj4+PHDcog0wuLmAQA7RHowKNxwfmA2QJ0HcwxOQ4LodTfuLxQERsYU pJQw== X-Gm-Message-State: AO0yUKWfTryZkeFgZY9x6ZJHdXkQe7RWcoUvfQ+xYb9ZY81RR30wWvJm B2Y3qNNeecwQMEoLl1RkxDs= X-Google-Smtp-Source: AK7set8+7t5gSxA8yCVq5Jfa7pFPXVsMZO49S8qqtj/RLr1CqVnT3wZC3W5t+iPxOXvqpAP5zdpo7A== X-Received: by 2002:a17:90b:1645:b0:23d:1b50:1eca with SMTP id il5-20020a17090b164500b0023d1b501ecamr4494046pjb.18.1678984864726; Thu, 16 Mar 2023 09:41:04 -0700 (PDT) Received: from ?IPV6:2601:681:8600:13d0::f0a? ([2601:681:8600:13d0::f0a]) by smtp.gmail.com with ESMTPSA id 17-20020a170902c15100b0019cbe436b87sm1734072plj.81.2023.03.16.09.41.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Mar 2023 09:41:04 -0700 (PDT) Message-ID: Date: Thu, 16 Mar 2023 10:41:03 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH v1] [RFC] Improve folding for comparisons with zero in tree-ssa-forwprop. Content-Language: en-US To: Manolis Tsamis , gcc-patches@gcc.gnu.org Cc: Philipp Tomsich , Richard Biener References: <20230316152706.2214124-1-manolis.tsamis@vrull.eu> From: Jeff Law In-Reply-To: <20230316152706.2214124-1-manolis.tsamis@vrull.eu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.4 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 3/16/23 09:27, Manolis Tsamis wrote: > For this C testcase: > > void g(); > void f(unsigned int *a) > { > if (++*a == 1) > g(); > } > > GCC will currently emit a comparison with 1 by using the value > of *a after the increment. This can be improved by comparing > against 0 and using the value before the increment. As a result > there is a potentially shorter dependancy chain (no need to wait > for the result of +1) and on targets with compare zero instructions > the generated code is one instruction shorter. > > Example from Aarch64: > > Before > ldr w1, [x0] > add w1, w1, 1 > str w1, [x0] > cmp w1, 1 > beq .L4 > ret > > After > ldr w1, [x0] > add w2, w1, 1 > str w2, [x0] > cbz w1, .L4 > ret > > gcc/ChangeLog: > > * tree-ssa-forwprop.cc (combine_cond_expr_cond): > (forward_propagate_into_comparison_1): Optimize > for zero comparisons. Deferring to gcc-14. Though I'm generally supportive of normalizing to a comparison against zero when we safely can :-) jeff