1. A method of compressing instructions in a program, comprising: extracting unique bit patterns from the instructions in the program; constructing a linear programming formulation or an integer programming formulation from the unique bit patterns and the instructions; solving the linear programming formulation or the integer programming formulation to produce a solution; and compressing at least some of the instructions based on the solution by storing at least some of the unique bit patterns in a memory and placing corresponding indices to the memory in new compressed instructions.