[llvm] 3f7a6ce - [DWARF][FIX] Handle the use of multiple registers gracefully

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 15 11:44:27 PDT 2022


Author: Johannes Doerfert
Date: 2022-04-15T13:43:50-05:00
New Revision: 3f7a6ce0de804a27954706d3a2fc2aef0c9554b7

URL: https://github.com/llvm/llvm-project/commit/3f7a6ce0de804a27954706d3a2fc2aef0c9554b7
DIFF: https://github.com/llvm/llvm-project/commit/3f7a6ce0de804a27954706d3a2fc2aef0c9554b7.diff

LOG: [DWARF][FIX] Handle the use of multiple registers gracefully

Certain applications crashed for us with the AMDGPU backend. While this
is not a proper fix it allows us to compile the code for now. I left a
TODO for someone that understands DWARF.

Differential Revision: https://reviews.llvm.org/D123717

Added: 
    llvm/test/CodeGen/AMDGPU/dwarf-multi-register-use-crash.ll

Modified: 
    llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
index fe438102ee986..1c21d5ee8bb1c 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
@@ -329,7 +329,16 @@ bool DwarfExpression::addMachineRegExpression(const TargetRegisterInfo &TRI,
       return false;
     }
 
-  assert(DwarfRegs.size() == 1);
+  // TODO: We should not give up here but the following code needs to be changed
+  //       to deal with multiple (sub)registers first.
+  if (DwarfRegs.size() > 1) {
+    LLVM_DEBUG(dbgs() << "TODO: giving up on debug information due to "
+                         "multi-register usage.\n");
+    DwarfRegs.clear();
+    LocationKind = Unknown;
+    return false;
+  }
+
   auto Reg = DwarfRegs[0];
   bool FBReg = isFrameRegister(TRI, MachineReg);
   int SignedOffset = 0;

