When indvars creates a wide induction variable, the debug location for the loop increment is incorrect (see below):
Example:
extern int foo(int); int bar(int x, int *a) for (int i = 0; i < x; ++i) // line 4 a[i] = foo(i); return a[0]; }
Before indvars is run, the IV (induction variable) increment is performed in the loop latch at line 4:
%inc = add nsw i32 %i.06, 1, !dbg !13
Where, %i.06 is our IV, and !dbg !13 is a DILocation which refers to line 4, discriminator 2.
After indvars is run, our IV is expanded into:
%indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %for.body.lr.ph]
In particular, %indvars.iv.next is defined by instruction:
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !9
However, !dbg !9 is the debug loc for line 4, discriminator 1. It should have been line 4, discriminator 2.
This patch fixes the issue by propagating the correct debug location from the original loop increment instruction to the new widened increment.
Please let me know if okay to commit.
Thanks,
Andrea