Skip to content

Commit 19ee7ff

Browse files
authored
[AggrInstCombine][DebugInfo] Propagate DILocation for inlined memchr (llvm#134808)
When AggressiveInstCombine replaces a memchr with a switch instruction, it currently drops the DILocation for that memchr. This patch changes this, propagating the memchr DILocation to all the generated instructions that replace it. Found using llvm#107279.
1 parent 6010d5b commit 19ee7ff

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,7 @@ static bool foldMemChr(CallInst *Call, DomTreeUpdater *DTU,
11331133
BasicBlock *BB = Call->getParent();
11341134
BasicBlock *BBNext = SplitBlock(BB, Call, DTU);
11351135
IRBuilder<> IRB(BB);
1136+
IRB.SetCurrentDebugLocation(Call->getDebugLoc());
11361137
IntegerType *ByteTy = IRB.getInt8Ty();
11371138
BB->getTerminator()->eraseFromParent();
11381139
SwitchInst *SI = IRB.CreateSwitch(
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S -p=aggressive-instcombine < %s | FileCheck %s
3+
;; Tests that when we inline a simple memchr, we transfer its DILocation to the
4+
;; generated instructions.
5+
6+
@.str.30 = constant [3 x i8] c"/\\\00"
7+
8+
define i32 @foo(i32 %conv22) {
9+
; CHECK-LABEL: define i32 @foo(
10+
; CHECK-SAME: i32 [[CONV22:%.*]]) {
11+
; CHECK-NEXT: [[ENTRY:.*:]]
12+
; CHECK-NEXT: [[TMP0:%.*]] = trunc i32 [[CONV22]] to i8, !dbg [[DBG3:![0-9]+]]
13+
; CHECK-NEXT: switch i8 [[TMP0]], label %[[ENTRY_SPLIT:.*]] [
14+
; CHECK-NEXT: ], !dbg [[DBG3]]
15+
; CHECK: [[MEMCHR_SUCCESS:.*:]]
16+
; CHECK-NEXT: br label %[[ENTRY_SPLIT]], !dbg [[DBG3]]
17+
; CHECK: [[ENTRY_SPLIT]]:
18+
; CHECK-NEXT: ret i32 0
19+
;
20+
entry:
21+
%memchr = call ptr @memchr(ptr @.str.30, i32 %conv22, i64 0), !dbg !3
22+
ret i32 0
23+
}
24+
25+
declare ptr @memchr(ptr, i32, i64)
26+
27+
!llvm.dbg.cu = !{!0}
28+
!llvm.module.flags = !{!2}
29+
30+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 20.0.0git")
31+
!1 = !DIFile(filename: "test.c", directory: "/tmp")
32+
!2 = !{i32 2, !"Debug Info Version", i32 3}
33+
!3 = !DILocation(line: 19, column: 42, scope: !4)
34+
!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 174, type: !5, unit: !0, retainedNodes: !6)
35+
!5 = !DISubroutineType(types: !6)
36+
!6 = !{}
37+
;.
38+
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
39+
; CHECK: [[META1]] = !DIFile(filename: "test.c", directory: {{.*}})
40+
; CHECK: [[DBG3]] = !DILocation(line: 19, column: 42, scope: [[META4:![0-9]+]])
41+
; CHECK: [[META4]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 174, type: [[META5:![0-9]+]], spFlags: DISPFlagDefinition, unit: [[META0]], retainedNodes: [[META6:![0-9]+]])
42+
; CHECK: [[META5]] = !DISubroutineType(types: [[META6]])
43+
; CHECK: [[META6]] = !{}
44+
;.

0 commit comments

Comments
 (0)