This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Fix 'array subscript is above array bounds' warning in res_send.c
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: Siddhesh Poyarekar <siddhesh at redhat dot com>, Adhemerval Zanella <azanella at linux dot vnet dot ibm dot com>, libc-alpha at sourceware dot org, schwab at suse dot de
- Date: Tue, 16 Dec 2014 23:00:19 +0100
- Subject: Re: [PATCH] Fix 'array subscript is above array bounds' warning in res_send.c
- Authentication-results: sourceware.org; auth=none
- References: <20141216104514 dot GN30928 at spoyarek dot pnq dot redhat dot com> <mvmy4q7j20b dot fsf at hawking dot suse dot de> <20141216112624 dot GO30928 at spoyarek dot pnq dot redhat dot com> <5490254E dot 8060508 at linux dot vnet dot ibm dot com> <20141216125211 dot GW30928 at spoyarek dot pnq dot redhat dot com> <54902C9E dot 5030408 at linux dot vnet dot ibm dot com> <20141216130524 dot GX30928 at spoyarek dot pnq dot redhat dot com> <54902FB8 dot 8070006 at linux dot vnet dot ibm dot com> <20141216134432 dot GY30928 at spoyarek dot pnq dot redhat dot com> <20141216180536 dot 9D6AE2C2448 at topped-with-meat dot com>
On Tue, Dec 16, 2014 at 10:05:36AM -0800, Roland McGrath wrote:
> When changing the source code does not actually cause any de-optimization
> of the generated code, then it seems cleaner to change the code rather than
> to suppress the warning. In this case, changing the condition will change
> what conditional-branch instruction is emitted, but it won't change the
> number (or size) of instructions emitted or change anything that would
> affect performance.
That is false, could change code as compiler thinks that branches with
equality are less probable than with inequality and decide to optimize
branch for size only where there is equality.
A simplest example is look on icc assembly as it also writes guessed
probabilities.
icc -O3 test.c -S
test.c:
int foo(int x)
{
return (x == 42) ? sin (32.0) : cos (14.3);
}
test.s:
je ..B1.4 # Prob 16% #4.16
test.c:
int foo(int x)
{
return (x >= 42) ? sin (32.0) : cos (14.3);
}
test.s:
jl ..B1.3 # Prob 50% #4.16