Missed optimization question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, for the below example, gcc (9.2.0) at -O and above generates
identical code for f1 and f2 (on x86_64 at least). So one would think
that the compiler "knows" that the min(m,b) can be reduced to m, however
f3 doesn't get optimized away into return 1; at any level of
optimization.

f4 is closest to the real example, where there's a bounds check on a
variable that was already min'd with the bound, but the check doesn't
get optimized away.

Why would this be the case?

Listing:

#define min(a,b) ((a)<(b)?(a):(b))

int f1(int a,int b)
{
	int m = min(a,b);
	return m;
}

int f2(int a,int b)
{
	int m = min(a,b);
	return min(m,b);
}

int f3(int a,int b)
{
	int m = min(a,b);
	return m == min(m,b);
}

int f4(int a,int b)
{
	int m = min(a,b);
	return m <= b;
}



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux