[PATCH] D111970: [GlobalISel][Legalizer] Restore eraseFromParentAndMarkDBGValuesForRemoval() for CallLowering artifacts.

Jack Andersen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 17 17:16:55 PDT 2021


jackoalan created this revision.
jackoalan added a reviewer: aemerson.
Herald added subscribers: pengfei, hiraditya, rovka.
jackoalan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

D109750 <https://reviews.llvm.org/D109750> was created to improve performance by avoiding the expense of `eraseFromParentAndMarkDBGValuesForRemoval` for instructions that are known to not be emitted by IR translation. However, this does not account for call lowering which is indirectly invoked by IR translation. Call lowering has reachability of `G_UNMERGE_VALUES`, `G_MERGE_VALUES`, `G_CONCAT_VECTORS`, and `G_BUILD_VECTOR` so these should be removed from this exclusion test.

Compiling a function with an argument wider than the native machine types results in `G_MERGE_VALUES` which is used by `DBG_VALUE`. This trivial case on i386 causes a validation failure post-legalization:

  int test_dbg_trunc(unsigned long long a) { return a; }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111970

Files:
  llvm/lib/CodeGen/GlobalISel/Utils.cpp
  llvm/test/CodeGen/X86/GlobalISel/x86-calllowering-dbg-trunc.ll


Index: llvm/test/CodeGen/X86/GlobalISel/x86-calllowering-dbg-trunc.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/GlobalISel/x86-calllowering-dbg-trunc.ll
@@ -0,0 +1,57 @@
+; RUN: llc -mtriple=i386-linux-gnu -global-isel -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=ALL
+
+; This file is the output of clang -g -O2
+; int test_dbg_trunc(unsigned long long a) { return a; }
+;
+; The intent of this check is to ensure the DBG_VALUE use of G_MERGE_VALUES is undef'd when the legalizer erases it.
+
+; ModuleID = 'x86-calllowering-dbg-trunc.c'
+source_filename = "x86-calllowering-dbg-trunc.c"
+target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128"
+target triple = "i386"
+
+; Function Attrs: mustprogress nofree norecurse nosync nounwind readnone uwtable willreturn
+define dso_local i32 @test_dbg_trunc(i64 %a) local_unnamed_addr #0 !dbg !9 {
+; ALL-LABEL: test_dbg_trunc:
+; ALL:       # %bb.0: # %entry
+; ALL:       pushl	%ebp
+; ALL:       movl	%esp, %ebp
+; ALL:       movl	8(%ebp), %eax
+; ALL:       #DEBUG_VALUE: test_dbg_trunc:a <- undef
+; ALL:       popl	%ebp
+; ALL:       retl
+entry:
+  call void @llvm.dbg.value(metadata i64 %a, metadata !15, metadata !DIExpression()), !dbg !16
+  %conv = trunc i64 %a to i32, !dbg !17
+  ret i32 %conv, !dbg !18
+}
+
+; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.value(metadata, metadata, metadata) #1
+
+attributes #0 = { mustprogress nofree norecurse nosync nounwind readnone uwtable willreturn "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="pentium4" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
+attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
+!llvm.ident = !{!8}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 14.0.0 (https://github.com/llvm/llvm-project ...)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "x86-calllowering-dbg-trunc.c", directory: "/tmp")
+!2 = !{i32 1, !"NumRegisterParameters", i32 0}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{i32 7, !"uwtable", i32 1}
+!7 = !{i32 7, !"frame-pointer", i32 2}
+!8 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project ...)"}
+!9 = distinct !DISubprogram(name: "test_dbg_trunc", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !14)
+!10 = !DISubroutineType(types: !11)
+!11 = !{!12, !13}
+!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!13 = !DIBasicType(name: "unsigned long long", size: 64, encoding: DW_ATE_unsigned)
+!14 = !{!15}
+!15 = !DILocalVariable(name: "a", arg: 1, scope: !9, file: !1, line: 1, type: !13)
+!16 = !DILocation(line: 0, scope: !9)
+!17 = !DILocation(line: 1, column: 51, scope: !9)
+!18 = !DILocation(line: 1, column: 44, scope: !9)
Index: llvm/lib/CodeGen/GlobalISel/Utils.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -1174,14 +1174,11 @@
 /// These artifacts generally don't have any debug users because they don't
 /// directly originate from IR instructions, but instead usually from
 /// legalization. Avoiding checking for debug users improves compile time.
-/// Note that truncates or extends aren't included because they have IR
-/// counterparts which can have debug users after translation.
+/// Note that truncates, extends, value merges, or vector builders aren't
+/// included because they have IR counterparts which can have debug users after
+/// translation.
 static bool shouldSkipDbgValueFor(MachineInstr &MI) {
   switch (MI.getOpcode()) {
-  case TargetOpcode::G_UNMERGE_VALUES:
-  case TargetOpcode::G_MERGE_VALUES:
-  case TargetOpcode::G_CONCAT_VECTORS:
-  case TargetOpcode::G_BUILD_VECTOR:
   case TargetOpcode::G_EXTRACT:
   case TargetOpcode::G_INSERT:
     return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111970.380265.patch
Type: text/x-patch
Size: 4420 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211018/4aecde4b/attachment.bin>


More information about the llvm-commits mailing list