From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id BA27C3858D1E for ; Thu, 22 Dec 2022 11:33:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BA27C3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 6ACCB239C2; Thu, 22 Dec 2022 11:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1671708806; h=from:from:reply-to: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=+iN8XMSsn6eFJk7NZrosOiQkXWQlOTyEnm2JeUpoIvo=; b=S3zbJIHkseh+n6Du79F+9r3/iriOHGglmmqe8NaVHTtM88gRyO2rhVE1i4PcEb8NJtBb3s vgr0XNRgAKoinz/hgpYlqOPyJS2vxUPozgp6RHiSTP/PJj9MAovTxWsLi23bR2TOPn65L3 vTXXUfm38gZZcPXjFjd8aMhRpcVB090= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1671708806; h=from:from:reply-to: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=+iN8XMSsn6eFJk7NZrosOiQkXWQlOTyEnm2JeUpoIvo=; b=J6pdrgouDApe/LgH8zLfTY7VI/LJbbdybCOH3V204mohm3QH9qf8rMy5Op6dFuOmTaS9GW o19wMsRAvEQ8jJAw== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 7C4E72C141; Thu, 22 Dec 2022 11:33:25 +0000 (UTC) Date: Thu, 22 Dec 2022 11:33:25 +0000 (UTC) From: Richard Biener To: Jakub Jelinek cc: gcc-patches@gcc.gnu.org, Aldy Hernandez , Andrew MacLeod Subject: Re: [PATCH] phiopt: Drop SSA_NAME_RANGE_INFO in maybe equal case [PR108166] In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 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 INTEGER_CST singleton and union that into the SSA_NAMEs range and then do set_range_info with the altered range I guess. 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)