From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 0006D385086D for ; Fri, 17 Mar 2023 14:12:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0006D385086D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679062349; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sPrIAzaMwdcSuTxCBANbw1oBEIyL2Zbj3DxEmaqRbyM=; b=Co7HC7uCJ81MUIvRN0d/2ff+oJz/gkjxA5cNniKRaD3WfHkDE6z9fwcjgWkp6VncrOugdp yaga4bCosSafl6hoqyPAylJSK+LDOuXTovyQs6aa6t7yAy5dhid3+u9drP9CyTHgb3w46d DzhlT2CzaD9xtJ0YYMGO9E55u699qc0= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-125-r-40p4glP5Cu-HY5ZCen5Q-1; Fri, 17 Mar 2023 10:12:28 -0400 X-MC-Unique: r-40p4glP5Cu-HY5ZCen5Q-1 Received: by mail-qt1-f198.google.com with SMTP id x5-20020ac86b45000000b003d59e5ef484so2577659qts.15 for ; Fri, 17 Mar 2023 07:12:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679062347; 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=sPrIAzaMwdcSuTxCBANbw1oBEIyL2Zbj3DxEmaqRbyM=; b=2jX/SDrABsGZ+UtQZOsytnl5XttK66kpCMxlGQOjVms1fUCxYWtT0eRhK2wU1h6naA dmRDCsISawxn8QGVyEgKsDI/u0vdtCyMcTrFWx1IvJ5CEIOzeNyEsf19GIyZuMBuIc57 LSqw84skjDH8TotAkztMdHWhMD+/HUaZtbJFt5IDkHrfQ7sbpV2oSHFiMJvyoAicL6th xgUe3GtYz5QqaNy+psZ1VG7qi41PiG7Ss9uXzjsQz8ksLsRFF73XME6UdVmK5SbdnuHV j2B9bC+AyTtc3pPEu8Ykc4KvZ3wZ2PR/yF2A5r5ftMNIFjr0TPEkkoJ630gul+ruk8Ot hHrA== X-Gm-Message-State: AO0yUKUIU9uyzHt3Mo5p1EMn0osAQl2ARA9PAfgLseYataZroQ5f+Wq0 uoWyAo8DPUjEqwPuI29XWNqu37H7rRKzprMro23oY5gOE7EINRwpvLxLz4IY5yUhTCyHIFGOgwS 3MGTuLmJImgECtCMZu6zf+xyvUA== X-Received: by 2002:a05:6214:400d:b0:5ac:d877:43c1 with SMTP id kd13-20020a056214400d00b005acd87743c1mr22123632qvb.40.1679062347430; Fri, 17 Mar 2023 07:12:27 -0700 (PDT) X-Google-Smtp-Source: AK7set9HoQfT8ivov4hkM6VzWHYw909AeqCJ0hI91patN2B9uCJvPZQVHjs3yyWbLomtUmtl48aN1Q== X-Received: by 2002:a05:6214:400d:b0:5ac:d877:43c1 with SMTP id kd13-20020a056214400d00b005acd87743c1mr22123597qvb.40.1679062347187; Fri, 17 Mar 2023 07:12:27 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::759b? ([2607:fea8:a263:f600::759b]) by smtp.gmail.com with ESMTPSA id d185-20020a37b4c2000000b007425ef4cbc2sm1694536qkf.100.2023.03.17.07.12.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Mar 2023 07:12:26 -0700 (PDT) Message-ID: <8ee85d6d-d843-e849-cdcf-9c7f357307d7@redhat.com> Date: Fri, 17 Mar 2023 10:12:25 -0400 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. To: Richard Biener , Manolis Tsamis Cc: gcc-patches@gcc.gnu.org, Philipp Tomsich , "hernandez, aldy" References: <20230316152706.2214124-1-manolis.tsamis@vrull.eu> From: Andrew MacLeod In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,BODY_8BITS,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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/17/23 04:31, Richard Biener wrote: > On Thu, Mar 16, 2023 at 4:27 PM 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. > The downside is we now need two registers and their lifetime overlaps. > > Your patch mixes changing / inverting a parameter (which seems unneeded > for the actual change) with preferring compares against zero. > > What's the reason to specifically prefer compares against zero? On x86 > we have add that sets flags, so ++*a == 0 would be preferred, but > for your sequence we'd need a test reg, reg; branch on zero, so we do > not save any instruction. > > We do have quite some number of bugreports with regards to making VRPs > life harder when splitting things this way. It's easier for VRP to handle > > _1 = _2 + 1; > if (_1 == 1) > > than it is > > _1 = _2 + 1; > if (_2 == 0) > > where VRP fails to derive a range for _1 on the _2 == 0 branch. So besides Heh?     _1 = *a_5(D);     b_6 = _1 + 1;     if (_1 == 0)       goto ; [INV]     else       goto ; [INV] 2->3  (T) _1 :  [irange] unsigned int [0, 0] NONZERO 0x0 2->3  (T) b_6 :         [irange] unsigned int [1, 1] NONZERO 0x1 2->4  (F) _1 :  [irange] unsigned int [1, +INF] 2->4  (F) b_6 :         [irange] unsigned int [0, 0][2, +INF] I will grant you that if the definition of b_6 is in a different basic block that if (_1 == 0) we may not always get a range for it,  but generally this should be OK?  especialyl within a basic block. I do have a few re-computation cases to improve upon of course :-P Andrew