<html><body>
<p><font size="2" face="Menlo-Regular">Hello,</font><br>
<br>
<font size="2" face="Menlo-Regular">I have some code that implements the memset() routine.  It appears that bgclang is getting (too) clever by detecting the setting-loop.  Once it detects this, it decides the "real" memset would be more efficient and calls that routine inplace of the setting-loop.  Very clever, but not optimal for me (and functionally incorrect since in the real code, it results in a recursive bomb calling memset repeatedly)</font><br>
<br>
<font size="2" face="Menlo-Regular">Is there a way to disable this feature?</font><br>
<br>
<font size="2" face="Menlo-Regular">bgclang -g -O2 t.c</font><br>
<br>
<tt><font size="2" color="#FF42F9">#include</font></tt><tt><font size="2"> </font></tt><tt><font size="2" color="#E0A175"><stdio.h></font></tt><br>
<tt><font size="2" color="#FF42F9">#include</font></tt><tt><font size="2"> </font></tt><tt><font size="2" color="#E0A175"><stdint.h></font></tt><br>
<br>
<tt><font size="2" color="#3F803F">char</font></tt><tt><font size="2"> </font></tt><tt><font size="2" color="#A1A100">buffer</font></tt><tt><font size="2">[24];</font></tt><br>
<br>
<tt><font size="2" color="#3F803F">void</font></tt><tt><font size="2">* </font></tt><tt><font size="2" color="#4200FF">my_memset</font></tt><tt><font size="2">(</font></tt><tt><font size="2" color="#3F803F">void</font></tt><tt><font size="2">* </font></tt><tt><font size="2" color="#A1A100">dest</font></tt><tt><font size="2">, </font></tt><tt><font size="2" color="#3F803F">int</font></tt><tt><font size="2"> </font></tt><tt><font size="2" color="#A1A100">value</font></tt><tt><font size="2">, </font></tt><tt><font size="2" color="#3F803F">size_t</font></tt><tt><font size="2"> </font></tt><tt><font size="2" color="#A1A100">n</font></tt><tt><font size="2"> )</font></tt><br>
<tt><font size="2">{</font></tt><br>
<tt><font size="2">    printf(</font></tt><tt><font size="2" color="#E0A175">"memset: dest=%p size=%ld\n"</font></tt><tt><font size="2">, dest, n);</font></tt><br>
<tt><font size="2">    </font></tt><tt><font size="2" color="#3F803F">uint8_t</font></tt><tt><font size="2">* </font></tt><tt><font size="2" color="#A1A100">d</font></tt><tt><font size="2"> = (</font></tt><tt><font size="2" color="#3F803F">uint8_t</font></tt><tt><font size="2">*)dest;</font></tt><br>
<tt><font size="2">    </font></tt><tt><font size="2" color="#C200FF">while</font></tt><tt><font size="2"> (n--)</font></tt><br>
<tt><font size="2">        *d++ = value;                      // this while loop replaced with memset() call</font></tt><br>
<tt><font size="2">    </font></tt><tt><font size="2" color="#C200FF">return</font></tt><tt><font size="2"> dest;</font></tt><br>
<tt><font size="2">}</font></tt><br>
<br>
<tt><font size="2" color="#3F803F">int</font></tt><tt><font size="2"> </font></tt><tt><font size="2" color="#4200FF">main</font></tt><tt><font size="2">(</font></tt><tt><font size="2" color="#3F803F">int</font></tt><tt><font size="2"> </font></tt><tt><font size="2" color="#A1A100">argc</font></tt><tt><font size="2">, </font></tt><tt><font size="2" color="#3F803F">char</font></tt><tt><font size="2">** </font></tt><tt><font size="2" color="#A1A100">argv</font></tt><tt><font size="2">)</font></tt><br>
<tt><font size="2">{</font></tt><br>
<tt><font size="2">    my_memset(buffer, 0, </font></tt><tt><font size="2" color="#C200FF">sizeof</font></tt><tt><font size="2">(buffer));</font></tt><br>
<tt><font size="2">    printf(</font></tt><tt><font size="2" color="#E0A175">"done\n"</font></tt><tt><font size="2">);</font></tt><br>
<tt><font size="2">    </font></tt><tt><font size="2" color="#C200FF">return</font></tt><tt><font size="2"> 0;</font></tt><br>
<tt><font size="2">}</font></tt><br>
<br>
<tt><font size="2">00000000010003c0 <.my_memset>:</font></tt><br>
<tt><font size="2"> 10003c0:       7c 08 02 a6     mflr    r0</font></tt><br>
<tt><font size="2"> 10003c4:       fb e1 ff f8     std     r31,-8(r1)</font></tt><br>
<tt><font size="2"> 10003c8:       f8 01 00 10     std     r0,16(r1)</font></tt><br>
<tt><font size="2"> 10003cc:       f8 21 ff 61     stdu    r1,-160(r1)</font></tt><br>
<tt><font size="2">....</font></tt><br>
<tt><font size="2"> 1000408:       7b 84 06 20     clrldi  r4,r28,56</font></tt><br>
<tt><font size="2"> 100040c:       7f c3 f3 78     mr      r3,r30</font></tt><br>
<tt><font size="2"> 1000410:       7f a5 eb 78     mr      r5,r29</font></tt><br>
<tt><font size="2"> 1000414:       48 00 d0 7d     bl      100d490 <.memset></font></tt><br>
<br>
<font size="2" face="sans-serif">Tom Gooding<br>
Senior Engineer / Blue Gene SW Lead / CAPI<br>
tgooding@us.ibm.com   507-253-0747<br>
</font></body></html>