<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Here is the complete IR I am dealing with, if that helps discussion.</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">







<p class="gmail-p1">-------------------------------------------------------------</p><p class="gmail-p1"><span class="gmail-s1">    %struct.A = type { %struct.Z*, %struct.Z*, %struct.Z*, %struct.Z*, %struct.Z* }</span></p><p class="gmail-p1"><span class="gmail-s1">    %struct.Z = type { %union.X, [180 x %union.Y] }</span></p><p class="gmail-p1"><span class="gmail-s1">    %union.X = type { %struct.anon }</span></p><p class="gmail-p1"><span class="gmail-s1">    %struct.anon = type { i64 }</span></p><p class="gmail-p1"><span class="gmail-s1">    %union.Y = type { %struct.anon.0 }</span></p><p class="gmail-p1"><span class="gmail-s1">    %struct.anon.0 = type { i32 }</span></p><p class="gmail-p1"><span class="gmail-s1">    %struct.D = type { i64 }</span></p><p class="gmail-p2"><span class="gmail-s1"></span><br></p><p class="gmail-p1"><span class="gmail-s1">    ; Function Attrs: norecurse nounwind</span></p><p class="gmail-p1"><span class="gmail-s1">    define void @func(%struct.A* noalias nocapture readonly %a, %struct.D* noalias nocapture readonly %d) local_unnamed_addr #0 {</span></p><p class="gmail-p1"><span class="gmail-s1">    entry:</span></p><p class="gmail-p1"><span class="gmail-s1">      %a2 = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 1</span></p><p class="gmail-p1"><span class="gmail-s1">      %0 = load %struct.Z*, %struct.Z** %a2, align 4, !tbaa !1</span></p><p class="gmail-p1"><span class="gmail-s1">      %1 = getelementptr inbounds %struct.D, %struct.D* %d, i32 0, i32 0</span></p><p class="gmail-p1"><span class="gmail-s1">      %bf.load = load i64, i64* %1, align 4</span></p><p class="gmail-p1"><span class="gmail-s1">      %bf.lshr = lshr i64 %bf.load, 8</span></p><p class="gmail-p1"><span class="gmail-s1">      %2 = trunc i64 %bf.lshr to i32</span></p><p class="gmail-p1"><span class="gmail-s1">      %bf.cast = and i32 %2, 255</span></p><p class="gmail-p1"><span class="gmail-s1">      %3 = getelementptr inbounds %struct.Z, %struct.Z* %0, i32 0, i32 1, i32 %bf.cast, i32 0, i32 0</span></p><p class="gmail-p1"><span class="gmail-s1">      %bf.load1 = load i32, i32* %3, align 4</span></p><p class="gmail-p1"><span class="gmail-s1">      %bf.clear2 = and i32 %bf.load1, 65535</span></p><p class="gmail-p1"><span class="gmail-s1">      store i32 %bf.clear2, i32* %3, align 4</span></p><p class="gmail-p1"><span class="gmail-s1">      ret void</span></p><p class="gmail-p1">






























</p><p class="gmail-p1"><span class="gmail-s1">    }</span></p><p class="gmail-p1"><span class="gmail-s1">-------------------------------------------------------------</span></p><p class="gmail-p1"><br></p><p class="gmail-p1">Regards,</p><p class="gmail-p1">chenwj</p></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-06-16 14:13 GMT+08:00 Ehsan Amiri via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><br><div class="gmail_extra">Forgot to reply to all<br><div class="gmail_quote"><br type="attribution"><blockquote class="m_3020434762619613146quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>Hi Eli<span class=""><div class="m_3020434762619613146quoted-text"><br><div class="gmail_extra"><br><div class="gmail_quote"><blockquote class="m_3020434762619613146m_-148379498413252890quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div text="#000000" bgcolor="#FFFFFF"><div class="m_3020434762619613146m_-148379498413252890quoted-text"><blockquote type="cite"><div dir="ltr"><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>
    </blockquote>
    <br></div>
    This looks fine.</div></blockquote></div></div></div></span></div><div dir="auto"><br></div><div dir="auto">Why can't we expect InstCombine to simplify this to an 8 bit load, assuming each of %0 and %1 has only one use ?</div><div dir="auto"><br></div><div dir="auto">Thanks</div><font color="#888888"><div dir="auto">Ehsan</div><div dir="auto"><br></div><div dir="auto"></div><div dir="auto"><div class="gmail_extra"><br></div></div></font></div>
</blockquote></div><br></div></div></div>
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">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><br clear="all"><div><br></div>-- <br><div class="gmail_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/~chenwj</a></div></div></div>
</div>