Missed optimization question

Marc Glisse marc.glisse@inria.fr
Sun Dec 1 18:58:00 GMT 2019


On Sun, 1 Dec 2019, Arvind Sankar wrote:

> 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?

Please file a report in gcc's bugzilla.

min(a,min(a,b)) is only simplified during reassoc. min(a,b)<=b is not 
simplified. min(a,b)==b is simplified to a>=b before reassoc.

Adding 2 transformations to match.pd would be quite simple, but is 
unlikely to happen until there is a bug report in the right place.

-- 
Marc Glisse



More information about the Gcc-help mailing list