From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18957 invoked by alias); 9 Nov 2007 12:37:41 -0000 Received: (qmail 18926 invoked by alias); 9 Nov 2007 12:37:32 -0000 Date: Fri, 09 Nov 2007 12:37:00 -0000 Message-ID: <20071109123732.18925.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug tree-optimization/34027] [4.3 regression] -Os code size nearly doubled In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "rguenther at suse dot de" 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: 2007-11/txt/msg00783.txt.bz2 ------- Comment #5 from rguenther at suse dot de 2007-11-09 12:37 ------- Subject: Re: [4.3 regression] -Os code size nearly doubled On Fri, 9 Nov 2007, jakub at gcc dot gnu dot org wrote: > ------- Comment #4 from jakub at gcc dot gnu dot org 2007-11-09 12:30 ------- > So then shouldn't this bug be about: > unsigned long long > foo (unsigned long long ns) > { > return ns % 1000000000L; > } > > unsigned long long > bar (unsigned long long ns) > { > return ns - (ns / 1000000000L) * 1000000000L; > } > > not compiling the same code at -Os? On x86_64 with -O2 it actually produces > identical code with the subtraction, supposedly that's faster. Guess even > (ns / 1000000000L) * 1000000000L should be folded into > ns - (ns % 1000000000L). With -O2 we express the division by the constant by multiplication / add sequences. But for both we get the extra multiplication: bar: .LFB3: movl $1000000000, %esi movq %rdi, %rax xorl %edx, %edx divq %rsi movq %rdi, %rcx imulq $1000000000, %rax, %rdx subq %rdx, %rcx movq %rcx, %rax ret bar: .LFB3: movq %rdi, %rdx movabsq $19342813113834067, %rax shrq $9, %rdx mulq %rdx shrq $11, %rdx imulq $1000000000, %rdx, %rdx subq %rdx, %rdi movq %rdi, %rax ret because we miss this folding opportunity. Richard. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34027