<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 1, 2017, at 10:20 AM, Hal Finkel <<a href="mailto:hfinkel@anl.gov" class="">hfinkel@anl.gov</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
  
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" class="">
  
  <div bgcolor="#FFFFFF" text="#000000" class=""><p class=""><br class="">
    </p>
    <div class="moz-cite-prefix">On 08/01/2017 11:54 AM, David Blaikie
      wrote:<br class="">
    </div>
    <blockquote cite="mid:CAENS6EvM7VPmpJZg6CDwzSvYSide9ByFvQB5cSAKBneu+PewTA@mail.gmail.com" type="cite" class="">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" class="">
      <div dir="ltr" class=""><br class="">
        <br class="">
        <div class="gmail_quote">
          <div dir="ltr" class="">On Tue, Aug 1, 2017 at 9:43 AM Hal Finkel <<a moz-do-not-send="true" href="mailto:hfinkel@anl.gov" class="">hfinkel@anl.gov</a>>
            wrote:<br class="">
          </div>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div bgcolor="#FFFFFF" text="#000000" class=""><p class=""><br class="">
              </p>
              <div class="m_838875341229329508moz-cite-prefix">On
                08/01/2017 11:28 AM, Adrian Prantl via llvm-commits
                wrote:<br class="">
              </div>
              <blockquote type="cite" class=""> <br class="">
                <div class="">
                  <blockquote type="cite" class="">
                    <div class="">On Aug 1, 2017, at 9:24 AM, David Blaikie <<a moz-do-not-send="true" href="mailto:dblaikie@gmail.com" target="_blank" class="">dblaikie@gmail.com</a>>
                      wrote:</div>
                    <br class="m_838875341229329508Apple-interchange-newline">
                    <div class="">
                      <div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class="">
                        <br class="">
                        <div class="gmail_quote">
                          <div dir="ltr" class="">On Tue, Aug 1, 2017 at 9:04 AM
                            Adrian Prantl via Phabricator <<a moz-do-not-send="true" href="mailto:reviews@reviews.llvm.org" target="_blank" class="">reviews@reviews.llvm.org</a>>
                            wrote:<br class="">
                          </div>
                          <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">aprantl
                            added inline comments.<br class="">
                            <br class="">
                            <br class="">
                            ================<br class="">
                            Comment at:
                            lib/Transforms/IPO/GlobalOpt.cpp:1577<br class="">
                            +  for(auto *GV : GVs)<br class="">
                            +    NewGV->addDebugInfo(GV);<br class="">
                            +<br class="">
                            ----------------<br class="">
                            NikolaPrica wrote:<br class="">
                            > aprantl wrote:<br class="">
                            > > I'm not familiar with this
                            transformation: Do we need to add a
                            DIExpression to mask out all but the first
                            bit (i.e. can multiple bools be packed into
                            the same uint32_t such that it could confuse
                            debuggers)?<br class="">
                            > The debug info which is provided here
                            with addDebugInfo later generates address of
                            the variable (DW_OP_addr: xxxx) in
                            DW_AT_location. If we provide here metadata
                            which is for 1byte variable  the debugger
                            would get confused because the enum type is
                            written as 4-byte and he would try to read 4
                            bytes. This is just temporary fix until
                            proper way to handle this is found.<br class="">
                            If I understood you correctly then the best
                            way to represent this would be a
                            `DW_OP_LLVM_fragment /*offset*/0
                            /*bitsize*/1 (or 8?)`<br class="">
                            expression. This will get lowered into a
                            DW_OP_bit_piece to tell the debugger that
                            this location is describing of the first n
                            bits of the variable.<br class="">
                          </blockquote>
                          <div class=""><br class="">
                            A slight problem with this is that at least
                            GDB won't print a single value if it's
                            partially unavailable (eg: if it's a struct
                            and the fragment describes one member but
                            not the othe,r I think that's OK - but if
                            it's a single int and only one out of 4
                            bytes are described - well, the value is
                            known/unknowable).<br class="">
                            <br class="">
                          </div>
                        </div>
                      </div>
                    </div>
                  </blockquote>
                  <div class=""><br class="">
                  </div>
                  <div class="">A debugger would have to print the value as
                    something like 0x??????01 to indicate that pieces
                    are missing. But no debugger I'm aware of does that.</div>
                  <br class="">
                  <blockquote type="cite" class="">
                    <div class="">
                      <div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">
                        <div class="gmail_quote">
                          <div class="">If this optimization is really based on
                            the proof that the other bytes are unused,
                            never written to or read, then a fragment
                            describing the other bytes as constant zero
                            would be good to have as well.<br class="">
                          </div>
                        </div>
                      </div>
                    </div>
                  </blockquote>
                </div>
              </blockquote>
              <br class="">
            </div>
            <div bgcolor="#FFFFFF" text="#000000" class=""> No, it is more
              complicated than that. See TryToShrinkGlobalToBoolean in
              lib/Transforms/IPO/GlobalOpt.cpp. It is looking for cases
              where the global is only set to one initialized value and
              one other value. In that case, it can make a Boolean
              global and replace uses of that Global with selects over
              that value.</div>
          </blockquote>
          <div class=""><br class="">
            Oh, wait - you mean a variable with value 42 and 87 gets
            collapsed to a boolean where true/1 is used to represent 42
            and false/0 is used to represent 87?<br class="">
          </div>
        </div>
      </div>
    </blockquote>
    <br class="">
    Yes. The code does this:<br class="">
    <br class="">
          // Change the load into a load of bool then a select.<br class="">
          LoadInst *LI = cast<LoadInst>(UI);<br class="">
          LoadInst *NLI = new LoadInst(NewGV, LI->getName()+".b",
    false, 0,<br class="">
                                       LI->getOrdering(),
    LI->getSyncScopeID(), LI);<br class="">
          Value *NSI;<br class="">
          if (IsOneZero)<br class="">
            NSI = new ZExtInst(NLI, LI->getType(), "", LI);<br class="">
          else<br class="">
            NSI = SelectInst::Create(NLI, OtherVal, InitVal, "", LI);<br class="">
          NSI->takeName(LI);<br class="">
          LI->replaceAllUsesWith(NSI);<br class=""></div></div></blockquote><div><br class=""></div><div>Whoa — this is going to be fun! A DWARF expression for that example might look like:</div><div><br class=""></div><div>DW_OP_constu 42 DW_OP_mul DW_OP_dup DW_OP_bra +2 DW_OP_skip +<end-1> DW_OP_constu 87 DW_OP_constu DW_OP_stack_value </div><div><br class=""></div><div>roughly: if (Val * 42) return Val * 42; else return 87;</div><div><br class=""></div><div>-- adrian</div><blockquote type="cite" class=""><div class=""><div bgcolor="#FFFFFF" text="#000000" class="">
    <br class="">
     -Hal<br class="">
    <br class="">
    <blockquote cite="mid:CAENS6EvM7VPmpJZg6CDwzSvYSide9ByFvQB5cSAKBneu+PewTA@mail.gmail.com" type="cite" class="">
      <div dir="ltr" class="">
        <div class="gmail_quote">
          <div class=""><br class="">
            Oh. Yeah. That's a bit more involved. (but nice that it
            means we can represent the values exactly - hopefully)<br class="">
            <br class="">
            Thanks!<br class="">
             </div>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div bgcolor="#FFFFFF" text="#000000" class=""> I think you actually
              want to generate a DWARF expression for these.<br class="">
              <br class="">
               -Hal<br class="">
              <br class="">
            </div>
            <div bgcolor="#FFFFFF" text="#000000" class="">
              <blockquote type="cite" class="">
                <div class="">
                  <div class=""><br class="">
                  </div>
                  Agreed, that would be the most practical solution — if
                  we can prove that it is correct.</div>
                <div class=""><br class="">
                </div>
                <div class="">-- adrian<br class="">
                  <blockquote type="cite" class="">
                    <div class="">
                      <div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">
                        <div class="gmail_quote">
                          <div class=""><br class="">
                            But I doubt that's the case - no doubt if we
                            can see all the reads and writes, we
                            optimize away the writes if we know they
                            won't be read, so we may end up with only
                            the one byte. C'est la vie.<br class="">
                            <br class="">
                            Just mention it to check/understand what the
                            optimization is/isn't doing, etc.<br class="">
                             </div>
                          <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br class="">
                            <br class="">
                            <a moz-do-not-send="true" href="https://reviews.llvm.org/D35994" rel="noreferrer" target="_blank" class="">https://reviews.llvm.org/D35994</a></blockquote>
                        </div>
                      </div>
                    </div>
                  </blockquote>
                </div>
                <br class="">
                <br class="">
                <fieldset class="m_838875341229329508mimeAttachmentHeader"></fieldset>
                <br class="">
                <pre class="">_______________________________________________
llvm-commits mailing list
<a moz-do-not-send="true" class="m_838875341229329508moz-txt-link-abbreviated" href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>
<a moz-do-not-send="true" class="m_838875341229329508moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a>
</pre>
              </blockquote>
            </div>
            <div bgcolor="#FFFFFF" text="#000000" class=""> <br class="">
              <pre class="m_838875341229329508moz-signature" cols="72">-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
            </div>
          </blockquote>
        </div>
      </div>
    </blockquote>
    <br class="">
    <pre class="moz-signature" cols="72">-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
  </div>

</div></blockquote></div><br class=""></body></html>