Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What kind of optimizations are included in -funsafe-math-optimizations?

GCC's man page states that -funsafe-math-optimizations allows for optimizations that "(a) assume that arguments and results are valid and (b) may violate IEEE or ANSI standards", but that's not very precise, is it?

What could an "invalid" argument be in this case? NaNs? Infinites? Subnormals? Negative numbers to sqrt()?

How far are results allowed to deviate from IEEE or ANSI standards? Is it "merely" stuff like operation associativity and ordering, or might it include eg. true comparisons with NaNs or incorrect comparisons with infinites? Could a stored variable be re-rounded after already being used (such that, for variables x and y, (x == y) + (x == y) could evaluate to 1)? Could isinf()/isnan() stop working?

Do the GCC devs follow any particular system or discipline with regards to such questions, or could the answer differ wildly from version to version?

like image 766
Dolda2000 Avatar asked Jan 25 '15 06:01

Dolda2000


People also ask

How many types of optimization are there?

There are two distinct types of optimization algorithms widely used today. (a) Deterministic Algorithms. They use specific rules for moving one solution to other. These algorithms are in use to suite some times and have been successfully applied for many engineering design problems.

What are Optimisation techniques?

What is optimization? Optimization technique is a powerful tool to obtain the desired design parameters and. best set of operating conditions .This would guide the experimental work and reduce. the risk and cost of design and operating.

What are the three elements of optimization?

Every optimization problem has three components: an objective function, decision variables, and constraints.


1 Answers

According to gcc.gnu.org (my bold):

This mode enables optimizations that allow arbitrary reassociations and transformations with no accuracy guarantees. It also does not try to preserve the sign of zeros.

That includes your mention of associative reordering, as well as "Built-in functions [which] have names such as __builtin_sqrt" being applied when they "may have less precision or be restricted to a smaller domain"

like image 142
Drew Dormann Avatar answered Sep 30 '22 17:09

Drew Dormann