From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752694AbbKWQL3 (ORCPT ); Mon, 23 Nov 2015 11:11:29 -0500 Received: from mout.kundenserver.de ([212.227.126.131]:55256 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751049AbbKWQLY (ORCPT ); Mon, 23 Nov 2015 11:11:24 -0500 From: Arnd Bergmann To: Nicolas Pitre Cc: Russell King - ARM Linux , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on 32-bit machines Date: Mon, 23 Nov 2015 17:11:20 +0100 Message-ID: <4277009.MDAEAbRExl@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:zmSKOT6K4InnzWRJbHwcrf0RKQhTfA9wQovE3Vk7tN5aWSdD8ar UTCq5yBM6+sk8ADUBA8rhuGw0kiPAoBE6AnVlJyGTNBzWKOHcHQ/CoVjW4n8G82KfCp5CNr Nqz0DU4ikfek9K+HXn4QQbPyIYTwvMo7oEMMrjzFYFfkdzETRL7fR7BPlwOub7I6Qgk9APJ VVMD83qqsnzKRlpTW2W4g== X-UI-Out-Filterresults: notjunk:1;V01:K0:GrbKU9uaTXY=:9dzGioeGXoHV5xjJ7LnVxn podKYZZx/b70hYdTbekjJS7QN+ER0mSxSh7uSElALQVZlZ2zVXN1yZRlZQfwU8knzmu9SoEi/ Hbki1eSZBGhGm9JWG+JSrT+ttwm6xZTb6xy9OQTvnjXHejyZcJk7mrfQd6Ab4Tbp08QQkpewF QbdAipy/rHGhWx+LxNCkFAdyaHB5gY/9mn9PKUSspGMzRlB+I1e61xqh+kdQonB7AJ0CiYgYk 7hHILdpWbakvh5RyFPTQ+sXvcuRXVdaItaP1RRLqWKtbj5dQw16SqPQWRLhLu2kndpR9K+mcY 39dr012berLTuGcvhnzyZ4cjMMISq3epRFToAwS6/8I5Z2d4DAc3yQHb1cAWCW1rqn2SlZl6S 2OMSvA2zQ9bFtKFu6QpumgVWG7/or1LMFXCXPe8AC30IoqhQFTmZj4TKtR9Lv8FlhSXoMqcWL ix/wp/kWt80QarGr45l4SRgOKQxIRRpDLQAheu5wSc9OiHbIu4vtqnPtIQJtRGJzrAmjqH8jI Zz3EjI/3GI6zuzx5Po/OVgjmQlDP99ooJU2QlFeaiGdW0r3fFbIWlhfzXU2S53zQHHvp3rOyX pC/cVLE7OloAomf8pZsCLVZZmdE+fxWy6XMJ6h/l1SwxZYEY+FRA4INAc4lx697oPC6HNVy5S HvPUhEcnF0DqHD0J57HgPt5UThSs9S5Vxv3/qivYlh1DIt/AHvAH5i+iCOLwDEPxsC8EH9YQ7 owCrH6YnVM0fafor Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Monday 23 November 2015 11:04:33 Nicolas Pitre wrote: > > OK... I'm able to "fix" the build with: > > diff --git a/include/asm-generic/div64.h b/include/asm-generic/div64.h > index 163f77999e..d246c4c801 100644 > --- a/include/asm-generic/div64.h > +++ b/include/asm-generic/div64.h > @@ -206,7 +206,7 @@ extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor); > uint32_t __rem; \ > (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \ > if (__builtin_constant_p(__base) && \ > - is_power_of_2(__base)) { \ > + is_power_of_2(__base) && __base != 0) { \ > __rem = (n) & (__base - 1); \ > (n) >>= ilog2(__base); \ > } else if (__div64_const32_is_OK && \ > > What doesn't make sense to me is the fact that is_power_of_2() is > defined as: > > static inline __attribute__((const)) > bool is_power_of_2(unsigned long n) > { > return (n != 0 && ((n & (n - 1)) == 0)); > } > > So the test for zero is already in there. > > And adding BUILD_BUG_ON(__builtin_constant_p(__base) && __base == 0) > before the if doesn't trig either. I've seen similarly messed up situations with PROFILE_ALL_BRANCHES before, I think it's got something to do with how __builtin_constant_p() is used inside of the __trace_if() macro, and how gcc sometimes falls back to treating variables as not-really-constant based on context. To gcc, __builtin_constant_p is just best-effort, and they don't care about returning false sometimes if they catch most cases in practice. Note that llvm will always return false for __builtin_constant_p on non-pointer arguments, which breaks a lot of optimizations. Arnd