<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><base href="x-msg://906/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div><br></div><div> void SelectionDAGBuilder::visitTargetIntrinsic(const CallInst &I,</div></div><div>-                                               unsigned Intrinsic) {</div><div>-  bool HasChain = !I.doesNotAccessMemory();</div><div>-  bool OnlyLoad = HasChain && I.onlyReadsMemory();</div><div>+                                             unsigned Intrinsic) {</div><div>+  // Info is set by getTgtMemInstrinsic</div><div>+  TargetLowering::IntrinsicInfo Info;</div><div>+  bool IsTgtIntrinsic = TLI.getTgtMemIntrinsic(Info, I, Intrinsic);</div><div>+  bool HasChain = Info.readMem || Info.writeMem;</div><div>+  bool OnlyLoad = HasChain && Info.readMem;</div><div><br></div><div>This doesn't seem right. If a call is marked ReadNone, it doesn't seem legal to select it to an intrinsic that read / write memory. By definition a "ReadNone" function cannot touch memory, no? </div><div><br></div><div>Evan</div><div><br></div><div><div>On Nov 6, 2012, at 1:45 PM, "Villmow, Micah" <<a href="mailto:Micah.Villmow@amd.com">Micah.Villmow@amd.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div lang="EN-US" link="blue" vlink="purple" style="font-family: Helvetica; font-size: medium; 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; "><div class="WordSection1" style="page: WordSection1; "><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="border-style: none none none solid; border-left-width: 1.5pt; border-left-color: blue; padding: 0in 0in 0in 4pt; position: static; z-index: auto; "><div><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(181, 196, 223); padding: 3pt 0in 0in; "><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><b><span style="font-size: 10pt; font-family: Tahoma, sans-serif; ">From:</span></b><span style="font-size: 10pt; font-family: Tahoma, sans-serif; "><span class="Apple-converted-space"> </span>Villmow, Micah<span class="Apple-converted-space"> </span><br><b>Sent:</b><span class="Apple-converted-space"> </span>Tuesday, November 06, 2012 1:37 PM<br><b>To:</b><span class="Apple-converted-space"> </span>'<a href="mailto:llvm-dev@cs.uiuc.edu" style="color: purple; text-decoration: underline; ">llvm-dev@cs.uiuc.edu</a>'<br><b>Cc:</b><span class="Apple-converted-space"> </span>Guo, Xiaoyi<br><b>Subject:</b><span class="Apple-converted-space"> </span>Bug in SelectionDAG visitTargetIntrinsic<o:p></o:p></span></div></div></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">We ran into a problem where specifying IntrNoMem was causing our instruction selection to fail with target specific intrinsics. After looking into the code and ISel debug it looks like tablegen and SelectionDAG are using different criteria to generate code for intrinsic_w_chain vs intrinsic_wo_chain.<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">In CodeGenDAGPatterns.cpp, tablegen decides based on whether IntrNoMem is set or not. However with SelectionDAG, whether to use a chain or not is determined by the call site attributes and not by the intrinsic.<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">So, we can get the situation where the call site has a different attribute than the intrinsic, and this causes selection dag to fail.<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">I believe that this is wrong and that whether a chain should be generated or not should come from only the intrinsic and not the call site. Since the mapping of call -> intrinsic is by function name only, it should not matter if the readnone attribute is set or not as that is irrelevant to the code generator. Only what is set in the tablegen definition should be determine how the intrinsic is generated.<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">So, I'm proposing the following patch. What this patch does is instead of relying on the call site to determine if a chain is required, use instead the read/write attributes of the intrinsic from the backend instead. There is not much documentation on target intrinsics and no other backend uses them in this manner.<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">This patch sound good?<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">Thanks,<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">Micah<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div></div></div><span><target_intrinsic_incorrect_chain.txt></span>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu" style="color: purple; text-decoration: underline; ">LLVMdev@cs.uiuc.edu</a><span class="Apple-converted-space"> </span>        <a href="http://llvm.cs.uiuc.edu" style="color: purple; text-decoration: underline; ">http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" style="color: purple; text-decoration: underline; ">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br></div></blockquote></div><br></body></html>