<div dir="ltr"><div>I understand the problem. Can't offer any useful help - most likely, you need to add some code to help the instruction selection or some such... but it's not an area that I'm familiar with...<br><br>--<br></div>Mats<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 15 June 2017 at 12:06, 陳韋任 <span dir="ltr"><<a href="mailto:chenwj.cs97g@g2.nctu.edu.tw" target="_blank">chenwj.cs97g@g2.nctu.edu.tw</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Hi Mats,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> It's private backend. I will try describing what I am dealing with.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> struct S {</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> unsigned int a : 8;</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> unsigned int b : 8;</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> unsigned int c : 8;</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> unsigned int d : 8;</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> unsigned int e;</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> }</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">We want to read S->b for example. The size of struct S is 64 bits, and seems LLVM treats it as i64.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Below is the IR corresponding to S->b, IIRC. </div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> %0 = load i64, *i64 ptr, align 4;</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> %1 = %0 lshr 8;</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> %2 = %1 and 255;</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Our target doesn't support load i64, so we have following code in XXXISelLowering.cpp</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> setOperationAction(ISD::<wbr>LOAD, MVT::i64, Custom);</div>
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> </div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Transform load i64 to load v2i32 during type legalization. During op legalization, load v2i32</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">is found unaligned (4 v.s. 8), so stack load/store instructions are generated. This is one problem.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Besides of that, our target has bitset/bitextract instructions, we want to use them on bitfield</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">access, too. But don't know how to do that.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Thanks.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Regards,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">chenwj</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">2017-06-15 0:10 GMT+08:00 mats petersson <span dir="ltr"><<a href="mailto:mats@planetcatfish.com" target="_blank">mats@planetcatfish.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Would probably help if you explained which backend you are working on (assuming it's a publicly available one). An example, with source that can be compiled by "anyone", along with the generated "bad code" and what you expect to see as "good code" would also help a lot.<br><br></div>From the things I've seen, it's not noticeably worse (or better) than other compilers. But it's not an area that I've spent a LOT of time on, and the combination of generic LLVM operations and the target implementation will determine the outcome - there are lots of clever tricks one can do at the machine-code level, that LLVM can't "know" in generic ways, since it's dependent on specific instructions. Most of my experience comes from x86 and ARM, both of which are fairly well established architectures with a good amount of people supporting the code-gen part. If you are using a different target, there may be missing target optimisations that the compiler could do.<br><br></div><div>I probably can't really help, just trying to help you make the question as clear as possible, so that those who may be able to help have enough information to work on.<br></div><div><br>--<br></div>Mats<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_156452401689228124h5">On 14 June 2017 at 13:57, 陳韋任 via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_156452401689228124h5"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Hi All,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> Is there known issue that LLVM is bad at codegen for some language structure, say C bitfield?</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Our custom backend generates inefficient code for bitfield access, so I am wondering where</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">should I look into first.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> Thanks.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Regards,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">chenwj</div><span class="m_156452401689228124m_9124155536079118788HOEnZb"><font color="#888888"><div><br></div>-- <br><div class="m_156452401689228124m_9124155536079118788m_-1292604874368495331gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Wei-Ren Chen (陳韋任)<br>Homepage: <a href="https://people.cs.nctu.edu.tw/~chenwj" target="_blank">https://people.cs.nctu.edu.tw/<wbr>~chenwj</a></div></div></div>
</font></span></div>
<br></div></div>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="m_156452401689228124gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Wei-Ren Chen (陳韋任)<br>Homepage: <a href="https://people.cs.nctu.edu.tw/~chenwj" target="_blank">https://people.cs.nctu.edu.tw/<wbr>~chenwj</a></div></div></div>
</div>
</div></div></blockquote></div><br></div>