Proving Safety of Speculative Load Instructions Compile-Time David Bernstein Michael Rodeh Mooly Sagiv IBM Israel Scientific Center the Technion City, Haifa 32000, Israel Email: bernstn@haifasc3.vnet.ibm.com at Abstract Speculative execution of instructions is one of the primary means for enhancing program performance of superscalar and VLIW machines. One of the pitfalls of such compile-time speculative scheduling of instructions is that it may cause run-time exceptions that did not exist in the original version of the program. As opposed to run-time hardware or software interception of such exceptions, we suggest that the compiler will analyze and prove the safety of those instructions that are candidates for speculative execution, rejecting the ones that have even a slight chance of causing an exception. Load (moving a memory operand to a register) instructions are important candidates for speculative execution, since they precondition any follow-on computation on load-store archi- tectures. To enable speculative loads, an algorithmic scheme for proving the safety of such instructions is presented and analyzed. Given a (novel) memory layout scheme which is spe- cially tailored to support safe memory accesses, it has been observed that a significant part of load instructions can be proven safe and thus can be made eligible for speculative execution. 1 Introduction The recent advent of superscalar and VLIW machines increases the need for aggressive instruction scheduling by optimizing compilers. If previously (for pipelined machines) it was sufficient to reorder instructions at the basic block level ([HG83], [War90]), it is evident now that for the newer machines, instructions have to be moved well beyond basic block boundaries. A few such efforts were described in JEll85, EN89, GS90, BR91]. It turns out that very often, to further improve the utilization of machine resources, instructions have to be scheduled speculatively, i.e., moved ahead of a preceding branch to a place were it is not yet determined in the program that such instructions have to be executed at all. Previously, speculative execution was considered in the context of moving loop-invariants out of loops [ASU85], while recently, due to the evolution toward superscalar and VLIW machine designs, this type of transformations is being exploited in a much broader scope of code motions. In case the compiler guesses right the direction of the branch over which a speculative instruction is moved, such instruc- tion computes useful results; otherwise the compiler must make sure that these results will not be used in the subsequent execution of the program.