dangerous optimalizations

mcvax!philmds!hulsebos@uunet.uu.net (Rob Hulsebos)
8 Sep 88 11:33:55 GMT

          From comp.compilers

Related articles
dangerous optimalizations mcvax!philmds!hulsebos@uunet.uu.net (1988-09-08)
| List of all articles for this month |

From: mcvax!philmds!hulsebos@uunet.uu.net (Rob Hulsebos)
Newsgroups: comp.compilers,comp.unix.questions
Keywords: compiler, optimalization, spl
Date: 8 Sep 88 11:33:55 GMT
Organization: Philips I&E DTS Eindhoven

The well-known construction found in lots of Unix device-drivers:

      1st instruction;
          2nd instruction;
          3rd instruction, etc. etc.
      last instruction;

only works correctly if all code between the spl7-splx calls is translated
into assembly-code which is executed after the spl7 and before the splx.
However, the optimizer (when enabled) may 'decide' to move some assembly-
instructions before the SPL7 or after the SPL0:

      translated 1st instruction;
      part of translated 2nd instruction;
            remainder of translated 2nd instruction;
            translated 3rd instruction, etc. etc

This may create one (or two) time-windows for the duration of the
assembly-instructions involved, which may cause the program(s) involved to
fail sometimes for mysterious reasons, as the C-code seems to be OK.

As optimizers usually know nothing of side-effects of the programs they
compile (in our case, the CPU-state is altered), care must be taken
when they are used if the compiler-writer(s) can not guarantee that their
compiler does not alter the flow of programs.

I have never seen any compiler doc which gives such guarantees.

Is there anybody who has experience with this subject ? Or has found that
his/hers compiler did the 'optimalizations' described above?

R.A. Hulsebos, Philips I&E Automation Modules ...!mcvax!philmds!hulsebos
Building TQ-III-1 room 11 phone: +31-40-785723
Eindhoven, The Netherlands # cat /dev/disclaimer
[Most optimizers that people actually use assume the worst when they see a
procedure call and avoid moving any code across one. Even if they do, it'd
seem to me that declaring the appropriate variables volatile would usually
tell the compiler what it needs to know to avoid unsafe optimizations of this
kind. Having said all that, most Unix kernels either seem to be compiled
with secret optimizer switches or else with no optimization of device drivers.

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.