From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 55BDF3858D37 for ; Wed, 30 Nov 2022 10:10:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 55BDF3858D37 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 2D96B21B11; Wed, 30 Nov 2022 10:10:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1669803010; 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=xWGrCnQhOGo6tc5l9soiJMUBO5QGVAOOwz4Ze/e+tQk=; b=HwJSPkAl6aFvbAwcdPXVvukgiKvxTJqG5WKR20jShepcwZf0VNg1XTGtMQ+XGYVv5UXyUY IF4JoPPjpSZhT5EdiOXkhHth5FoMX4uLsc40qQ+lVJHnHfzbdHbuO9n5OdFNjH+k+J9pvK 2n6hV3/7f+ECjtyUdYgfHqjYbNlYBYI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1669803010; 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=xWGrCnQhOGo6tc5l9soiJMUBO5QGVAOOwz4Ze/e+tQk=; b=9fwZH5LT5GxAiXwnRQJKxOE9J2tUuSRezEwAQ6JIkxkSjbVmyQtyzBjfz3plK+exugZYsC McYDbBs2VydybNBw== 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 0AD2E2C149; Wed, 30 Nov 2022 10:10:10 +0000 (UTC) Date: Wed, 30 Nov 2022 10:10:09 +0000 (UTC) From: Richard Biener To: Jakub Jelinek cc: Roger Sayle , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] tree-chrec: Fix up ICE on pointer multiplication [PR107835] In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="-1609957120-654823838-1669803010=:7009" X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,BODY_8BITS,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: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---1609957120-654823838-1669803010=:7009 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8BIT On Wed, 30 Nov 2022, Jakub Jelinek wrote: > Hi! > > r13-254-gdd3c7873a61019e9 added an optimization for {a, +, a} (x-1), > but as can be seen on the following testcase, the way it is written > where chrec_fold_multiply is called with type doesn't work for pointers: >              res = build_int_cst (TREE_TYPE (x), 1); >              res = chrec_fold_plus (TREE_TYPE (x), x, res); >              res = chrec_convert_rhs (type, res, NULL); >              res = chrec_fold_multiply (type, chrecr, res); > while what we were doing before and what is still used if the condition > doesn't match is fine: >              res = chrec_convert_rhs (TREE_TYPE (chrecr), x, NULL); >              res = chrec_fold_multiply (TREE_TYPE (chrecr), chrecr, res); >              res = chrec_fold_plus (type, CHREC_LEFT (chrec), res); > because it performs chrec_fold_multiply on TREE_TYPE (chrecr) and converts > only afterwards. > > I think the easiest fix is to ignore the new path for pointer types. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? OK. Thanks, Richard. > 2022-11-30 Jakub Jelinek > > PR tree-optimization/107835 > * tree-chrec.cc (chrec_apply): Don't handle "{a, +, a} (x-1)" > as "a*x" if type is a pointer type. > > * gcc.c-torture/compile/pr107835.c: New test. > > --- gcc/tree-chrec.cc.jj 2022-05-10 18:33:14.641029951 +0200 > +++ gcc/tree-chrec.cc 2022-11-29 15:24:41.810400368 +0100 > @@ -622,7 +622,8 @@ chrec_apply (unsigned var, > /* "{a, +, b} (x)" -> "a + b*x". */ > else if (operand_equal_p (CHREC_LEFT (chrec), chrecr) > && TREE_CODE (x) == PLUS_EXPR > - && integer_all_onesp (TREE_OPERAND (x, 1))) > + && integer_all_onesp (TREE_OPERAND (x, 1)) > + && !POINTER_TYPE_P (type)) > { > /* We know the number of iterations can't be negative. > So {a, +, a} (x-1) -> "a*x". */ > --- gcc/testsuite/gcc.c-torture/compile/pr107835.c.jj 2022-11-29 15:31:32.565382590 +0100 > +++ gcc/testsuite/gcc.c-torture/compile/pr107835.c 2022-11-29 15:31:15.795628304 +0100 > @@ -0,0 +1,11 @@ > +/* PR tree-optimization/107835 */ > + > +int * > +foo (void) > +{ > + int *x = 0; > + unsigned n = n; > + for (; n; --n, ++x) > + ; > + return x; > +} > > 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) ---1609957120-654823838-1669803010=:7009--