From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16389 invoked by alias); 1 May 2012 12:47:33 -0000 Received: (qmail 16381 invoked by uid 22791); 1 May 2012 12:47:33 -0000 X-SWARE-Spam-Status: No, hits=-4.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 01 May 2012 12:47:20 +0000 From: "marc.glisse at normalesup dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/53100] Optimize __int128 with range information Date: Tue, 01 May 2012 12:47:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: marc.glisse at normalesup dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-05/txt/msg00012.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53100 --- Comment #3 from Marc Glisse 2012-05-01 12:47:03 UTC --- (In reply to comment #2) > and not to introduce them just before an optimization that removes them. Usually, doing (long)num1*(__int128)(long)num2 does the right thing. I tried in the example here replacing the plain __int128 multiplications with: inline bool g1(__int128 x){ //return(x<=LONG_MAX)&&(x>=LONG_MIN); //on 2 lines because of PR30318, unless you apply the patch I posted there bool b1 = x<=LONG_MAX; bool b2 = x>=LONG_MIN; return b1&&b2; } inline __int128 mul(__int128 a,__int128 b){ bool B=g1(a)&&g1(b); if(__builtin_constant_p(B)&&B) return (long)a*(__int128)(long)b; return a*b; } __builtin_constant_p does detect we are in the right case, however, because of bad timing between the various optimizations, the double cast (__int128)(long)(u-x) is simplified to just (u-x) before it gets a chance to help. I need to replace the subtraction instead (or in addition) to the multiplication: inline __int128 sub(__int128 a,__int128 b){ bool B=g1(a)&&g1(b)&& g1(a-b); if(__builtin_constant_p(B)&&B) return (long)a-(long)b; return a-b; } But it would fit better inside the compiler than as a fragile use of __builtin_constant_p.