<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="">Without the -disable-simplify-libcalls option, opt generates a call to memset intrinsic, and llc in turn generates a call to __eabi_memset that remains unsolved. That is why I think that compiler-rt is needed here.<div class=""><br class=""></div><div class="">I have change the global declaration to :</div><div class="">;———</div><div class=""><div class="">@__bss_start = external global i32</div><div class="">@__bss_end   = weak global i32 0</div><div class="">;———</div><div class=""><br class=""></div><div class="">But no change : the optimized code is still a repeat until.</div><div class=""><br class=""></div><div class="">I have also tried without success :</div><div class=""><div class="">;———</div><div class=""><div class="">@__bss_start = extern_weak global i32</div><div class="">@__bss_end   = extern_weak global i32</div><div class="">;———</div></div></div><div class=""><br class=""></div><div class="">Regards,</div><div class=""><br class=""></div><div class="">Pierre Molinaro</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">Le 28 août 2015 à 17:34, John Criswell <<a href="mailto:jtcriswel@gmail.com" class="">jtcriswel@gmail.com</a>> a écrit :</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="">
    <div class="moz-cite-prefix">On 8/28/15 11:31 AM, devh8h wrote:<br class="">
    </div>
    <blockquote cite="mid:15FD05C4-C970-476D-BD77-0035D3DFCE40@free.fr" type="cite" class="">
      <meta http-equiv="Context-Type" content="text/html; charset=utf-8" class="">
      <div class="">
        <div class="">I had thought to use the memset
          intrinsic, unfortunately I did not succeed to cross compiling
          compiler-rt on my Mac.</div>
      </div>
    </blockquote>
    <br class="">
    I don't think you need compiler-rt to use the memset intrinsic.  I
    think the code generator will generate efficient inline code for it
    (though I'm not certain).<br class="">
    <br class="">
    In any event, Joerg's suggestion of making one external weak sounds
    a lot easier.<br class="">
    :)<br class="">
    <br class="">
    Regards,<br class="">
    <br class="">
    John Criswell<br class="">
    <br class="">
    <blockquote cite="mid:15FD05C4-C970-476D-BD77-0035D3DFCE40@free.fr" type="cite" class="">
      <div class="">
        <div class=""><br class="">
        </div>
        <div class="">Regards,</div>
        <div class=""><br class="">
        </div>
        <div class="">Pierre Molinaro</div>
        <div class=""><br class="">
        </div>
        <div class=""><br class="">
        </div>
        <br class="">
        <blockquote type="cite" class="">
          <div class="">Le 28 août 2015 à 17:22, John Criswell <<a moz-do-not-send="true" href="mailto:jtcriswel@gmail.com" class=""></a><a class="moz-txt-link-abbreviated" href="mailto:jtcriswel@gmail.com">jtcriswel@gmail.com</a>> a écrit :</div>
          <br class="Apple-interchange-newline">
          <div class="">On 8/28/15 11:20 AM, devh8h wrote:<br class="">
            <blockquote type="cite" class="">It is a very basic
              "blink-led" program, on a Teensy 3.1. There is no
              operating system. The BSS clear function is called at
              boot. I would write a general BSS clear function, that
              behaves correctly even if the BSS section is empty.<br class="">
            </blockquote>
            <br class="">
            I thought it was something like that.<br class="">
            <br class="">
            Let me know if the memset intrinsic approach works.<br class="">
            <br class="">
            Regards,<br class="">
            <br class="">
            John Criswell<br class="">
            <br class="">
            <blockquote type="cite" class=""><br class="">
              Thank,<br class="">
              <br class="">
              Pierre Molinaro<br class="">
              <br class="">
              <blockquote type="cite" class="">Le 28 août 2015 à 17:00,
                John Criswell <<a moz-do-not-send="true" href="mailto:jtcriswel@gmail.com" class="">jtcriswel@gmail.com</a>>
                a écrit :<br class="">
                <br class="">
                On 8/28/15 10:52 AM, devh8h via llvm-dev wrote:<br class="">
                <blockquote type="cite" class="">Hi,<br class="">
                  <br class="">
                  I am writing a function that clears the BSS section on
                  an Cortex-M4 embedded system.<br class="">
                </blockquote>
                I assume that, for some reason, the operating system is
                not demand-paging in zeroed memory.  Is that correct?<br class="">
                <br class="">
                <blockquote type="cite" class="">The LLVM (version
                  3.7.0rc3) code I had wrote  is :<br class="">
                  ;------------<br class="">
                  target datalayout =
                  "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"<br class="">
                  target triple = "thumbv7em-none--eabi"<br class="">
                  <br class="">
                  @__bss_start = external global i32<br class="">
                  @__bss_end   = external global i32<br class="">
                  <br class="">
                  define void @clearBSS () nounwind {<br class="">
                  entry:<br class="">
                    br label %bssLoopTest<br class="">
                   bssLoopTest:<br class="">
                    %p = phi i32* [@__bss_start, %entry], [%p.next,
                  %bssLoop]<br class="">
                    %completed = icmp eq i32* %p, @__bss_end<br class="">
                    br i1 %completed, label %clearCompleted, label
                  %bssLoop<br class="">
                   bssLoop:<br class="">
                    store i32 0, i32* %p, align 4<br class="">
                    %p.next = getelementptr inbounds i32, i32* %p, i32 1<br class="">
                    br label %bssLoopTest<br class="">
                   clearCompleted:<br class="">
                    ret void<br class="">
                  }<br class="">
                  ;------------<br class="">
                  <br class="">
                  This code runs. But when I optimize it with :<br class="">
                  <span class="Apple-tab-span"> </span>opt
                  -disable-simplify-libcalls -Os -S source.ll -o
                  optimized.ll<br class="">
                  <br class="">
                  I get the following code for the @clearBSS function :<br class="">
                  ;------------<br class="">
                  define void @clearBSS() nounwind {<br class="">
                  entry:<br class="">
                    br label %bssLoop<br class="">
                  <br class="">
                  bssLoop:                                          ;
                  preds = %entry, %bssLoop<br class="">
                    %p1 = phi i32* [ @__bss_start, %entry ], [ %p.next,
                  %bssLoop ]<br class="">
                    store i32 0, i32* %p1, align 4<br class="">
                    %p.next = getelementptr inbounds i32, i32* %p1, i32
                  1<br class="">
                    %completed = icmp eq i32* %p.next, @__bss_end<br class="">
                    br i1 %completed, label %clearCompleted, label
                  %bssLoop<br class="">
                  <br class="">
                  clearCompleted:                                   ;
                  preds = %bssLoop<br class="">
                    ret void<br class="">
                  }<br class="">
                  ;------------<br class="">
                  The optimizer has transformed the while loop into a
                  repeat until.<br class="">
                  <br class="">
                  I think it assumes the two variables @__bss_start and
                  @__bss_end are distinct. But they are solved at link
                  time, and they are the same if the BSS section is
                  empty : in this case, the optimized function fails.<br class="">
                  <br class="">
                  Is there a way to prevent the optimizer to assume the
                  two variables are distinct ? Or what is the proper way
                  to deal with link time values ?<br class="">
                </blockquote>
                Have you tried using the memset intrinsic?  You could
                case bss_start and bss_end to integers, subtract them to
                find the length, and then use memset to zero the memory.
                 I would think memset should work if the length is zero.<br class="">
                <br class="">
                Regards,<br class="">
                <br class="">
                John Criswell<br class="">
                <br class="">
                <blockquote type="cite" class="">Thanks,<br class="">
                  <br class="">
                  Pierre Molinaro<br class="">
                  <br class="">
                  _______________________________________________<br class="">
                  LLVM Developers mailing list<br class="">
                  <a moz-do-not-send="true" href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="">
                </blockquote>
                <br class="">
                -- <br class="">
                John Criswell<br class="">
                Assistant Professor<br class="">
                Department of Computer Science, University of Rochester<br class="">
                <a moz-do-not-send="true" href="http://www.cs.rochester.edu/u/criswell" class="">http://www.cs.rochester.edu/u/criswell</a><br class="">
                <br class="">
              </blockquote>
            </blockquote>
            <br class="">
            <br class="">
            -- <br class="">
            John Criswell<br class="">
            Assistant Professor<br class="">
            Department of Computer Science, University of Rochester<br class="">
            <a moz-do-not-send="true" href="http://www.cs.rochester.edu/u/criswell" class="">http://www.cs.rochester.edu/u/criswell</a><br class="">
            <br class="">
          </div>
        </blockquote>
      </div>
      <br class="">
    </blockquote>
    <br class="">
    <br class="">
    <pre class="moz-signature" cols="72">-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a class="moz-txt-link-freetext" href="http://www.cs.rochester.edu/u/criswell">http://www.cs.rochester.edu/u/criswell</a></pre>
  </div>

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