mardi 28 février 2017

Optimization - General rule - if condition into a loop breaks the pipeline

In the context of a job, I have to optimize a big code which has a lot of loops in its main structure.

Sometimes, there are into these loops (with big iterations) one or more "if then else" conditions. A colleague of mine told me to avoid these "if then else" conditions into loops because according to him, "this breaks the pipeline of execution".

But in some cases, I have not the choice to not use them unless modifying a lot of things (and I don't want to start by doing large modifications).

I think that for avoiding them, I need to pre-filter the indexes which check and replace the indexes selected by the "if then else" condition (in the current version) but this doesn't seem interesting from an optimization point of view because to pre-filter and find these valid indexes, I need also to use another loop before the existing loop.

From what I know, the "pipeline" is the capacity for a processor to fetch the next instruction before the current instruction to be finished.

So, I would like to have advices about this concept "Don't use "if then else" into loops because it breaks pipeline" : is this really the case or modern compiler and processor can overcome this algorithmic issue.

Any remark is welcome, thanks

Aucun commentaire:

Enregistrer un commentaire