[PATCH] D98218: [LSR] fix a issue that LoopStrengthReduction drop debug location unnecessarily
Yuanbo Li via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 18 15:53:32 PDT 2021
yuanboli233 added a comment.
As @jmorse pointed out, OptimizeLoopTermCond might move the newly created instruction around. I was working on an example to trigger an instruction move and the replacement of the conditional. Here I have an example, I show part of the code here:
define void @foobar(i32 %n) !dbg !6 {
bb.nph:
%cond = icmp eq i32 %n, 0, !dbg !16
call void @llvm.dbg.value(metadata i1 %cond, metadata !9, metadata !DIExpression()), !dbg !16
%umax = select i1 %cond, i32 1, i32 %n, !dbg !17
call void @llvm.dbg.value(metadata i32 %umax, metadata !11, metadata !DIExpression()), !dbg !17
br label %bb, !dbg !18
bb: ; preds = %bb, %bb.nph
%i.03 = phi i32 [ 0, %bb.nph ], [ %indvar.next, %bb ], !dbg !19
call void @llvm.dbg.value(metadata i32 %i.03, metadata !13, metadata !DIExpression()), !dbg !19
%indvar.next = add nuw nsw i32 %i.03, 1, !dbg !20
call void @llvm.dbg.value(metadata i32 %indvar.next, metadata !14, metadata !DIExpression()), !dbg !20
%exitcond = icmp eq i32 %indvar.next, %umax, !dbg !21
call void @llvm.dbg.value(metadata i1 %exitcond, metadata !15, metadata !DIExpression()), !dbg !21
br i1 %exitcond, label %return, label %bb, !dbg !22
return: ; preds = %bb
ret void, !dbg !23
}
is optimized to
define void @foobar(i32 %n) !dbg !6 {
bb.nph:
call void @llvm.dbg.value(metadata i1 undef, metadata !9, metadata !DIExpression()), !dbg !16
call void @llvm.dbg.value(metadata i32 undef, metadata !11, metadata !DIExpression()), !dbg !17
br label %bb, !dbg !18
bb: ; preds = %bb, %bb.nph
%i.03 = phi i32 [ 0, %bb.nph ], [ %indvar.next, %bb ], !dbg !19
call void @llvm.dbg.value(metadata i32 %i.03, metadata !13, metadata !DIExpression()), !dbg !19
%indvar.next = add nuw nsw i32 %i.03, 1, !dbg !20
call void @llvm.dbg.value(metadata i32 %indvar.next, metadata !14, metadata !DIExpression()), !dbg !20
call void @llvm.dbg.value(metadata i1 %scmp, metadata !15, metadata !DIExpression()), !dbg !21
%scmp = icmp uge i32 %indvar.next, %n, !dbg !21
br i1 %scmp, label %return, label %bb, !dbg !22
return: ; preds = %bb
ret void, !dbg !23
}
The %exitcond is replaced by %scmp, and %scmp is moved to the second last instruction of the block. Maybe the debug location should probably still be kept, but I am not very sure about it. Even the debug location should not be kept, it probably should be dropped during the instruction move in the OptimizeLoopTermCond function. May I know your thoughts about this specific case?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D98218/new/
https://reviews.llvm.org/D98218
More information about the llvm-commits
mailing list