<div dir="ltr">I assume we would see this is a pure debug quality bug if you split the for loop header over multiple lines? (so it wasn't just a discriminator bug)? <br><br>Which instruction/part of the loop header is it taking the line 4/disc 1 from?</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Oct 21, 2016 at 7:34 AM Andrea Di Biagio <<a href="mailto:andrea.dibiagio@gmail.com">andrea.dibiagio@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">andreadb created this revision.<br class="gmail_msg">
andreadb added reviewers: aprantl, probinson, wolfgangp, dblaikie, echristo.<br class="gmail_msg">
andreadb added a subscriber: llvm-commits.<br class="gmail_msg">
Herald added a subscriber: mehdi_amini.<br class="gmail_msg">
<br class="gmail_msg">
When indvars creates a wide induction variable, the debug location for the loop increment is incorrect (see below):<br class="gmail_msg">
<br class="gmail_msg">
Example:<br class="gmail_msg">
<br class="gmail_msg">
extern int foo(int);<br class="gmail_msg">
<br class="gmail_msg">
int bar(int x, int *a)<br class="gmail_msg">
for (int i = 0; i < x; ++i) // line 4<br class="gmail_msg">
a[i] = foo(i);<br class="gmail_msg">
<br class="gmail_msg">
return a[0];<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
Before indvars is run, the IV (induction variable) increment is performed in the loop latch at line 4:<br class="gmail_msg">
<br class="gmail_msg">
%inc = add nsw i32 %i.06, 1, !dbg !13<br class="gmail_msg">
<br class="gmail_msg">
Where, %i.06 is our IV, and !dbg !13 is a DILocation which refers to line 4, discriminator 2.<br class="gmail_msg">
<br class="gmail_msg">
After indvars is run, our IV is expanded into:<br class="gmail_msg">
<br class="gmail_msg">
%indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %<a href="http://for.body.lr.ph" rel="noreferrer" class="gmail_msg" target="_blank">for.body.lr.ph</a>]<br class="gmail_msg">
<br class="gmail_msg">
In particular, %indvars.iv.next is defined by instruction:<br class="gmail_msg">
<br class="gmail_msg">
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !9<br class="gmail_msg">
<br class="gmail_msg">
However, !dbg !9 is the debug loc for line 4, discriminator 1. It should have been line 4, discriminator 2.<br class="gmail_msg">
<br class="gmail_msg">
This patch fixes the issue by propagating the correct debug location from the original loop increment instruction to the new widened increment.<br class="gmail_msg">
<br class="gmail_msg">
Please let me know if okay to commit.<br class="gmail_msg">
<br class="gmail_msg">
Thanks,<br class="gmail_msg">
Andrea<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<a href="https://reviews.llvm.org/D25872" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D25872</a><br class="gmail_msg">
<br class="gmail_msg">
Files:<br class="gmail_msg">
lib/Transforms/Scalar/IndVarSimplify.cpp<br class="gmail_msg">
test/DebugInfo/Generic/indvar-discriminator.ll<br class="gmail_msg">
<br class="gmail_msg">
</blockquote></div>