The embodiments of the present application provide a compilation optimization method, device, electronic device and storage medium, wherein the method includes: obtaining
source code to be compiled, wherein the
source code includes a target fragment; the target fragment includes a memory access operation and a
branch operation for performing a boundary check on the memory access operation; when it is determined that the target fragment meets the optimization conditions, the memory access operation and the
branch operation in the target fragment are converted into preset instructions to obtain an optimized target fragment; the preset instructions implement the memory access operation and the
branch operation through one instruction; based on the optimized target fragment, a binary file is generated. The embodiments of the present application propose a new instruction, which can implement the memory access operation and the branch operation through one instruction, thereby reducing the use of branch instructions, and to a certain extent can reduce the additional overhead caused by branch instructions, thereby improving program performance.