Skip to content

Commit 06a9c67

Browse files
authored
[CVP] Fix #76058: missing debug location in processSDiv function (#76118)
This PR fixes #76058.
1 parent ff32ab3 commit 06a9c67

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,11 +935,13 @@ static bool processSDiv(BinaryOperator *SDI, const ConstantRange &LCR,
935935
UDiv->setDebugLoc(SDI->getDebugLoc());
936936
UDiv->setIsExact(SDI->isExact());
937937

938-
Value *Res = UDiv;
938+
auto *Res = UDiv;
939939

940940
// If the operands had two different domains, we need to negate the result.
941-
if (Ops[0].D != Ops[1].D)
941+
if (Ops[0].D != Ops[1].D) {
942942
Res = BinaryOperator::CreateNeg(Res, Res->getName() + ".neg", SDI);
943+
Res->setDebugLoc(SDI->getDebugLoc());
944+
}
943945

944946
SDI->replaceAllUsesWith(Res);
945947
SDI->eraseFromParent();
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; RUN: opt -passes=correlated-propagation -S < %s | FileCheck %s
2+
; CHECK: %{{[a-zA-Z0-9_]*}} = udiv i8 %x.nonneg, %y, !dbg ![[DBGLOC:[0-9]+]]
3+
; CHECK-NEXT: %{{[a-zA-Z0-9_]*}}.neg = sub i8 0, %rem1, !dbg ![[DBGLOC]]
4+
5+
; Function Attrs: inaccessiblememonly nocallback nofree nosync nounwind willreturn
6+
declare void @llvm.assume(i1 noundef) #0
7+
8+
define void @test8_neg_neg(i8 %x, i8 %y) !dbg !5 {
9+
%c0 = icmp sle i8 %x, 0, !dbg !13
10+
call void @llvm.dbg.value(metadata i1 %c0, metadata !9, metadata !DIExpression()), !dbg !13
11+
call void @llvm.assume(i1 %c0), !dbg !14
12+
%c1 = icmp sge i8 %y, 0, !dbg !15
13+
call void @llvm.dbg.value(metadata i1 %c1, metadata !11, metadata !DIExpression()), !dbg !15
14+
call void @llvm.assume(i1 %c1), !dbg !16
15+
%rem = sdiv i8 %x, %y, !dbg !17
16+
call void @llvm.dbg.value(metadata i8 %rem, metadata !12, metadata !DIExpression()), !dbg !17
17+
ret void, !dbg !18
18+
}
19+
20+
; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
21+
declare void @llvm.dbg.value(metadata, metadata, metadata) #1
22+
23+
!llvm.module.flags = !{!0}
24+
!llvm.dbg.cu = !{!1}
25+
26+
!0 = !{i32 2, !"Debug Info Version", i32 3}
27+
!1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
28+
!2 = !DIFile(filename: "reduced.ll", directory: "/")
29+
!5 = distinct !DISubprogram(name: "test8_neg_neg", linkageName: "test8_neg_neg", scope: null, file: !2, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !1, retainedNodes: !8)
30+
!6 = !DISubroutineType(types: !7)
31+
!7 = !{}
32+
!8 = !{!9, !11, !12}
33+
!9 = !DILocalVariable(name: "1", scope: !5, file: !2, line: 1, type: !10)
34+
!10 = !DIBasicType(name: "ty8", size: 8, encoding: DW_ATE_unsigned)
35+
!11 = !DILocalVariable(name: "2", scope: !5, file: !2, line: 3, type: !10)
36+
!12 = !DILocalVariable(name: "3", scope: !5, file: !2, line: 5, type: !10)
37+
!13 = !DILocation(line: 1, column: 1, scope: !5)
38+
!14 = !DILocation(line: 2, column: 1, scope: !5)
39+
!15 = !DILocation(line: 3, column: 1, scope: !5)
40+
!16 = !DILocation(line: 4, column: 1, scope: !5)
41+
!17 = !DILocation(line: 5, column: 1, scope: !5)
42+
!18 = !DILocation(line: 6, column: 1, scope: !5)

0 commit comments

Comments
 (0)