Re: 'Re: [PATCH] drivers/android: remove redundant ret variable'

From: Greg KH
Date: Wed Jan 05 2022 - 05:09:50 EST


On Wed, Jan 05, 2022 at 09:19:42AM +0000, cgel.zte@xxxxxxxxx wrote:
> I found that there are indeed some optimizations
> after removing the redundancy.

You stripped off all context, making this impossible to remember what
you are responding to :(

>
> For example:
>
> int foo(int a, int b)
> {
> int ret;
> ret = a>b ? a: b;
> return ret;
> }
> int main()
> {
> int val;
> val = foo(7,2);
> return 0;
> }
>
> and
>
> int foo(int a, int b)
> {
> return a>b ? a: b;
> }
> int main()
> {
> int val;
> val = foo(7,2);
> return 0;
> }
>
> The corresponding disassembly code is as follows:
>
> 1129: f3 0f 1e fa endbr64
> 112d: 55 push %rbp
> 112e: 48 89 e5 mov %rsp,%rbp
> 1131: 89 7d fc mov %edi,-0x4(%rbp)
> 1134: 89 75 f8 mov %esi,-0x8(%rbp)
> 1137: 8b 45 fc mov -0x4(%rbp),%eax
> 113a: 39 45 f8 cmp %eax,-0x8(%rbp)
> 113d: 0f 4d 45 f8 cmovge -0x8(%rbp),%eax
> 1141: 5d pop %rbp
> 1142: c3 retq
>
> and
>
> 1129: f3 0f 1e fa endbr64
> 112d: 55 push %rbp
> 112e: 48 89 e5 mov %rsp,%rbp
> 1131: 89 7d ec mov %edi,-0x14(%rbp)
> 1134: 89 75 e8 mov %esi,-0x18(%rbp)
> 1137: 8b 45 ec mov -0x14(%rbp),%eax
> 113a: 39 45 e8 cmp %eax,-0x18(%rbp)
> 113d: 0f 4d 45 e8 cmovge -0x18(%rbp),%eax
> 1141: 89 45 fc mov %eax,-0x4(%rbp)
> 1144: 8b 45 fc mov -0x4(%rbp),%eax
> 1147: 5d pop %rbp
> 1148: c3 retq
>
> After removing the redundancy, the compiler does
> have some optimizations

As I said on your other email, look at the kernel built files please,
they should be much different from your tiny example above.

thanks,

greg k-h