In some embodiments, the invention includes a method of compiling
instructions of a program. The method includes receiving instructions for
code motion and controlling the code motion while interacting with block
ordering. The code motion may be done as part of various activities
including instruction scheduling, partial redundancy elimination, and loop
invariant removal. The scheduling may involve making an assessment of the
cost of scheduling an instruction that takes into account generation
and/or elimination of branches due to resulting block order update and
determining whether to make the code motion based on the cost. Instruction
scheduling may involve regeneration of predicate expressions to invert
conditional branches.