<div dir="ltr">I noticed this too and I'm not sure why <a class="" href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_doxygen_html_ScheduleDAGInstrs-5F8cpp.html-23a25fe0578f0a0e48d63fcf4ab7a892dd5&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=Qmh_U6A4Y7gzPc4Y8NSCF5_YztpM9EtWVAw3zyHhQT4&s=3MZWsDoVRnQ3VR4xSL4KimNSl6b6L37uOq-zF0LsSTE&e=" style="font-family:monospace,fixed;font-size:9pt;line-height:15px;color:rgb(70,101,162);text-decoration:none">isUnsafeMemoryObject</a> returns true for such simple array access. But before reaching that check, you should hit <div><br></div><div><pre class="" style="font-family:monospace,fixed;font-size:9pt;border:1px solid rgb(196,207,229);padding:4px 6px;margin:4px 8px 4px 2px;overflow:auto;word-wrap:break-word;line-height:15px;color:rgb(0,0,0);background-color:rgb(251,252,253)"> <span class="" style="color:rgb(128,0,0)">// Let the target decide if memory accesses cannot possibly overlap.</span>
<a name="l00527" style="color:rgb(61,87,140)"></a>00527 <span class="" style="color:rgb(224,128,0)">if</span> ((MIa-><a class="" href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_doxygen_html_classllvm-5F1-5F1MachineInstr.html-23a2b48451e9cc8433ed5f8ee30462cc96e&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=Qmh_U6A4Y7gzPc4Y8NSCF5_YztpM9EtWVAw3zyHhQT4&s=PmIifiWZh87AXlO5GhAoXOmrpkCj1E0WuwxFXNqqrE8&e=" title="Return true if this instruction could possibly read memory." style="color:rgb(70,101,162);text-decoration:none">mayLoad</a>() || MIa-><a class="" href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_doxygen_html_classllvm-5F1-5F1MachineInstr.html-23aa5f0eb2aad4a731d5d5133b8cb5e0a98&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=Qmh_U6A4Y7gzPc4Y8NSCF5_YztpM9EtWVAw3zyHhQT4&s=xUj8_-S0KyymhUi9f8a8tJqtEHZzY6CmGO6CdLgkTQ8&e=" title="Return true if this instruction could possibly modify memory." style="color:rgb(70,101,162);text-decoration:none">mayStore</a>()) &&
<a name="l00528" style="color:rgb(61,87,140)"></a>00528 (MIb-><a class="" href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_doxygen_html_classllvm-5F1-5F1MachineInstr.html-23a2b48451e9cc8433ed5f8ee30462cc96e&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=Qmh_U6A4Y7gzPc4Y8NSCF5_YztpM9EtWVAw3zyHhQT4&s=PmIifiWZh87AXlO5GhAoXOmrpkCj1E0WuwxFXNqqrE8&e=" title="Return true if this instruction could possibly read memory." style="color:rgb(70,101,162);text-decoration:none">mayLoad</a>() || MIb-><a class="" href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_doxygen_html_classllvm-5F1-5F1MachineInstr.html-23aa5f0eb2aad4a731d5d5133b8cb5e0a98&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=Qmh_U6A4Y7gzPc4Y8NSCF5_YztpM9EtWVAw3zyHhQT4&s=xUj8_-S0KyymhUi9f8a8tJqtEHZzY6CmGO6CdLgkTQ8&e=" title="Return true if this instruction could possibly modify memory." style="color:rgb(70,101,162);text-decoration:none">mayStore</a>()))
<a name="l00529" style="color:rgb(61,87,140)"></a>00529 <span class="" style="color:rgb(224,128,0)">if</span> (TII-><a class="" href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_doxygen_html_classllvm-5F1-5F1TargetInstrInfo.html-23a255c4fa466c5f2ba7e52f67296834de8&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=Qmh_U6A4Y7gzPc4Y8NSCF5_YztpM9EtWVAw3zyHhQT4&s=hlB6rEI71Ch7WQ5iXdBZYsPcir4_xbXA0-uzkm7uoOs&e=" style="color:rgb(70,101,162);text-decoration:none">areMemAccessesTriviallyDisjoint</a>(MIa, MIb, AA))
<a name="l00530" style="color:rgb(61,87,140)"></a>00530 <span class="" style="color:rgb(224,128,0)">return</span> <span class="" style="color:rgb(0,128,0)">false</span>;</pre></div><div><br></div><div>Here your target could override areMemAcdessesTriviallyDisjoint() function to make it work, at least for the example you gave.</div><div><br></div><div>Patrick</div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-07-01 15:08 GMT-04:00 Johnson, Nicholas Paul <span dir="ltr"><<a href="mailto:Nicholas.Paul.Johnson@deshawresearch.com" target="_blank">Nicholas.Paul.Johnson@deshawresearch.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
While tuning the MIScheduler for my target, I discovered a code that unnecessarily restricts the scheduler. I think this is a bug, but I would appreciate a second opinion.<br>
<br>
<br>
In file ScheduleDAGInstrs.cpp, the function MIsNeedChainEdge determines whether two MachineInstrs are ordered by a memory dependence. It first runs through the standard criteria (Do both instructions access memory? Does at least one store to memory? Is either access volatile? etc.), and finally queries AliasAnalysis if available.<br>
<br>
Before reaching alias analysis, however, function isUnsafeMemoryObject pessimizes the result. In particular, isUnsafeMemoryObject returns true unless all of the pointer's underlying objects satisfy IsIdentifiedObject. This forces MIsNeedChainEdge to conservatively report true, even though AliasAnalysis could give a more precise answer in some situations. Further, it is unclear why this test even exists: it does not attempt to compare the underlying object sets to test for an alias, and the volatility check should cover all this-object-is-not-quite-memory situations.<br>
<br>
As a simple example of why this matters, suppose that you have a function like this:<br>
void doit(int *baseptr) {<br>
baseptr[0] = 1; // store 1<br>
baseptr[1] = 2; // store 2<br>
}<br>
<br>
In this example, stores 1 and 2 can be freely re-ordered. However, isUnsafeMemoryObject reports true because the underlying objects (formal parameter 'baseptr') do not satisfy IsIdentifiedObject. Nonetheless, BasicAliasAnalysis can show that derived pointers &baseptr[0] and &baseptr[1] are disjoint.<br>
<br>
<br>
Proposed solution:<br>
- If MIsNeedChainEdge is invoked without alias analysis (AA=nullptr), behavior should be unchanged.<br>
- Otherwise, isUnsafeMemoryObject should not test for identified objects.<br>
- A minimal patch appears at the end of this email.<br>
<br>
<br>
Thanks,<br>
Nick Johnson<br>
D. E. Shaw Research<br>
<br>
<br>
<br>
diff --git a/lib/CodeGen/ScheduleDAGInstrs.cpp b/lib/CodeGen/ScheduleDAGInstrs.cpp<br>
index 390b6d2..fcf43ca 100644<br>
--- a/lib/CodeGen/ScheduleDAGInstrs.cpp<br>
+++ b/lib/CodeGen/ScheduleDAGInstrs.cpp<br>
@@ -475,7 +475,8 @@ static inline bool isGlobalMemoryObject(AliasAnalysis *AA, MachineInstr *MI) {<br>
// to deal with (i.e. volatile object).<br>
static inline bool isUnsafeMemoryObject(MachineInstr *MI,<br>
const MachineFrameInfo *MFI,<br>
- const DataLayout &DL) {<br>
+ const DataLayout &DL,<br>
+ AliasAnalysis *AA) {<br>
if (!MI || MI->memoperands_empty())<br>
return true;<br>
// We purposefully do no check for hasOneMemOperand() here<br>
@@ -497,6 +498,7 @@ static inline bool isUnsafeMemoryObject(MachineInstr *MI,<br>
if (!V)<br>
return true;<br>
<br>
+ if (!AA) {<br>
SmallVector<Value *, 4> Objs;<br>
getUnderlyingObjects(V, Objs, DL);<br>
for (Value *V : Objs) {<br>
@@ -504,6 +506,7 @@ static inline bool isUnsafeMemoryObject(MachineInstr *MI,<br>
if (!isIdentifiedObject(V))<br>
return true;<br>
}<br>
+ }<br>
<br>
return false;<br>
}<br>
@@ -533,7 +536,7 @@ static bool MIsNeedChainEdge(AliasAnalysis *AA, const MachineFrameInfo *MFI,<br>
if (!MIa->hasOneMemOperand() || !MIb->hasOneMemOperand())<br>
return true;<br>
<br>
- if (isUnsafeMemoryObject(MIa, MFI, DL) || isUnsafeMemoryObject(MIb, MFI, DL))<br>
+ if (isUnsafeMemoryObject(MIa, MFI, DL, AA) || isUnsafeMemoryObject(MIb, MFI, DL, AA))<br>
return true;<br>
<br>
// If we are dealing with two "normal" loads, we do not need an edge<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" rel="noreferrer" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div>