<div dir="ltr"><div>Ahmed, </div><div><br></div><div>  It looks like shouldReduceLoadWidth is the best solution, since we can create override and just return false if the new size is 8, this should avoid generating LD1 in this case. I'm also seeing LD1 being generated by other opt functions in DAGCombiner, so I'm not sure this is a full solution for us, unless they are also generating LD1 via ReduceLoadWidth, I'm not sure yet.</div><div><br></div><div>  Though we are not yet using the version of LLVM that has the shouldReduceLoadWidth virtual function.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 3, 2015 at 2:08 PM, Ahmed Bougacha <span dir="ltr"><<a href="mailto:ahmed.bougacha@gmail.com" target="_blank">ahmed.bougacha@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>On Tue, Mar 3, 2015 at 10:35 AM, Ryan Taylor <<a href="mailto:ryta1203@gmail.com">ryta1203@gmail.com</a>> wrote:<br>
> I'm curious about this code in ReduceLoadWidth (and in DAGCombiner in<br>
> general):<br>
><br>
> if (LegalOperations && !TLI.isLoadExtLegal(ExtType, ExtVT))<br>
>    return SDValue();<br>
><br>
> LegalOperations is false for the first pre-legalize pass and true for the<br>
> post-legalize pass. The first pass is target-independent yes? So that makes<br>
> sense.<br>
><br>
> The issue we are having is this: we don't support 8 bit loads and we don't<br>
> support 8 bit extloads, so we end up with LD1 with zext after either the<br>
> first pass or the second pass (depending on the test case). If we add the<br>
> TargetLowering callback method setLoadExtAction(ISD::ZEXTLOAD, MVT::i8,<br>
> Expand) then it crashes during legalization<br>
<br>
</span>This part is surprising.  What happens?  This seems to me like the<br>
correct solution.<br>
<br>
I'm guessing it's because there's no good way to legalize 8 bit loads?<br>
 I have no idea what happens when those are illegal, as I'd expect<br>
them to be always available?<br>
<br>
<br>
Here's a cheap hack though: I see that ReduceLoadWidth is predicated on the<br>
TLI "shouldReduceLoadWidth" hook.  Did you try overriding that to<br>
avoid creating 8 bit loads?<br>
<span><br>
> and if we don't have that in<br>
> then it crashes during instruction selection.<br>
><br>
> There are two ways to fix this:<br>
><br>
> 1) Add the setLoadExtAction AND comment out 'LegalOperations &&' in the<br>
> conditional. (this solves the problem)<br>
><br>
> 2) Create a custom expand to undo the optimization added by ReduceLoadWidth.<br>
><br>
> The 2nd approach seems more in line with what LLVM infrastructure wants but<br>
> it seems silly to have to undo an optimization?<br>
><br>
> Essentially, we have some bit packing structures and the code is trying to<br>
> get the upper bits. The initial dag generates an LD2 with srl (which makes<br>
> sense, it's what we want). The DAGCombiner then goes in and changes that LD2<br>
> with srl to an LD1 zextload, which we don't support.<br>
><br>
> Why is LegalOperations really needed here? What is the purpose and point of<br>
> this? It seems you could eliminate this and be all the better for it.<br>
<br>
</span>FWIW I somewhat agree, and believe this is a common "problem":  we<br>
eagerly generate obviously-illegal nodes, because we're before<br>
legalisation, so it's OK, right?  Except, it's sometimes hard to<br>
recover from.  Most of the time, it's a good thing, precisely because<br>
it catches patterns that would be disturbed by legalization.<br>
<br>
Did you try running the integration tests - at least X86 - after<br>
changing the condition?<br>
<br>
-Ahmed<br>
<br>
> Thanks.<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" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
><br>
</blockquote></div><br></div>