[LLVMdev] inttoptr weirdness

Dale Johannesen dalej at apple.com
Mon Dec 14 16:09:15 PST 2009


On Dec 14, 2009, at 3:50 PMPST, Chris Lattner wrote:

> On Dec 14, 2009, at 2:21 PM, Jeffrey Yasskin wrote:
>>>
>>> @"compile-test::*testObj*" = external constant i8*              ;
>>> <i8**> [#uses=1]
>>>
>>> define void @"compile-test::__toplevel-main"() {
>>> entry:
>>>       store i8* null, i8** @"compile-test::*testObj*"
>>
>> I'm surprised this store got optimized out, even though LLVM can
>> optimize away the subsequent load. Writing to an external global
>> variable is a visible side-effect, and unless there's other undefined
>> behavior, LLVM shouldn't remove it.
>
> Sure it can, llvm can delete any non-volatile redundant load, or any
> non-volatile redundant store.  It doesn't matter whether it is to a
> global or not, LLVM (as with many compilers) memory models are for
> single threaded programs.  We do try to conform to the C++'0x memory
> model by not introducing memory accesses where they did not exist
> before, but deleting non-volatile accesses is always fine.

That's true, but it's often hard to figure out a store to a global can  
be deleted, as a use may be arbitrarily far away, in a different file  
for example.

In this case the global is declared constant, so storing to it is  
invalid.  That is probably why it got removed.




More information about the llvm-dev mailing list