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 6F9823858D1E for ; Thu, 22 Dec 2022 12:09:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6F9823858D1E 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=1671710974; 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: in-reply-to:in-reply-to:references:references; bh=pAe6J01dOx1c6ot1RJFL4IWPnpU2QKIEeEu5chiaxPk=; b=h6Cmj5mANoDDy6wQjxMnW9YwmtXl+bE/qAbb2UAzKlOwTP+/MRpo+DTYa6id0CJzV3cnI3 H7wjqzsZkFJCkHClZ4o+1W1fzV70SZfXFGK9u3HGjAUTcXiN6qVCBJkHk1MP5hwdzg15mN //BChKfBgKHMIV6O0fjALODh7CHKUXs= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-367-ChN6pDe8PD657JTvTPnjiw-1; Thu, 22 Dec 2022 07:09:32 -0500 X-MC-Unique: ChN6pDe8PD657JTvTPnjiw-1 Received: by mail-ed1-f71.google.com with SMTP id w20-20020a056402269400b004700a51c202so1407691edd.13 for ; Thu, 22 Dec 2022 04:09:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pAe6J01dOx1c6ot1RJFL4IWPnpU2QKIEeEu5chiaxPk=; b=bEkLw+ilVMUr6Z71P0wl5Z6/J6uMEBynSC8L9SwfoXzr8RGA6WP84Jq4AlAU7OfKqA E871p3XT//6P3xhMh7SOb7mskQkGb9W0PMznyPTG88YleHwJ8+ZpEAHBW/aPIZVFNzgh gQggXqTlPF+9IjSxkTXRYfWLiORTuCu+IEJJGmEfK5e8eRikmepz6ql7oyE/2dHOazq6 Nz6MRaxBMXwpD7o58svJ99zpoO3vyxq6YgeemoIJGRldUUN4HOEYFe/k6qeNvNvtlOGa 5xlQ4e6bwNZaIUQ1kc0xTvREvTB88+KfqrcNTO3Ng6Ojkovf+vbT+LRX6NRyNVtvAPkk 3d2Q== X-Gm-Message-State: AFqh2krtud6Mchw25vvmACHLcVtwIFeLHHQehzaEEUA2PdQrew2YpPog R4q/4KkV9FvC9knU5pQI5WAQ1qTiyxqRiHyzqhV6dF4owbFObuvus+ODk1NnLvZC53u8MMBcpO+ dOMwswCfvbzCXFUGlt6Dzi9OwFMtYhVwkzw== X-Received: by 2002:a50:eb08:0:b0:46c:97e9:476d with SMTP id y8-20020a50eb08000000b0046c97e9476dmr454127edp.389.1671710971369; Thu, 22 Dec 2022 04:09:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXuMO5JrKbEKBGRrikNx8fD7S5lxB7q7p8wRlTN1GU6Bv1FSwOFl7IQ+m2B8Lc1c8AV3a0t3C+b0tD1RUL19tbY= X-Received: by 2002:a50:eb08:0:b0:46c:97e9:476d with SMTP id y8-20020a50eb08000000b0046c97e9476dmr454125edp.389.1671710971147; Thu, 22 Dec 2022 04:09:31 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Aldy Hernandez Date: Thu, 22 Dec 2022 13:09:21 +0100 Message-ID: Subject: Re: [PATCH] phiopt: Drop SSA_NAME_RANGE_INFO in maybe equal case [PR108166] To: Richard Biener Cc: Jakub Jelinek , gcc-patches , Andrew MacLeod X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="0000000000009a4d5105f0698af6" X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,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: --0000000000009a4d5105f0698af6 Content-Type: text/plain; charset="UTF-8" On Thu, Dec 22, 2022, 12:33 Richard Biener wrote: > On Thu, 22 Dec 2022, Jakub Jelinek wrote: > > > Hi! > > > > The following place in value_replacement is after proving that > > x == cst1 ? cst2 : x > > phi result is only used in a comparison with constant which doesn't > > care if it compares cst1 or cst2 and replaces it with x. > > The testcase is miscompiled because we have after the replacement > > incorrect range info for the phi result, we would need to > > effectively union the phi result range with cst1 (oarg in the code) > > because previously that constant might be missing in the range, but > > newly it can appear (we've just verified that the single use stmt > > of the phi result doesn't care about that value in particular). > > > > The following patch just resets the info, bootstrapped/regtested > > on x86_64-linux and i686-linux, ok for trunk? > > OK. > > > Aldy/Andrew, how would one instead union the SSA_NAME_RANGE_INFO > > with some INTEGER_CST and store it back into SSA_NAME_RANGE_INFO > > (including adjusting non-zero bits and the like)? > > There's no get_range_info on SSA_NAMEs (anymore?) but you can > construct a value_range from the This is my fault. When we added get_global_range_query, I removed get_range_info. I should've left that entry point. I'll look into adding it next cycle for readability's sake INTEGER_CST singleton and > union that into the SSA_NAMEs range and then do set_range_info > with the altered range I guess. > Note that set_range_info is an intersect operation. It should really be called update_range_info. Up to now, there were no users that wanted to clobber old ranges completely. Aldy > Richard. > > > 2022-12-22 Jakub Jelinek > > > > PR tree-optimization/108166 > > * tree-ssa-phiopt.cc (value_replacement): For the maybe_equal_p > > case turned into equal_p reset SSA_NAME_RANGE_INFO of phi result. > > > > * g++.dg/torture/pr108166.C: New test. > > > > --- gcc/tree-ssa-phiopt.cc.jj 2022-10-28 11:00:53.970243821 +0200 > > +++ gcc/tree-ssa-phiopt.cc 2022-12-21 14:27:58.118326548 +0100 > > @@ -1491,6 +1491,12 @@ value_replacement (basic_block cond_bb, > > default: > > break; > > } > > + if (equal_p) > > + /* After the optimization PHI result can have value > > + which it couldn't have previously. > > + We could instead of resetting it union the range > > + info with oarg. */ > > + reset_flow_sensitive_info (gimple_phi_result (phi)); > > if (equal_p && MAY_HAVE_DEBUG_BIND_STMTS) > > { > > imm_use_iterator imm_iter; > > --- gcc/testsuite/g++.dg/torture/pr108166.C.jj 2022-12-21 > 14:31:02.638661322 +0100 > > +++ gcc/testsuite/g++.dg/torture/pr108166.C 2022-12-21 > 14:30:45.441909725 +0100 > > @@ -0,0 +1,26 @@ > > +// PR tree-optimization/108166 > > +// { dg-do run } > > + > > +bool a, b; > > +int d, c; > > + > > +const int & > > +foo (const int &f, const int &g) > > +{ > > + return !f ? f : g; > > +} > > + > > +__attribute__((noipa)) void > > +bar (int) > > +{ > > +} > > + > > +int > > +main () > > +{ > > + c = foo (b, 0) > ((b ? d : b) ?: 8); > > + a = b ? d : b; > > + bar (a); > > + if (a != 0) > > + __builtin_abort (); > > +} > > > > Jakub > > > > > > -- > Richard Biener > SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, > Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; > HRB 36809 (AG Nuernberg) > > --0000000000009a4d5105f0698af6--