Add a trunc as an IV user if it is used only by a single IV user that is added
directly through the trunc and there are other IV users that has the same SCEV
recurrence as the trunc. By adding such trunc, we expect that LSR chooses a
better solution in case where there are other IV users which have the same SCEV
recurrence as the trunc.
Motivating case in AArch64 is added as a testcase where extra IV increments are
added in LSR which picked suboptimal formulae.
For the loop :
for.body.preheader: %n_sext = sext i32 %n to i64 br label %for.body for.body: %K.in = phi i64 [ %n_sext, %for.body.preheader ], [ %K, %for.body ] %K = add i64 %K.in, 1 %StoredAddr = getelementptr inbounds [12 x i32], [12 x i32]* @gvarray, i64 0, i64 %K %StoredValue = trunc i64 %K to i32 store volatile i32 %StoredValue, i32* %StoredAddr %cmp = icmp sgt i64 %K, 1 br i1 %cmp, label %for.body, label %for.end
Before this change :
.LBB0_2: add x11, x9, x10, lsl #2 add x10, x10, #1 str w8, [x11, #4] add w8, w8, #1 cmp x10, #1 b.gt .LBB0_2
After this change :
.LBB0_2: add x10, x8, #1 cmp x8, #1 str w8, [x9, x8, lsl #2] mov x8, x10 b.gt .LBB0_2