From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 72790 invoked by alias); 17 Jul 2017 20:50:28 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 72054 invoked by uid 89); 17 Jul 2017 20:50:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:949 X-HELO: smtp.ispras.ru Received: from bran.ispras.ru (HELO smtp.ispras.ru) (83.149.199.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 17 Jul 2017 20:50:25 +0000 Received: from monopod.intra.ispras.ru (monopod.intra.ispras.ru [10.10.3.121]) by smtp.ispras.ru (Postfix) with ESMTP id 0D0615FB48; Mon, 17 Jul 2017 23:50:23 +0300 (MSK) Date: Mon, 17 Jul 2017 20:50:00 -0000 From: Alexander Monakov To: Marc Glisse cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] match.pd: reassociate multiplications with constants In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20.13 (LNX 116 2015-12-14) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-SW-Source: 2017-07/txt/msg01005.txt.bz2 On Mon, 17 Jul 2017, Marc Glisse wrote: > > +/* Combine successive multiplications. Similar to above, but handling > > + overflow is different. */ > > +(simplify > > + (mult (mult @0 INTEGER_CST@1) INTEGER_CST@2) > > + (with { > > + bool overflow_p; > > + wide_int mul = wi::mul (@1, @2, TYPE_SIGN (type), &overflow_p); > > + } > > + (if (!overflow_p || TYPE_OVERFLOW_WRAPS (type)) > > I wonder if there are cases where this would cause trouble for saturating > integers. The only case I can think of is when @2 is -1, but that's likely > simplified to NEGATE_EXPR first. Ah, yes, I think if @2 is -1 or 0 then we should not attempt this transform for either saturating or sanitized types, just like in the first patch. I think wrapping the 'with' with 'if (!integer_minus_onep (@2) && !integer_zerop (@2))' works, since as you say it should become a negate/zero anyway? Alexander