From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 106850 invoked by alias); 27 Jan 2017 09:03:04 -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 106832 invoked by uid 89); 27 Jan 2017 09:03:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=H*RU:sk:mail2-r, H*MI:sk:dbf04e1, glance, H*f:sk:dbf04e1 X-HELO: mail2-relais-roc.national.inria.fr Received: from mail2-relais-roc.national.inria.fr (HELO mail2-relais-roc.national.inria.fr) (192.134.164.83) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 27 Jan 2017 09:03:01 +0000 Received: from 29.61.140.77.rev.sfr.net (HELO stedding) ([77.140.61.29]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jan 2017 10:02:59 +0100 Date: Fri, 27 Jan 2017 09:13:00 -0000 From: Marc Glisse Reply-To: gcc-patches@gcc.gnu.org To: Jeff Law cc: gcc-patches Subject: Re: [PATCH][RFA][PR tree-optimization/79095] Improve overflow test optimization and avoid invalid warnings In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-SW-Source: 2017-01/txt/msg02124.txt.bz2 On Thu, 26 Jan 2017, Jeff Law wrote: >> I assume this causes a regression for code like >> >> unsigned f(unsigned a){ >> unsigned b=a+1; >> if(b> return b; >> } > Yes. The transformation ruins the conversion into ADD_OVERFLOW for the +- 1 > case. However, ISTM that we could potentially recover the ADD_OVERFLOW in > phi-opt. It's a very simple pattern that would be presented to phi-opt, so > it might not be terrible to recover -- which has the advantage that if a user > wrote an optimized overflow test we'd be able to recover ADD_OVERFLOW for it. phi-opt is a bit surprising at first glance because there can be overflow checking without condition/PHI, but if it is convenient to catch many cases... >> We currently get >> addl $1, %edi >> movl $42, %eax >> cmovnc %edi, %eax >> or almost as good with b==0 >> movl %edi, %eax >> movl $42, %edx >> addl $1, %eax >> cmove %edx, %eax >> while with a==-1 we have the redundant comparison >> leal 1(%rdi), %eax >> cmpl $-1, %edi >> movl $42, %edx >> cmove %edx, %eax >> >> Simplifying x + 1 < x to x + 1 == 0 might not be enough to simplify your >> examples though I guess? > It's an interesting idea. But x+1 == 0 will get canonicalized back into x == > -1. Well, it doesn't always get canonicalized since I got different code above for b==0 and for a==-1. There may be another single_use check in there. But that was probably not a good idea anyway. -- Marc Glisse