<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Thanks Bill, I appreciate even if it’s "a bit self-serving" :).<div><br><div><div><div>On Mar 14, 2013, at 4:24 PM, Bill Wendling <<a href="mailto:wendling@apple.com">wendling@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">On Mar 14, 2013, at 4:02 PM, Quentin Colombet <<a href="mailto:qcolombet@apple.com">qcolombet@apple.com</a>> wrote:<br><br><blockquote type="cite">Hi,<br><br>I’ve updated the patch for Global merge constants so that it implements the last proposal.<br><br>Thanks for your reviews,<br><br></blockquote>It's a bit self-serving for me to review this, given that I suggested it, but here we go. :-) Overall, this looks good. I would be interested to know how this affects compile time --- specifically at '-O0'. I ask because of looping over the uses of a global in a program can take a while for something that's used a lot. Could you run the test-suite to see if there are any significant slowdowns?<br></div></blockquote><div>Will do. However, this pass is obviously not run at O0.</div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><br>There are a few nits:<br><br>+/// Check whether the uses of the given value can be replaced by GEP.<br><br>Should this start with a '\brief’?<br></div></blockquote>Good question…</div><div>doxygen can interpret the first line of such comments as a brief, but it depends on how it is configured so I don’t know.</div><div>Anyway, it does not hurt to add one in that case :).</div><div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">+/// This function also checks transitively the uses made after a bitcast of the<br>+/// given value.<br>+/// Currently we consider that this is not possible when at least one of the<br>+/// use is one of these kind:<br>+/// - Intrinsic<br>+/// - Landing pad<br>+/// - Inline asm<br>+/// \pre Val is a GlobalVariable or a bitcast of a GlobalVariable or a bitcast<br>+///      of a bitcast of a GlobalVariable and so on.<br>+static bool areUsesAcceptGEP(const Value *Val) {<br><br>Do you mean 'areUsesExceptGEP’?<br></div></blockquote><div>No, I want to check if all the uses can have a GEP as one of their operand, i.e., it won’t break the IR if we turn one of their operand into a GEP.</div><div>Maybe doUsesAcceptGEP is more correct?</div><div>If you have something else in mind, I’m sure it will be better!</div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><br>+  for (Value::const_use_iterator UseIt = Val->use_begin(),<br>+         EndIt = Val->use_end(); UseIt != EndIt; ++UseIt) {<br>+    // Do not mess with Intrinsic or LandingPad<br>+    if (isa<const LandingPadInst>(*UseIt) ||<br>+        isa<const IntrinsicInst>(*UseIt))<br><br>You don't need the 'const' in the 'isa<>' statement.<br></div></blockquote>Okay.</div><div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><br>+      return false;<br>+    // Same for InlineAsm<br>+    const CallInst *CI = dyn_cast<const CallInst>(*UseIt);<span class="Apple-converted-space"> </span><br><br>Same here, re 'const' in the 'dyn_cast<>' statement.<br></div></blockquote>Okay.</div><div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><br>+    if (CI && isa<const InlineAsm>(CI->getCalledValue()))<br>+      return false;<br>+    // Check transitively uses done after a bitcasts<br>+    const BitCastInst *BI = dyn_cast<const BitCastInst>(*UseIt);<br>+    // FIXME: Is it possible to have a cycle with bitcasts uses, i.e.,<br>+    // value1 bitcasted to value2 and value2 bitcasted to value1 without<br>+    // anything in between?<br><br>I don't think it's possible with SSA. I'm assuming you mean something like this?<br></div></blockquote>That’s what I think too: because of SSA and because you cannot change the address of a global variable.</div><div>I can remove this comment then!</div><div><br></div><div>For the record, I had in mind something like this (which is syntactically wrong):</div><div>@g = i32*</div><div>@h = float*</div><div><br></div><div>define @foo() {</div><div>  @h = bitcast i32* @g to float*</div><div>}</div><div><br></div><div><div>define @bar() {</div><div>  @g = bitcast float* @h to i32*</div><div>}</div></div><div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><br>@g = i32* ...<br><br>define void @foo() {<br> %tmp1 = bitcast i32* @g to i8*<br> %tmp2 = bitcast i8* %tmp1 to i32*<br>}<br><br>+    // If yes, we should keep a set of already seen values.<br>+    if (BI && !areUsesAcceptGEP(BI))<br>+      return false;<br>+  }<br>+  return true;<br>+}<br><br>-bw</div></blockquote></div><br></div></div><div>-Quentin</div></body></html>