diff mbox

[02/17] x86, lto: Disable fancy hweight optimizations for LTO v2

Message ID 1391846481-31491-2-git-send-email-ak@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andi Kleen Feb. 8, 2014, 8:01 a.m. UTC
The fancy x86 hweight uses different compiler options for the
hweight file. This does not work with LTO. Just disable the optimization
with LTO

v2: Simplify Kconfig checks (Jan Beulich)
Cc: x86@kernel.org
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 arch/x86/Kconfig                    | 1 +
 arch/x86/include/asm/arch_hweight.h | 9 +++++++++
 2 files changed, 10 insertions(+)

Comments

H. Peter Anvin Feb. 8, 2014, 6:52 p.m. UTC | #1
On 02/08/2014 12:01 AM, Andi Kleen wrote:
> The fancy x86 hweight uses different compiler options for the
> hweight file. This does not work with LTO. Just disable the optimization
> with LTO

No, I'm going to NAK this.  This means not using the POPCNT instruction
if LTO is enabled, and that really isn't an acceptable option.

	-hpa


--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Andi Kleen Feb. 8, 2014, 8:21 p.m. UTC | #2
On Sat, Feb 08, 2014 at 10:52:07AM -0800, H. Peter Anvin wrote:
> On 02/08/2014 12:01 AM, Andi Kleen wrote:
> > The fancy x86 hweight uses different compiler options for the
> > hweight file. This does not work with LTO. Just disable the optimization
> > with LTO
> 
> No, I'm going to NAK this.  This means not using the POPCNT instruction
> if LTO is enabled, and that really isn't an acceptable option.

I thought the use was obscure?

Ok, suppose can just disable LTO for the file.
The only drawback is that the functions will not be optimized away when
not used, as they'll need to be __visible.

-Andi
H. Peter Anvin Feb. 8, 2014, 9:43 p.m. UTC | #3
That's fine.

On February 8, 2014 12:21:24 PM PST, Andi Kleen <ak@linux.intel.com> wrote:
>On Sat, Feb 08, 2014 at 10:52:07AM -0800, H. Peter Anvin wrote:
>> On 02/08/2014 12:01 AM, Andi Kleen wrote:
>> > The fancy x86 hweight uses different compiler options for the
>> > hweight file. This does not work with LTO. Just disable the
>optimization
>> > with LTO
>> 
>> No, I'm going to NAK this.  This means not using the POPCNT
>instruction
>> if LTO is enabled, and that really isn't an acceptable option.
>
>I thought the use was obscure?
>
>Ok, suppose can just disable LTO for the file.
>The only drawback is that the functions will not be optimized away when
>not used, as they'll need to be __visible.
>
>-Andi
diff mbox

Patch

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 940e50e..f125c5f 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -255,6 +255,7 @@  config X86_32_LAZY_GS
 
 config ARCH_HWEIGHT_CFLAGS
 	string
+	default "" if LTO
 	default "-fcall-saved-ecx -fcall-saved-edx" if X86_32
 	default "-fcall-saved-rdi -fcall-saved-rsi -fcall-saved-rdx -fcall-saved-rcx -fcall-saved-r8 -fcall-saved-r9 -fcall-saved-r10 -fcall-saved-r11" if X86_64
 
diff --git a/arch/x86/include/asm/arch_hweight.h b/arch/x86/include/asm/arch_hweight.h
index 9686c3d..ca80549 100644
--- a/arch/x86/include/asm/arch_hweight.h
+++ b/arch/x86/include/asm/arch_hweight.h
@@ -25,9 +25,14 @@  static inline unsigned int __arch_hweight32(unsigned int w)
 {
 	unsigned int res = 0;
 
+#ifdef CONFIG_LTO
+	res  = __sw_hweight32(w);
+#else
+
 	asm (ALTERNATIVE("call __sw_hweight32", POPCNT32, X86_FEATURE_POPCNT)
 		     : "="REG_OUT (res)
 		     : REG_IN (w));
+#endif
 
 	return res;
 }
@@ -46,6 +51,9 @@  static inline unsigned long __arch_hweight64(__u64 w)
 {
 	unsigned long res = 0;
 
+#ifdef CONFIG_LTO
+	res = __sw_hweight64(w);
+#else
 #ifdef CONFIG_X86_32
 	return  __arch_hweight32((u32)w) +
 		__arch_hweight32((u32)(w >> 32));
@@ -54,6 +62,7 @@  static inline unsigned long __arch_hweight64(__u64 w)
 		     : "="REG_OUT (res)
 		     : REG_IN (w));
 #endif /* CONFIG_X86_32 */
+#endif
 
 	return res;
 }