<div><div>Hi, <br> </div>Thanks, John, I just forgot the multi-thread issue.<br>I'll write my own pass to handle this as for my project, it is just single-thread case.<br> <br><br><br>Sheng.<br><br><blockquote class="gmail_quote" style="margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; margin-left: 0.80ex; border-left-color: #cccccc; border-left-width: 1px; border-left-style: solid; padding-left: 1ex">
Date: Thu, 22 May 2008 09:30:45 -0500<br> From: John Criswell <<a href="mailto:criswell@cs.uiuc.edu">criswell@cs.uiuc.edu</a>><br> Subject: Re: [LLVMdev] Eliminate Store-Load pair even the LoadInst is<br> volatile<br>
To: LLVM Developers Mailing List <<a href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a>><br> Message-ID: <<a href="mailto:48358395.3070403@cs.uiuc.edu">48358395.3070403@cs.uiuc.edu</a>><br> Content-Type: text/plain; charset=ISO-8859-1; format=flowed<br>
<br> Zhou Sheng wrote:<br> > Hi all,<br> ><br> > I put a case into llvm and got the following .ll code:<br> ><br> > ...<br> > %r1419_0_0_0_i376 = alloca i32 ; <i32*> [#uses=2]<br> > ...<br> > %tmp1476_i = lshr i32 %tmp1226_i, 24 ; <i32> [#uses=1]<br>
><br> > store i32 %tmp1476_i, i32* %r1419_0_0_0_i376, align 4<br> > %tmp1505_i = volatile load i32* %r1419_0_0_0_i376, align 4 ; <i32> [#uses=1]<br> ><br> > %tmp1542_i = getelementptr [256 x i8]* @Te, i32 0, i32 %tmp1505_i<br>
> ...<br> ><br> ><br> > llvm opt can't remove the redundant store-load pair to just use the value %tmp1476 as the load is volatile.<br> > But I think for the above situation, it's safe to remove store-load, as the allocad %r1419_0_0_0_i376 just has two users (the one load and one store), correct?<br>
><br> I don't think you can do that. Loads are often marked volatile because<br> the memory location is accessed in some "undefined" way. For example,<br> if the pointer to the alloca'ed memory escapes, it could be used for<br>
synchronization with another thread. There could be other, concurrent<br> stores by other threads that will change the value read by the load.<br> Your optimization would break such code because this thread would only<br>
see stores that it itself made.<br> > Can I add some code to instcombine or dce for this?<br> ><br> ><br> In general, I think shortcutting the volatile load would be incorrect,<br> and therefore, such a transform should not be a part of instcombine or dce.<br>
<br> However, if you wanted to, you could write your own custom pass that<br> shortcuts the load *if* you know that in your particular situation that<br> such shortcuts are safe. For example, if I was writing a front-end for<br>
LLVM that naively generated volatile loads for all synchronization<br> variables, I could write a pass that would short-cut the load if it<br> could also prove that the alloca never escapes (and therefore, only the<br> local thread can access the alloca'ed memory).<br>
<br> -- John T.<br><br><br><br> ------------------------------<br>__________<br><br><br> End of LLVMdev Digest, Vol 47, Issue 102<br> ****************************************<br></blockquote></div><br>