<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;">Hi Tom,<div><br></div><div>That’s weird that bugpoint is linking correctly for you.</div><div><br></div><div>I have dug in that linking problem and here is what I found.</div><div>Because of the CodeGenPrepare pass, libLLVMScalarOpts has a dependency on libLLVMCodeGen, which is not included on the link command of bugpoint.</div><div><br></div><div>So far it was working because all the functions of TargetLowering called in CodeGenPrepare are either:</div><div>- virtual function (resolved dynamically).</div><div>- inlined in the header (code available statically).</div><div><br></div><div>InstructionOpcodeToISD is not a virtual function and not inlined in the header, thus the linking problem.</div><div><br></div><div>We could add a dependency in bugpoint on libLLVMCodeGen, but I am not sure we want to do that.</div><div>Another possibility would be to inline InstructionOpcodeToISD into the header, though I haven’t check how much this is pulling into the header.</div><div><br></div><div>Thoughts?</div><div><br></div><div>Cheers,</div><div><div apple-content-edited="true">
<div style="color: rgb(0, 0, 0); font-family: Helvetica;  font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">-Quentin</div>

</div>
<br><div><div>On Feb 18, 2014, at 2:28 PM, Tom Stellard <<a href="mailto:tom@stellard.net">tom@stellard.net</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Tue, Feb 18, 2014 at 12:45:33PM -0800, Quentin Colombet wrote:<br><blockquote type="cite"><br>On Feb 18, 2014, at 11:19 AM, Tom Stellard <<a href="mailto:tom@stellard.net">tom@stellard.net</a>> wrote:<br><br><blockquote type="cite">On Tue, Feb 18, 2014 at 11:00:05AM -0800, Quentin Colombet wrote:<br><blockquote type="cite"><br>On Feb 18, 2014, at 10:30 AM, Tom Stellard <<a href="mailto:tom@stellard.net">tom@stellard.net</a>> wrote:<br><br><blockquote type="cite">On Tue, Feb 18, 2014 at 09:47:21AM -0800, Quentin Colombet wrote:<br><blockquote type="cite"><br>On Feb 18, 2014, at 9:37 AM, Quentin Colombet <<a href="mailto:qcolombet@apple.com">qcolombet@apple.com</a>> wrote:<br><br><blockquote type="cite">Hi Tom,<br><br>On Feb 18, 2014, at 9:21 AM, Tom Stellard <<a href="mailto:tom@stellard.net">tom@stellard.net</a>> wrote:<br><br><blockquote type="cite">Hi Quentin,<br><br>Sorry I missed this on the first time around:<span class="Apple-converted-space"> </span><br><br><blockquote type="cite">--- a/lib/Transforms/Scalar/CodeGenPrepare.cpp<br>+++ b/lib/Transforms/Scalar/CodeGenPrepare.cpp<br>@@ -1728,6 +1730,35 @@<br>TypePromotionHelper::promoteOperandForOther(Instruction *SExt,<br>return SExtOpnd;<br>}<br><br>+/// IsPromotionProfitable - Check whether or not promoting an<br>instruction<br>+/// to a wider type was profitable.<br>+/// \p MatchedSize gives the number of instructions that have been<br>matched<br>+/// in the addressing mode after the promotion was applied.<br>+/// \p SizeWithPromotion gives the number of created instructions for<br>+/// the promotion plus the number of instructions that have been<br>+/// matched in the addressing mode before the promotion.<br>+/// \p PromotedOperand is the value that has been promoted.<br>+/// \return True if the promotion is profitable, false otherwise.<br>+bool<br>+AddressingModeMatcher::IsPromotionProfitable(unsigned MatchedSize,<br>+                                             unsigned SizeWithPromotion,<br>+                                             Value *PromotedOperand) const {<br>+  // We folded less instructions than what we created to promote the operand.<br>+  // This is not profitable.<br>+  if (MatchedSize < SizeWithPromotion)<br>+    return false;<br>+  if (MatchedSize > SizeWithPromotion)<br>+    return true;<br>+  // The promotion is neutral but it may help folding the signextension in<br>+  // loads for instance.<br>+  // Check that we did not create an illegal instruction.<br>+  Instruction *PromotedInst = dyn_cast<Instruction>(PromotedOperand);<br>+  if (!PromotedInst)<br>+    return false;<br>+  return TLI.isOperationLegalOrCustom(PromotedInst->getOpcode(),<br>+                                      EVT::getEVT(PromotedInst->getType()));<br></blockquote><br>This won't work, because the IR Instructions and SelectionDAG Opcodes<br>have different enumeration values.<br></blockquote>Right, good catch!<br><br><blockquote type="cite">The original test case must have<br>passed, because it is using a default TargetLowering implementation<br>rather than the one from R600.<br><br>I've attached an updated version of the original test case which compiles<br>the program using llc and triggers the bug again.<br><br>I couldn't find other transforms that use the isOperation* callbacks, so<br>I think you may have to add a function to convert from IR Instruction to<br>SelectionDAG Opcodes or implement this some other way.<br></blockquote>I think a specific hook in TargetLowering may be the best approach here.<br>Let me see what I can come up with.<br>If you have ideas on the naming, let me know :).<br></blockquote>In fact, we may be able to use this:<br>int TargetLoweringBase::InstructionOpcodeToISD(unsigned Opcode)const<br></blockquote><br>Oh, I didn't see that.  That should work.<br></blockquote>Almost there.<br>I am seeing a link error when creating the bugpoint executable.<br><br>llvm[2]: Linking Release executable bugpoint (without symbols)<br>Undefined symbols for architecture x86_64:<br>"llvm::TargetLoweringBase::InstructionOpcodeToISD(unsigned int) const", referenced from:<br>    (anonymous namespace)::AddressingModeMatcher::MatchOperationAddr(llvm::User*, unsigned int, unsigned int, bool*) in libLLVMScalarOpts.a(CodeGenPrepare.o)<br>ld: symbol(s) not found for architecture x86_64<br><br>The thing that I do not understand is why the linker is not find this function, whereas it does not complain about TargetLoweringBase::isLegalAddressingMode.<br>I may have missed something obvious, but I do not see it.<br></blockquote><br>I'm not seeing this error on my machine.  What build system are you<br>using?<br></blockquote>Makefile on Mac OS.<br><br><blockquote type="cite">Did you try running make clean first?<br></blockquote>I’ve tried but it does not seem to make the trick.<br><br>Could you try the attached patch?<br><br></blockquote><br>I've tested this and it builds fine for me on Linux with autoconf<br>and it also fixes the testcase.<br><br>-Tom<br><br><blockquote type="cite">Thanks,<br>-Quentin<br><br><blockquote type="cite"><br>-Tom<br><br><blockquote type="cite"><br>Any idea?<br><br>Thanks,<br>-Quentin<br><blockquote type="cite"><br>-Tom<br><blockquote type="cite"><br><blockquote type="cite"><br>Cheers,<br>Quentin<br><blockquote type="cite"><br>Thanks,<br>Tom<br><update-cgp-test.case.diff><br></blockquote><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></div></blockquote></div><br></div></body></html>