Eliminate Store-Load pair even the LoadInst is volatile

Hi,

Thanks, John, I just forgot the multi-thread issue.
I’ll write my own pass to handle this as for my project, it is just single-thread case.

Sheng.

Zhou Sheng wrote:

Hi,
Thanks, John, I just forgot the multi-thread issue.

Multi-threading is just one example of why volatile exists. Some systems use it for I/O operations (since you don't want the load/store to I/O device memory to get optimized away). Volatile may also be used in programs that access shared memory via a shared memory segment (i.e. multi-process sharing instead of multi-thread sharing).There may be other reasons why volatile is used, but the above are probably the most common.

In C, the volatile keyword simply means that the compiler must be pessimistic with removing the load/store because memory is affected in some way outside the scope of compiler analysis. I assume LLVM's volatile attribute is used to implement these types of optimization restrictions.

I'll write my own pass to handle this as for my project, it is just single-thread case.

As long as you know the transform is safe within the domain of your application, it makes sense. However, my question would be: if you know it's safe, then why is the load marked volatile in the first place? Are you sure that volatile is only used for safe shared memory accesses, or could it be there for another reason?

-- John T.