Skip to content

Commit c7fcae5

Browse files
author
Yeting Kuo
committed
[InstCombine][debuginfo] Update valueCoversEntireFragment for fixed size fragment and scalable value.
Update valueCoversEntireFragment to handle new case and add regression test. Reviewed By: sdesmalen, aprantl Differential Revision: https://reviews.llvm.org/D144472
1 parent 5c602c4 commit c7fcae5

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,11 +1493,9 @@ static bool PhiHasDebugValue(DILocalVariable *DIVar,
14931493
static bool valueCoversEntireFragment(Type *ValTy, DbgVariableIntrinsic *DII) {
14941494
const DataLayout &DL = DII->getModule()->getDataLayout();
14951495
TypeSize ValueSize = DL.getTypeAllocSizeInBits(ValTy);
1496-
if (std::optional<uint64_t> FragmentSize = DII->getFragmentSizeInBits()) {
1497-
assert(!ValueSize.isScalable() &&
1498-
"Fragments don't work on scalable types.");
1499-
return ValueSize.getFixedValue() >= *FragmentSize;
1500-
}
1496+
if (std::optional<uint64_t> FragmentSize = DII->getFragmentSizeInBits())
1497+
return TypeSize::isKnownGE(ValueSize, TypeSize::getFixed(*FragmentSize));
1498+
15011499
// We can't always calculate the size of the DI variable (e.g. if it is a
15021500
// VLA). Try to use the size of the alloca that the dbg intrinsic describes
15031501
// intead.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt < %s -passes='instcombine' -S | FileCheck %s
3+
4+
define i32 @foo(<vscale x 2 x i32> %x) {
5+
; CHECK-LABEL: @foo(
6+
; CHECK-NEXT: entry:
7+
; CHECK-NEXT: [[ARR:%.*]] = alloca i32, align 8
8+
; CHECK-NEXT: call void @llvm.dbg.value(metadata <vscale x 2 x i32> undef, metadata [[META8:![0-9]+]], metadata !DIExpression()), !dbg [[DBG14:![0-9]+]]
9+
; CHECK-NEXT: store <vscale x 2 x i32> [[X:%.*]], ptr [[ARR]], align 8
10+
; CHECK-NEXT: [[RES:%.*]] = load i32, ptr [[ARR]], align 8
11+
; CHECK-NEXT: ret i32 [[RES]]
12+
;
13+
entry:
14+
%arr = alloca i32, align 4
15+
call void @llvm.dbg.declare(metadata ptr %arr, metadata !8, metadata !DIExpression()), !dbg !14
16+
store <vscale x 2 x i32> %x, ptr %arr, align 4
17+
%res = load i32, ptr %arr
18+
ret i32 %res
19+
}
20+
21+
define i32 @foo2(<vscale x 2 x i32> %x) {
22+
; CHECK-LABEL: @foo2(
23+
; CHECK-NEXT: entry:
24+
; CHECK-NEXT: [[ARR:%.*]] = alloca [4 x i32], align 8
25+
; CHECK-NEXT: call void @llvm.dbg.declare(metadata ptr [[ARR]], metadata [[META15:![0-9]+]], metadata !DIExpression()), !dbg [[DBG17:![0-9]+]]
26+
; CHECK-NEXT: store <vscale x 2 x i32> [[X:%.*]], ptr [[ARR]], align 8
27+
; CHECK-NEXT: [[RES:%.*]] = load i32, ptr [[ARR]], align 8
28+
; CHECK-NEXT: ret i32 [[RES]]
29+
;
30+
entry:
31+
%arr = alloca [4 x i32], align 4
32+
call void @llvm.dbg.declare(metadata ptr %arr, metadata !15, metadata !DIExpression()), !dbg !17
33+
store <vscale x 2 x i32> %x, ptr %arr, align 4
34+
%res = load i32, ptr %arr
35+
ret i32 %res
36+
}
37+
38+
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
39+
declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
40+
41+
attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
42+
43+
!llvm.dbg.cu = !{!0}
44+
!llvm.module.flags = !{!3, !4, !5, !6, !7}
45+
46+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 17.0.0 ([email protected]:llvm/llvm-project.git a489e11439e36c7e0ec83b28a6fb1596a5c21faa)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2, splitDebugInlining: false, nameTableKind: None)
47+
!1 = !DIFile(filename: "u.cpp", directory: "/path/to/test", checksumkind: CSK_MD5, checksum: "42f62c17fb0f0110f515890bc6d69cb5")
48+
!2 = !{}
49+
!3 = !{i32 7, !"Dwarf Version", i32 5}
50+
!4 = !{i32 2, !"Debug Info Version", i32 3}
51+
!5 = !{i32 1, !"wchar_size", i32 4}
52+
!6 = !{i32 1, !"target-abi", !"lp64d"}
53+
!7 = !{i32 8, !"SmallDataLimit", i32 8}
54+
!8 = !DILocalVariable(name: "arr", scope: !9, file: !1, line: 3, type: !12)
55+
!9 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 2, type: !10, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
56+
!10 = !DISubroutineType(types: !11)
57+
!11 = !{null}
58+
!12 = !DICompositeType(tag: DW_TAG_array_type, baseType: !13, size: 128, elements: !2)
59+
!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
60+
!14 = !DILocation(line: 3, column: 7, scope: !9)
61+
!15 = !DILocalVariable(name: "arr", scope: !16, file: !1, line: 6, type: !12)
62+
!16 = distinct !DISubprogram(name: "foo2", linkageName: "foo2", scope: !1, file: !1, line: 5, type: !10, scopeLine: 5, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
63+
!17 = !DILocation(line: 6, column: 7, scope: !16)

0 commit comments

Comments
 (0)