240 lines · plain
1 2# RUN: llc -mtriple=aarch64-none-linux-gnu -verify-machineinstrs -run-pass=livedebugvalues %s -o - | FileCheck %s3 4#5# This test is for the problem from https://bugs.llvm.org/show_bug.cgi?id=38714.6# 7# Specifically, Register Coalescer creates following conversion :8#9# undef %0.sub_32:gpr64 = ORRWrs $wzr, %3:gpr32common, 0, debug-location !24;10#11# It copies 32-bit value from gpr32 into gpr64. But later Live DEBUG_VALUE analysis12# is not able to create debug location record for that instruction. The fix is13# to write custom isCopyInstrImpl() which would recognize the ORRWrs instr as14# move instruction.15#16# The LLVM-IR below was produced by clang on the following C++ code:17# 18# int printf(const char* restrict format, ...);19# 20# 21# int main( int argc, char **argv )22# {23# for(int i = 1; i < argc; ++i) {24# printf("Argument %d: %s\n", i, argv[i]);25# }26# return 0;27# }28# 29 30# CHECK-LABEL: main31# CHECK: DBG_VALUE $w0, $noreg32# CHECK: renamable $[[REG1:w[0-9]+]] = ORRWrs $wzr, killed renamable $w0, 033# CHECK: DBG_VALUE $[[REG1]], $noreg34 35 36--- |37 ; ModuleID = '<stdin>'38 source_filename = "test.c"39 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"40 target triple = "aarch64-unknown-linux"41 42 @.str = private unnamed_addr constant [17 x i8] c"Argument %d: %s\0A\00", align 143 44 ; Function Attrs: nounwind45 define dso_local i32 @main(i32 %argc, ptr nocapture readonly %argv) local_unnamed_addr #0 !dbg !7 {46 entry:47 call void @llvm.dbg.value(metadata i32 %argc, metadata !15, metadata !DIExpression()), !dbg !1948 call void @llvm.dbg.value(metadata ptr %argv, metadata !16, metadata !DIExpression()), !dbg !1949 call void @llvm.dbg.value(metadata i32 1, metadata !17, metadata !DIExpression()), !dbg !2050 %cmp5 = icmp sgt i32 %argc, 1, !dbg !2151 br i1 %cmp5, label %for.body.preheader, label %for.cond.cleanup, !dbg !2352 53 for.body.preheader: ; preds = %entry54 %wide.trip.count = zext i32 %argc to i64, !dbg !2455 br label %for.body, !dbg !2556 57 for.cond.cleanup: ; preds = %for.body, %entry58 ret i32 0, !dbg !2759 60 for.body: ; preds = %for.body, %for.body.preheader61 %indvars.iv = phi i64 [ 1, %for.body.preheader ], [ %indvars.iv.next, %for.body ]62 call void @llvm.dbg.value(metadata i64 %indvars.iv, metadata !17, metadata !DIExpression()), !dbg !2063 %scevgep = getelementptr ptr, ptr %argv, i64 %indvars.iv, !dbg !2564 %0 = load ptr, ptr %scevgep, align 8, !dbg !25, !tbaa !2865 %tmp = trunc i64 %indvars.iv to i3266 %call = tail call i32 (ptr, ...) @printf(ptr @.str, i32 %tmp, ptr %0), !dbg !3267 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !3368 call void @llvm.dbg.value(metadata i32 undef, metadata !17, metadata !DIExpression(DW_OP_plus_uconst, 1, DW_OP_stack_value)), !dbg !2069 %exitcond = icmp eq i64 %wide.trip.count, %indvars.iv.next, !dbg !2170 br i1 %exitcond, label %for.cond.cleanup, label %for.body, !dbg !23, !llvm.loop !3471 }72 73 ; Function Attrs: nounwind74 declare dso_local i32 @printf(ptr nocapture readonly, ...) local_unnamed_addr #175 76 ; Function Attrs: nounwind readnone speculatable77 declare void @llvm.dbg.value(metadata, metadata, metadata) #278 79 ; Function Attrs: nounwind80 declare void @llvm.stackprotector(ptr, ptr) #381 82 attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "frame-pointer"="all" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+neon" "use-soft-float"="false" }83 attributes #1 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+neon" "use-soft-float"="false" }84 attributes #2 = { nounwind readnone speculatable }85 attributes #3 = { nounwind }86 87 !llvm.dbg.cu = !{!0}88 !llvm.module.flags = !{!3, !4, !5}89 !llvm.ident = !{!6}90 91 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)92 !1 = !DIFile(filename: "test.c", directory: "test")93 !2 = !{}94 !3 = !{i32 2, !"Dwarf Version", i32 4}95 !4 = !{i32 2, !"Debug Info Version", i32 3}96 !5 = !{i32 1, !"wchar_size", i32 4}97 !6 = !{!"clang version 9.0.0 "}98 !7 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 6, type: !8, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !14)99 !8 = !DISubroutineType(types: !9)100 !9 = !{!10, !10, !11}101 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)102 !11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)103 !12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)104 !13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_unsigned_char)105 !14 = !{!15, !16, !17}106 !15 = !DILocalVariable(name: "argc", arg: 1, scope: !7, file: !1, line: 6, type: !10)107 !16 = !DILocalVariable(name: "argv", arg: 2, scope: !7, file: !1, line: 6, type: !11)108 !17 = !DILocalVariable(name: "i", scope: !18, file: !1, line: 8, type: !10)109 !18 = distinct !DILexicalBlock(scope: !7, file: !1, line: 8, column: 3)110 !19 = !DILocation(line: 0, scope: !7)111 !20 = !DILocation(line: 0, scope: !18)112 !21 = !DILocation(line: 8, column: 20, scope: !22)113 !22 = distinct !DILexicalBlock(scope: !18, file: !1, line: 8, column: 3)114 !23 = !DILocation(line: 8, column: 3, scope: !18)115 !24 = !DILocation(line: 0, scope: !22)116 !25 = !DILocation(line: 9, column: 36, scope: !26)117 !26 = distinct !DILexicalBlock(scope: !22, file: !1, line: 8, column: 33)118 !27 = !DILocation(line: 11, column: 3, scope: !7)119 !28 = !{!29, !29, i64 0}120 !29 = !{!"any pointer", !30, i64 0}121 !30 = !{!"omnipotent char", !31, i64 0}122 !31 = !{!"Simple C/C++ TBAA"}123 !32 = !DILocation(line: 9, column: 5, scope: !26)124 !33 = !DILocation(line: 8, column: 28, scope: !22)125 !34 = distinct !{!34, !23, !35}126 !35 = !DILocation(line: 10, column: 3, scope: !18)127 128...129---130name: main131alignment: 4132exposesReturnsTwice: false133legalized: false134regBankSelected: false135selected: false136failedISel: false137tracksRegLiveness: true138hasWinCFI: false139registers: []140liveins: 141 - { reg: '$w0', virtual-reg: '' }142 - { reg: '$x1', virtual-reg: '' }143frameInfo: 144 isFrameAddressTaken: false145 isReturnAddressTaken: false146 hasStackMap: false147 hasPatchPoint: false148 stackSize: 48149 offsetAdjustment: 0150 maxAlignment: 8151 adjustsStack: true152 hasCalls: true153 stackProtector: ''154 maxCallFrameSize: 0155 cvBytesOfCalleeSavedRegisters: 0156 hasOpaqueSPAdjustment: false157 hasVAStart: false158 hasMustTailInVarArgFunc: false159 localFrameSize: 0160 savePoint: []161 restorePoint: []162fixedStack: []163stack: 164 - { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8, 165 stack-id: default, callee-saved-register: '$lr', callee-saved-restored: true, 166 debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }167 - { id: 1, name: '', type: spill-slot, offset: -16, size: 8, alignment: 8, 168 stack-id: default, callee-saved-register: '$fp', callee-saved-restored: true,169 debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }170 - { id: 2, name: '', type: spill-slot, offset: -24, size: 8, alignment: 8, 171 stack-id: default, callee-saved-register: '$x19', callee-saved-restored: true, 172 debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }173 - { id: 3, name: '', type: spill-slot, offset: -32, size: 8, alignment: 8, 174 stack-id: default, callee-saved-register: '$x20', callee-saved-restored: true, 175 debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }176 - { id: 4, name: '', type: spill-slot, offset: -40, size: 8, alignment: 8, 177 stack-id: default, callee-saved-register: '$x21', callee-saved-restored: true, 178 debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }179 - { id: 5, name: '', type: spill-slot, offset: -48, size: 8, alignment: 8, 180 stack-id: default, callee-saved-register: '$x22', callee-saved-restored: true, 181 debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }182constants: []183machineFunctionInfo: {}184body: |185 bb.0.entry:186 successors: %bb.1(0x40000000), %bb.3(0x40000000)187 liveins: $w0, $x1, $x21, $x22, $x19, $x20, $lr188 189 DBG_VALUE $w0, $noreg, !15, !DIExpression(), debug-location !19190 DBG_VALUE $w0, $noreg, !15, !DIExpression(), debug-location !19191 DBG_VALUE $x1, $noreg, !16, !DIExpression(), debug-location !19192 early-clobber $sp = frame-setup STPXpre killed $x22, killed $x21, $sp, -6 :: (store (s64) into %stack.5), (store (s64) into %stack.4)193 frame-setup STPXi killed $x20, killed $x19, $sp, 2 :: (store (s64) into %stack.3), (store (s64) into %stack.2)194 frame-setup STPXi $fp, killed $lr, $sp, 4 :: (store (s64) into %stack.1), (store (s64) into %stack.0)195 $fp = frame-setup ADDXri $sp, 32, 0196 frame-setup CFI_INSTRUCTION def_cfa $w29, 16197 frame-setup CFI_INSTRUCTION offset $w30, -8, debug-location !23198 frame-setup CFI_INSTRUCTION offset $w29, -16, debug-location !23199 frame-setup CFI_INSTRUCTION offset $w19, -24, debug-location !23200 frame-setup CFI_INSTRUCTION offset $w20, -32, debug-location !23201 frame-setup CFI_INSTRUCTION offset $w21, -40, debug-location !23202 frame-setup CFI_INSTRUCTION offset $w22, -48, debug-location !23203 DBG_VALUE 1, $noreg, !17, !DIExpression(), debug-location !20204 dead $wzr = SUBSWri renamable $w0, 2, 0, implicit-def $nzcv, debug-location !23205 Bcc 11, %bb.3, implicit $nzcv, debug-location !23206 207 bb.1.for.body.preheader:208 successors: %bb.2(0x80000000)209 liveins: $w0, $x1210 211 $x21 = ADRP target-flags(aarch64-page) @.str212 $x19 = ORRXrs $xzr, killed $x1, 0213 DBG_VALUE $x19, $noreg, !16, !DIExpression(), debug-location !19214 renamable $w22 = ORRWrs $wzr, killed renamable $w0, 0, implicit-def $x22, debug-location !24215 $w20 = MOVZWi 1, 0, implicit-def $x20216 renamable $x21 = ADDXri killed $x21, target-flags(aarch64-pageoff, aarch64-nc) @.str, 0217 218 bb.2.for.body:219 successors: %bb.3(0x04000000), %bb.2(0x7c000000)220 liveins: $x19, $x20, $x21, $x22221 222 DBG_VALUE $x20, $noreg, !17, !DIExpression(), debug-location !20223 renamable $x2 = LDRXroX renamable $x19, renamable $x20, 0, 1, debug-location !25 :: (load (s64) from %ir.scevgep, !tbaa !28)224 $x0 = ORRXrs $xzr, $x21, 0, debug-location !32225 $w1 = ORRWrs $wzr, $w20, 0, debug-location !32226 BL @printf, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit killed $x0, implicit killed $w1, implicit killed $x2, implicit-def $sp, implicit-def dead $w0, debug-location !32227 renamable $x20 = nuw nsw ADDXri killed renamable $x20, 1, 0, debug-location !33228 DBG_VALUE $noreg, $noreg, !17, !DIExpression(DW_OP_plus_uconst, 1, DW_OP_stack_value), debug-location !20229 $xzr = SUBSXrs renamable $x22, renamable $x20, 0, implicit-def $nzcv, implicit-def $nzcv, debug-location !23230 Bcc 1, %bb.2, implicit killed $nzcv, debug-location !23231 232 bb.3.for.cond.cleanup:233 $fp, $lr = frame-destroy LDPXi $sp, 4, debug-location !27 :: (load (s64) from %stack.1), (load (s64) from %stack.0)234 $x20, $x19 = frame-destroy LDPXi $sp, 2, debug-location !27 :: (load (s64) from %stack.3), (load (s64) from %stack.2)235 $w0 = ORRWrs $wzr, $wzr, 0, debug-location !27236 early-clobber $sp, $x22, $x21 = frame-destroy LDPXpost $sp, 6, debug-location !27 :: (load (s64) from %stack.5), (load (s64) from %stack.4)237 RET undef $lr, implicit killed $w0, debug-location !27238 239...240