1. A method of compiling a program, the method comprising: performing a program flow analysis on a software transactional memory (STM) transaction that tracks a possible shadow copy pointer for first and second memory accesses to a memory location in the STM transaction; and identifying an STM optimization for the second memory access using the program flow analysis.