<font color="#000000"><font face="verdana,sans-serif">Hello,<br></font></font><div><font class="Apple-style-span" face="verdana, sans-serif"><br></font></div><div><font class="Apple-style-span" face="verdana, sans-serif">The code snippet pasted in the previous email are generated at -O0 with llc.<br>

</font></div><div><div class="gmail_quote">Since I am inserting a new basic block (contains printf statement and program exit) which is jumped upon based on the result of the comparison, the compiler cannot/shouldnot optimize that away by means of DCE or anything else.</div>

<div class="gmail_quote"><br></div><div class="gmail_quote">The same kind of stuff is happening for the following duplication. </div><div class="gmail_quote"><br></div><div class="gmail_quote"><div class="gmail_quote">bb6.split:                                        ; preds = %bb6</div>

<div class="gmail_quote">  %33 = load i32* %32, align 4</div><div class="gmail_quote">  %34 = load i32* %i, align 4</div><div class="gmail_quote">  %HV4_3 = sub nsw i32 %34, %33</div><div class="gmail_quote">  %35 = sub nsw i32 %34, %33</div>

<div class="gmail_quote">  %HV4_2 = getelementptr inbounds [100 x i32]* %a, i32 0, i32 %HV4_3</div><div class="gmail_quote">  %36 = getelementptr inbounds [100 x i32]* %a, i32 0, i32 %35</div><div class="gmail_quote">  %LDCmp6 = icmp ne i32* %36, %HV4_2</div>

<div class="gmail_quote">  br i1 %LDCmp6, label %relExit, label %bb6.split.split</div><div class="gmail_quote"><br></div><div class="gmail_quote">In the above example even the operands are not same and I guess compiler cannot be that smart at -O0. I sense something is wrong with the code generation for ARM.</div>

<div class="gmail_quote"><br></div><div class="gmail_quote">What other way do you suggest for duplicating since you mentioned I shouldn't rely on duplication the way I am doing it?</div><div class="gmail_quote"><br></div>

<div class="gmail_quote">Thanks a lot. I really appreciate your help.</div><div class="gmail_quote">Daya</div><div class="gmail_quote"><br></div><div class="gmail_quote"><br></div></div><div class="gmail_quote">On Wed, Jul 6, 2011 at 10:27 AM, Renato Golin <span dir="ltr"><<a href="mailto:renato.golin@arm.com">renato.golin@arm.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On 6 July 2011 14:55, D S Khudia <<a href="mailto:daya.khudia@gmail.com">daya.khudia@gmail.com</a>> wrote:<br>


> The following is an example code generation for arm and x86 for a same IR<br>
> BB. In the x86 code I can see that the same computation is done twice and<br>
> result is stored in two different registers and then these two different<br>
> registers are used for comparision.<br>
<br>
</div>Yes, but you shouldn't rely on it, since the compiler is free to<br>
optimize that away.<br>
<div class="im"><br>
<br>
> By the way I am duplicating instruction<br>
> and inserting comparison to catch transient errors.<br>
<br>
</div>I thought so. Try running llc with -O0 or disable specific<br>
optimizations (like dead-code elimination) to keep your comparisons<br>
intact.<br>
<br>
But since the two values are identical, it's possible that even so,<br>
both will live in the same register.<br>
<br>
cheers,<br>
<font color="#888888">--renato<br>
</font></blockquote></div><br></div>