# RUN: llc -run-pass wasm-reg-coloring %s -o - | FileCheck %s
# Tests for invalid DBG_VALUE set to undef after in RegColoring
--- |
target triple = "wasm32-unknown-unknown"
declare void @use(i32)
define void @coalesce_test_0() {
call void @llvm.dbg.value(metadata i32 0, metadata !5, metadata !DIExpression()), !dbg !10
ret void
}
define void @coalesce_test_1() {
unreachable
}
define void @coalesce_test_2() {
unreachable
}
define void @coalesce_test_3() {
unreachable
}
declare void @llvm.dbg.value(metadata, metadata, metadata)
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2, !3, !4}
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, emissionKind: FullDebug)
!1 = !DIFile(filename: "test.c", directory: "")
!2 = !{i32 7, !"Dwarf Version", i32 5}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !{i32 1, !"wchar_size", i32 4}
!5 = !DILocalVariable(name: "var_a", scope: !6, file: !1, line: 2, type: !9)
!6 = distinct !DISubprogram(name: "coalesce_test_0", scope: !1, file: !1, line: 1, type: !7, scopeLine: 1, unit: !0)
!7 = !DISubroutineType(types: !8)
!8 = !{null}
!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!10 = !DILocation(line: 0, scope: !6)
!11 = !DILocalVariable(name: "var_b", scope: !6, file: !1, line: 2, type: !9)
!12 = !DILocalVariable(name: "var_c", scope: !6, file: !1, line: 2, type: !9)
...
---
# %0 and %1 are coalesced in this test
# CHECK-LABEL: name: coalesce_test_0
name: coalesce_test_0
liveins:
- { reg: '$arguments' }
tracksRegLiveness: true
body: |
bb.0:
liveins: $arguments
%0:i32 = CONST_I32 0, implicit-def $arguments
; This should remain the same
DBG_VALUE %0, $noreg, !5, !DIExpression(), debug-location !10
; This should be set to undef, because this is within %0's live range
DBG_VALUE %1, $noreg, !10, !DIExpression(), debug-location !10
CALL @use, %0, implicit-def $arguments
NOP implicit-def $arguments
%1:i32 = CONST_I32 1, implicit-def $arguments
; This should be set to undef, because this is within %1's live range
DBG_VALUE %0, $noreg, !5, !DIExpression(), debug-location !10
; This should remain the same
DBG_VALUE %1, $noreg, !10, !DIExpression(), debug-location !10
CALL @use, %1, implicit-def $arguments
RETURN implicit-def $arguments
; CHECK: %0:i32 = CONST_I32 0
; CHECK-NEXT: DBG_VALUE %0, $noreg
; CHECK-NEXT: DBG_VALUE $noreg, $noreg
; CHECK-NEXT: CALL @use, %0
; CHECK-NEXT: NOP
; CHECK-NEXT: %0:i32 = CONST_I32 1
; CHECK-NEXT: DBG_VALUE $noreg, $noreg
; CHECK-NEXT: DBG_VALUE %0, $noreg
; CHECK-NEXT: CALL @use, %0
; CHECK-NEXT: RETURN implicit-def $arguments
...
---
# A similar test with above, only with more consecutive DBG_VALUEs. These
# consecutive DBG_VALUEs will be handled with a quick last result check.
# CHECK-LABEL: name: coalesce_test_1
name: coalesce_test_1
liveins:
- { reg: '$arguments' }
tracksRegLiveness: true
body: |
bb.0:
liveins: $arguments
%0:i32 = CONST_I32 0, implicit-def $arguments
; All DBG_VALUE %1s in %0's live range will be set to undef
DBG_VALUE %1, $noreg, !10, !DIExpression(), debug-location !10
DBG_VALUE %1, $noreg, !10, !DIExpression(), debug-location !10
DBG_VALUE %0, $noreg, !5, !DIExpression(), debug-location !10
DBG_VALUE %1, $noreg, !10, !DIExpression(), debug-location !10
CALL @use, %0, implicit-def $arguments
NOP implicit-def $arguments
%1:i32 = CONST_I32 1, implicit-def $arguments
; All DBG_VALUE %0s in %1's live range will be set to undef
DBG_VALUE %0, $noreg, !5, !DIExpression(), debug-location !10
DBG_VALUE %0, $noreg, !5, !DIExpression(), debug-location !10
DBG_VALUE %1, $noreg, !10, !DIExpression(), debug-location !10
DBG_VALUE %0, $noreg, !5, !DIExpression(), debug-location !10
CALL @use, %1, implicit-def $arguments
RETURN implicit-def $arguments
; CHECK: %0:i32 = CONST_I32 0
; CHECK-NEXT: DBG_VALUE $noreg, $noreg
; CHECK-NEXT: DBG_VALUE $noreg, $noreg
; CHECK-NEXT: DBG_VALUE %0, $noreg
; CHECK-NEXT: DBG_VALUE $noreg, $noreg
; CHECK-NEXT: CALL @use, %0
; CHECK-NEXT: NOP
; CHECK-NEXT: %0:i32 = CONST_I32 1
; CHECK-NEXT: DBG_VALUE $noreg, $noreg
; CHECK-NEXT: DBG_VALUE $noreg, $noreg
; CHECK-NEXT: DBG_VALUE %0, $noreg
; CHECK-NEXT: DBG_VALUE $noreg, $noreg
; CHECK-NEXT: CALL @use, %0
; CHECK-NEXT: RETURN implicit-def $arguments
...
---
# The same with coalesce_test_0, but the two registers' live ranges are in
# different BBs.
# CHECK-LABEL: name: coalesce_test_2
name: coalesce_test_2
liveins:
- { reg: '$arguments' }
tracksRegLiveness: true
body: |
bb.0:
liveins: $arguments
%0:i32 = CONST_I32 0, implicit-def $arguments
DBG_VALUE %0, $noreg, !5, !DIExpression(), debug-location !10
DBG_VALUE %1, $noreg, !10, !DIExpression(), debug-location !10
CALL @use, %0, implicit-def $arguments
BR %bb.1, implicit-def $arguments
; CHECK: bb.0:
; CHECK: %0:i32 = CONST_I32 0
; CHECK-NEXT: DBG_VALUE %0, $noreg
; CHECK-NEXT: DBG_VALUE $noreg, $noreg
; CHECK-NEXT: CALL @use, %0
; CHECK-NEXT: BR %bb.1
bb.1:
%1:i32 = CONST_I32 1, implicit-def $arguments
DBG_VALUE %0, $noreg, !5, !DIExpression(), debug-location !10
DBG_VALUE %1, $noreg, !10, !DIExpression(), debug-location !10
CALL @use, %1, implicit-def $arguments
RETURN implicit-def $arguments
; CHECK: bb.1:
; CHECK-NEXT: %0:i32 = CONST_I32 1
; CHECK-NEXT: DBG_VALUE $noreg, $noreg
; CHECK-NEXT: DBG_VALUE %0, $noreg
; CHECK-NEXT: CALL @use, %0
; CHECK-NEXT: RETURN implicit-def $arguments
...
---
# Same test with three registers.
# CHECK-LABEL: name: coalesce_test_3
name: coalesce_test_3
liveins:
- { reg: '$arguments' }
tracksRegLiveness: true
body: |
bb.0:
liveins: $arguments
%0:i32 = CONST_I32 0, implicit-def $arguments
DBG_VALUE %0, $noreg, !5, !DIExpression(), debug-location !10
DBG_VALUE %1, $noreg, !10, !DIExpression(), debug-location !10
DBG_VALUE %2, $noreg, !11, !DIExpression(), debug-location !10
CALL @use, %0, implicit-def $arguments
NOP implicit-def $arguments
%1:i32 = CONST_I32 1, implicit-def $arguments
DBG_VALUE %0, $noreg, !5, !DIExpression(), debug-location !10
DBG_VALUE %1, $noreg, !10, !DIExpression(), debug-location !10
DBG_VALUE %2, $noreg, !11, !DIExpression(), debug-location !10
CALL @use, %1, implicit-def $arguments
NOP implicit-def $arguments
%2:i32 = CONST_I32 2, implicit-def $arguments
DBG_VALUE %0, $noreg, !5, !DIExpression(), debug-location !10
DBG_VALUE %1, $noreg, !10, !DIExpression(), debug-location !10
DBG_VALUE %2, $noreg, !11, !DIExpression(), debug-location !10
CALL @use, %2, implicit-def $arguments
RETURN implicit-def $arguments
; CHECK: %0:i32 = CONST_I32 0
; CHECK-NEXT: DBG_VALUE %0, $noreg
; CHECK-NEXT: DBG_VALUE $noreg, $noreg
; CHECK-NEXT: DBG_VALUE $noreg, $noreg
; CHECK-NEXT: CALL @use, %0
; CHECK-NEXT: NOP
; CHECK-NEXT: %0:i32 = CONST_I32 1
; CHECK-NEXT: DBG_VALUE $noreg, $noreg
; CHECK-NEXT: DBG_VALUE %0, $noreg
; CHECK-NEXT: DBG_VALUE $noreg, $noreg
; CHECK-NEXT: CALL @use, %0
; CHECK-NEXT: NOP
; CHECK-NEXT: %0:i32 = CONST_I32 2
; CHECK-NEXT: DBG_VALUE $noreg, $noreg
; CHECK-NEXT: DBG_VALUE $noreg, $noreg
; CHECK-NEXT: DBG_VALUE %0, $noreg
; CHECK-NEXT: CALL @use, %0
; CHECK-NEXT: RETURN implicit-def $arguments
---