diff  --git a/llvm/test/CodeGen/AMDGPU/dwarf-multi-register-use-crash.ll b/llvm/test/CodeGen/AMDGPU/dwarf-multi-register-use-crash.ll
new file mode 100644
index 0000000000000..ffc965d69835c
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/dwarf-multi-register-use-crash.ll
@@ -0,0 +1,152 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx908 < %s | FileCheck %s
+
+; Don't crash.
+
+; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
+
+declare ptr @__kmpc_alloc_shared()
+
+define weak_odr void @test(i32 %0) !dbg !34 {
+; CHECK-LABEL: test:
+; CHECK:       .Lfunc_begin0:
+; CHECK-NEXT:    .loc 1 288 0 ; dummy:288:0
+; CHECK-NEXT:    .cfi_sections .debug_frame
+; CHECK-NEXT:    .cfi_startproc
+; CHECK-NEXT:  ; %bb.0:
+; CHECK-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; CHECK-NEXT:    s_or_saveexec_b64 s[16:17], -1
+; CHECK-NEXT:    buffer_store_dword v40, off, s[0:3], s32 offset:4 ; 4-byte Folded Spill
+; CHECK-NEXT:    s_mov_b64 exec, s[16:17]
+; CHECK-NEXT:    v_writelane_b32 v40, s33, 15
+; CHECK-NEXT:    v_writelane_b32 v40, s30, 0
+; CHECK-NEXT:    v_writelane_b32 v40, s31, 1
+; CHECK-NEXT:    v_writelane_b32 v40, s34, 2
+; CHECK-NEXT:    v_writelane_b32 v40, s35, 3
+; CHECK-NEXT:    v_writelane_b32 v40, s36, 4
+; CHECK-NEXT:    v_writelane_b32 v40, s37, 5
+; CHECK-NEXT:    v_writelane_b32 v40, s38, 6
+; CHECK-NEXT:    v_writelane_b32 v40, s39, 7
+; CHECK-NEXT:    v_writelane_b32 v40, s40, 8
+; CHECK-NEXT:    v_writelane_b32 v40, s41, 9
+; CHECK-NEXT:    v_writelane_b32 v40, s42, 10
+; CHECK-NEXT:    v_writelane_b32 v40, s43, 11
+; CHECK-NEXT:    s_mov_b32 s33, s32
+; CHECK-NEXT:    s_addk_i32 s32, 0x400
+; CHECK-NEXT:    v_writelane_b32 v40, s44, 12
+; CHECK-NEXT:    v_writelane_b32 v40, s46, 13
+; CHECK-NEXT:    s_mov_b64 s[40:41], s[4:5]
+; CHECK-NEXT:    ;DEBUG_VALUE: dummy:dummy <- undef
+; CHECK-NEXT:  .Ltmp0:
+; CHECK-NEXT:    .loc 1 49 9 prologue_end ; dummy:49:9
+; CHECK-NEXT:    s_getpc_b64 s[4:5]
+; CHECK-NEXT:    s_add_u32 s4, s4, __kmpc_alloc_shared at gotpcrel32@lo+4
+; CHECK-NEXT:    s_addc_u32 s5, s5, __kmpc_alloc_shared at gotpcrel32@hi+12
+; CHECK-NEXT:    v_writelane_b32 v40, s47, 14
+; CHECK-NEXT:    s_load_dwordx2 s[46:47], s[4:5], 0x0
+; CHECK-NEXT:    s_mov_b64 s[4:5], s[40:41]
+; CHECK-NEXT:    buffer_store_dword v41, off, s[0:3], s33 ; 4-byte Folded Spill
+; CHECK-NEXT:    v_mov_b32_e32 v41, v31
+; CHECK-NEXT:    s_mov_b32 s42, s14
+; CHECK-NEXT:    s_mov_b32 s43, s13
+; CHECK-NEXT:    s_mov_b32 s44, s12
+; CHECK-NEXT:    s_mov_b64 s[34:35], s[10:11]
+; CHECK-NEXT:    s_mov_b64 s[36:37], s[8:9]
+; CHECK-NEXT:    s_mov_b64 s[38:39], s[6:7]
+; CHECK-NEXT:    s_waitcnt lgkmcnt(0)
+; CHECK-NEXT:    s_swappc_b64 s[30:31], s[46:47]
+; CHECK-NEXT:    s_mov_b64 s[4:5], s[40:41]
+; CHECK-NEXT:    s_mov_b64 s[6:7], s[38:39]
+; CHECK-NEXT:    s_mov_b64 s[8:9], s[36:37]
+; CHECK-NEXT:    s_mov_b64 s[10:11], s[34:35]
+; CHECK-NEXT:    s_mov_b32 s12, s44
+; CHECK-NEXT:    s_mov_b32 s13, s43
+; CHECK-NEXT:    s_mov_b32 s14, s42
+; CHECK-NEXT:    v_mov_b32_e32 v31, v41
+; CHECK-NEXT:    s_swappc_b64 s[30:31], s[46:47]
+; CHECK-NEXT:  .Ltmp1:
+; CHECK-NEXT:    ;DEBUG_VALUE: dummy:dummy <- [$vgpr0_vgpr1+0]
+; CHECK-NEXT:    .loc 1 0 9 is_stmt 0 ; dummy:0:9
+; CHECK-NEXT:    buffer_load_dword v41, off, s[0:3], s33 ; 4-byte Folded Reload
+; CHECK-NEXT:    v_mov_b32_e32 v2, 0
+; CHECK-NEXT:    flat_store_dword v[0:1], v2
+; CHECK-NEXT:    v_readlane_b32 s47, v40, 14
+; CHECK-NEXT:    v_readlane_b32 s46, v40, 13
+; CHECK-NEXT:    v_readlane_b32 s44, v40, 12
+; CHECK-NEXT:    v_readlane_b32 s43, v40, 11
+; CHECK-NEXT:    v_readlane_b32 s42, v40, 10
+; CHECK-NEXT:    v_readlane_b32 s41, v40, 9
+; CHECK-NEXT:    v_readlane_b32 s40, v40, 8
+; CHECK-NEXT:    v_readlane_b32 s39, v40, 7
+; CHECK-NEXT:    v_readlane_b32 s38, v40, 6
+; CHECK-NEXT:    v_readlane_b32 s37, v40, 5
+; CHECK-NEXT:    v_readlane_b32 s36, v40, 4
+; CHECK-NEXT:    v_readlane_b32 s35, v40, 3
+; CHECK-NEXT:    v_readlane_b32 s34, v40, 2
+; CHECK-NEXT:    v_readlane_b32 s31, v40, 1
+; CHECK-NEXT:    v_readlane_b32 s30, v40, 0
+; CHECK-NEXT:    s_addk_i32 s32, 0xfc00
+; CHECK-NEXT:    v_readlane_b32 s33, v40, 15
+; CHECK-NEXT:    s_or_saveexec_b64 s[4:5], -1
+; CHECK-NEXT:    buffer_load_dword v40, off, s[0:3], s32 offset:4 ; 4-byte Folded Reload
+; CHECK-NEXT:    s_mov_b64 exec, s[4:5]
+; CHECK-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
+; CHECK-NEXT:    s_setpc_b64 s[30:31]
+; CHECK-NEXT:  .Ltmp2:
+  %2 = call ptr @__kmpc_alloc_shared(), !dbg !43
+  %3 = call ptr @__kmpc_alloc_shared()
+  store i32 0, ptr %3, align 4
+  call void @llvm.dbg.declare(metadata ptr %3, metadata !40, metadata !DIExpression()), !dbg !43
+  ret void
+}
+
+attributes #0 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
+
+!llvm.dbg.cu = !{!0, !25, !26}
+!llvm.module.flags = !{!27, !28, !29, !30, !31, !32, !33}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 15.0.0 (https://github.com/llvm/llvm-project.git 05256c8d95e0b15bcc502d595c15d902ff520f97)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !8, imports: !20, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "dummy", directory: "dummy", checksumkind: CSK_MD5, checksum: "b67bec84bdce3730b4a6f2ed8d50b85c")
+!2 = !{!3, !3, !3}
+!3 = distinct !DICompositeType(tag: DW_TAG_enumeration_type, name: "dummy", scope: !4, file: !1, line: 49, baseType: !5, size: 32, elements: !6, identifier: "dummy")
+!4 = !DINamespace(name: "dummy", scope: null)
+!5 = !DIBasicType(name: "dummy", size: 32, encoding: DW_ATE_unsigned)
+!6 = !{!7}
+!7 = !DIEnumerator(name: "dummy", value: 0, isUnsigned: true)
+!8 = !{!5, !9, !11, !12, !13, !14}
+!9 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "dummy", scope: !10, file: !1, line: 49, size: 32, flags: DIFlagEnumClass, elements: !6, identifier: "dummy")
+!10 = !DINamespace(name: "dummy", scope: !4)
+!11 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "dummy", scope: !4, file: !1, line: 49, size: 32, flags: DIFlagEnumClass, elements: !6, identifier: "dummy")
+!12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "dummy", scope: !4, file: !1, line: 49, size: 32, flags: DIFlagEnumClass, elements: !6, identifier: "dummy")
+!13 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "dummy", scope: !10, file: !1, line: 49, size: 32, flags: DIFlagEnumClass, elements: !6, identifier: "dummy")
+!14 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "dummy", scope: !10, file: !1, line: 49, size: 32, flags: DIFlagEnumClass, elements: !6, templateParams: !15, identifier: "dummy")
+!15 = !{!16, !17, !19}
+!16 = !DITemplateTypeParameter(name: "dummy", type: !11)
+!17 = !DITemplateTypeParameter(name: "dummy", type: !18)
+!18 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "dummy", scope: !10, file: !1, line: 49, size: 32, flags: DIFlagEnumClass, identifier: "dummy")
+!19 = !DITemplateValueParameter(type: !5, value: i1 true)
+!20 = !{!21}
+!21 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !4, entity: !22, file: !1, line: 49)
+!22 = !DISubprogram(name: "dummy", scope: !4, file: !1, line: 49, type: !23, flags: DIFlagEnumClass, spFlags: DISPFlagOptimized)
+!23 = !DISubroutineType(types: !24)
+!24 = !{!5}
+!25 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 15.0.0 (https://github.com/llvm/llvm-project.git 05256c8d95e0b15bcc502d595c15d902ff520f97)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, imports: !20, splitDebugInlining: false, nameTableKind: None)
+!26 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 15.0.0 (https://github.com/llvm/llvm-project.git 05256c8d95e0b15bcc502d595c15d902ff520f97)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !24, imports: !20, splitDebugInlining: false, nameTableKind: None)
+!27 = !{i32 7, !"Dwarf Version", i32 5}
+!28 = !{i32 2, !"Debug Info Version", i32 3}
+!29 = !{i32 1, !"wchar_size", i32 4}
+!30 = !{i32 7, !"openmp", i32 50}
+!31 = !{i32 7, !"openmp-device", i32 50}
+!32 = !{i32 7, !"PIC Level", i32 2}
+!33 = !{i32 1, !"LTOPostLink", i32 1}
+!34 = distinct !DISubprogram(name: "dummy", linkageName: "dummy", scope: !35, file: !1, line: 49, type: !23, scopeLine: 288, flags: DIFlagEnumClass, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, declaration: !36, retainedNodes: !37)
+!35 = distinct !DICompositeType(tag: DW_TAG_class_type, file: !1, line: 49, size: 32, flags: DIFlagEnumClass, elements: !6, identifier: "dummy")
+!36 = !DISubprogram(name: "dummy", scope: !35, file: !1, line: 49, type: !23, scopeLine: 288, flags: DIFlagEnumClass, spFlags: DISPFlagOptimized)
+!37 = !{!38, !40, !41, !42}
+!38 = !DILocalVariable(name: "dummy", arg: 1, scope: !34, type: !39, flags: DIFlagEnumClass)
+!39 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 32)
+!40 = !DILocalVariable(name: "dummy", arg: 2, scope: !34, file: !1, line: 49, type: !5)
+!41 = !DILocalVariable(name: "dummy", arg: 3, scope: !34, file: !1, line: 49, type: !5)
+!42 = !DILocalVariable(name: "dummy", arg: 4, scope: !34, file: !1, line: 49, type: !5)
+!43 = !DILocation(line: 49, column: 9, scope: !34)


        


More information about the llvm-commits mailing list