Re: [PATCH] x86: Optimize TIF checking in __switch_to_xtra.
From: Thomas Gleixner
Date: Fri Dec 09 2016 - 11:27:53 EST
On Fri, 9 Dec 2016, Thomas Gleixner wrote:
> On Tue, 6 Dec 2016, Kyle Huey wrote:
> > I propose the following patch, which results in GCC generating this code:
> >
> > mov (%rsi),%rax
> > xor (%rdi),%rax
> > mov %rdi,%rbx
> > mov %rsi,%r12
> > test $0x2000000,%eax
> > mov %rax,%rdx
> > jne 3f
> > 1: test $0x10000,%edx
> > je 2f
> > /* do some more work */
> > 2: /* the rest of the function */
> > ret
> > 3: /* do work */
> > mov (%r12),%rdx
> > xor (%rbx),%rdx
> > jmp 1b
> >
> > When we are not doing the work controlled by these flags this is significantly
> > better. We only have to load the flags from memory once, and we do a single
> > XOR that we can test multiple times instead of repeatedly isolating bits.
>
> You rely on the compiler doing the right thing. And it's non obvious from
> the code that this gets optimized as above.
On i386 this creates worse code due to register pressure it seems.