Re: Safety and legality of optimizations

cliffc@crocus.hpl.hp.com (Cliff Click)
Tue, 21 Mar 1995 15:26:41 GMT

          From comp.compilers

Related articles
Re: Optimizing Across && And || bart@cs.uoregon.edu (1995-02-23)
Safety and legality of optimizations(Re: Optimizing Across && And ||) Vinod.Grover@Eng.Sun.COM (1995-03-18)
Re: Safety and legality of optimizations cliffc@crocus.hpl.hp.com (1995-03-21)
Re: Safety and legality of optimizations Vinod.Grover@Eng.Sun.COM (1995-03-28)
Re: Safety and legality of optimizations cliffc@crocus.hpl.hp.com (1995-04-03)
Re: Safety and legality of optimizations cef@geodesic.com (Charles Fiterman) (1995-04-15)
Re: Safety and legality of optimizations Dave@OCCL-CAM.DEMON.CO.UK (Dave Lloyd) (1995-04-18)
Re: Safety and legality of optimizations cliffc@crocus.hpl.hp.com (1995-04-17)
Re: Safety and legality of optimizations jim@meiko.co.uk (1995-04-21)
[1 later articles]
| List of all articles for this month |
Newsgroups: comp.compilers
From: cliffc@crocus.hpl.hp.com (Cliff Click)
Keywords: optimize, design
Organization: Hewlett-Packard Laboratories, Cambridge Research Office
References: 95-02-17995-03-107
Date: Tue, 21 Mar 1995 15:26:41 GMT

Vinod.Grover@Eng.Sun.COM (Vinod Grover) writes:
> Yes, but is it safe to eliminate infinite loops? Consider:
> /* fire the rockets if f is null or acyclic */
> void doit_or_die(foo *f, int n) {
> foo *x;
> for (x=f; x; x = x->next) {}
> /* fire 'em */
> ...
> }
>
> Eliminating the loop or moving code across infinite loop can be argued
> as unsafe.




Here "fire 'em" does some form of I/O (writes a hardware register, whatever).
Moving I/O across a potentially infinite loop is bad.
However, you _can_ move everything else across the loop, as long as you
preserve all data- & control- dependences. You can even move other
potentially infinite loops across. As in:


    void do_or_die(foo *f, int n) {
        foo *x;
        for (x=f; x; x = x->next) {} /* possible seg-fault, possible inf loop */
        f->baz = 1/n; /* possible divide error */
        for (x=f->bar; x; x=x->next){} /* possible seg-fault, possible inf loop */
        /* fire 'em */ /* I/O occurs here */
        ...
  }


    void do_or_die_TRANSFORMED(foo *f, int n) {
        foo *x;
        f->baz = 1/n; /* <-- possible exception reordered */
        for (x=f->bar; x; x=x->next){} /* Possible inf loop, seg fault */
        for (x=f; x; x = x->next) {} /* Possible inf loop, seg fault */
        /* fire 'em */ /* no faults occured, all loops terminated*/
        ...
  }


Of course, anything that follows a really infinite loop is just dead.
I guess I also believe that compilers need only preserve partial correctness.
As in:


    void do_or_die(foo *f, int n) {
        n = 0xdeadbeef;
        ((foo*)n)->next; /* <-- dead code that seg-faults & halts prog */
        /* fire 'em */
    }


    void do_or_die_TRANSFORMED(foo *f, int n) {
        /* fire 'em */ /* ahh, the end of the world as we know it... :-) */
    }


Cliff
--
Cliff Click Compiler Research Scientist
Cambridge Research Office, Hewlett-Packard Laboratories
One Main Street, 10th Floor, Cambridge, MA 02142
(617) 225-4915 Work (617) 225-4930 Fax
cliffc@hpl.hp.com http://bellona.cs.rice.edu/MSCP/cliff.html
--


Post a followup to this message

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