1# RUN: llc -mtriple=x86_64-unknown-unknown -start-after=peephole-opt -stop-before=detect-dead-lanes -o - %s | FileCheck %s 2 3# Test that the optimize LEA pass can remove a redundant LEA even when it is 4# also used by a DBG_VALUE. Check that the uses of the replaced LEA are updated 5# correctly. 6 7--- | 8 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 9 10 %struct.A = type { i32, i32, i32 } 11 12 @c = common local_unnamed_addr global %struct.A* null, align 8 13 @a = common local_unnamed_addr global i32 0, align 4 14 @d = common local_unnamed_addr global i32 0, align 4 15 @b = common local_unnamed_addr global i32 0, align 4 16 17 define i32 @fn1() local_unnamed_addr !dbg !8 { 18 %1 = load %struct.A*, %struct.A** @c, align 8, !dbg !13 19 %2 = load i32, i32* @a, align 4, !dbg !13 20 %3 = sext i32 %2 to i64, !dbg !13 21 %4 = getelementptr inbounds %struct.A, %struct.A* %1, i64 %3, !dbg !13 22 %5 = ptrtoint %struct.A* %4 to i64, !dbg !13 23 %6 = trunc i64 %5 to i32, !dbg !13 24 store i32 %6, i32* @d, align 4, !dbg !13 25 %7 = getelementptr inbounds %struct.A, %struct.A* %1, i64 %3, i32 2, !dbg !14 26 tail call void @llvm.dbg.value(metadata i32* %7, i64 0, metadata !11, metadata !DIExpression()), !dbg !15 27 br label %8, !dbg !16 28 29 ; <label>:8: ; preds = %8, %0 30 %9 = load i32, i32* %7, align 4, !dbg !17 31 store i32 %9, i32* @d, align 4, !dbg !17 32 br label %8, !dbg !18 33 } 34 35 ; Function Attrs: nounwind readnone 36 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #0 37 38 attributes #0 = { nounwind readnone } 39 40 !llvm.dbg.cu = !{!0} 41 !llvm.module.flags = !{!5, !6, !7} 42 43 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, globals: !2) 44 !1 = !DIFile(filename: "test.c", directory: "") 45 !2 = !{} 46 !3 = !{!4} 47 !4 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 48 !5 = !{i32 2, !"Dwarf Version", i32 4} 49 !6 = !{i32 2, !"Debug Info Version", i32 3} 50 !7 = !{i32 1, !"PIC Level", i32 2} 51 !8 = distinct !DISubprogram(name: "fn1", scope: !1, file: !1, line: 7, type: !9, isLocal: false, isDefinition: true, scopeLine: 7, isOptimized: true, unit: !0, retainedNodes: !10) 52 !9 = !DISubroutineType(types: !3) 53 !10 = !{!11} 54 !11 = !DILocalVariable(name: "e", scope: !8, file: !1, line: 8, type: !12) 55 !12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !4, size: 64) 56 !13 = !DILocation(line: 9, scope: !8) 57 !14 = !DILocation(line: 10, scope: !8) 58 !15 = !DILocation(line: 8, scope: !8) 59 !16 = !DILocation(line: 11, scope: !8) 60 !17 = !DILocation(line: 13, scope: !8) 61 !18 = !DILocation(line: 14, scope: !8) 62 63... 64--- 65name: fn1 66alignment: 4 67exposesReturnsTwice: false 68legalized: false 69regBankSelected: false 70selected: false 71tracksRegLiveness: true 72registers: 73 - { id: 0, class: gr64 } 74 - { id: 1, class: gr64 } 75 - { id: 2, class: gr64_nosp } 76 - { id: 3, class: gr64_nosp } 77 - { id: 4, class: gr64 } 78 - { id: 5, class: gr32 } 79 - { id: 6, class: gr32 } 80frameInfo: 81 isFrameAddressTaken: false 82 isReturnAddressTaken: false 83 hasStackMap: false 84 hasPatchPoint: false 85 stackSize: 0 86 offsetAdjustment: 0 87 maxAlignment: 0 88 adjustsStack: false 89 hasCalls: false 90 maxCallFrameSize: 0 91 hasOpaqueSPAdjustment: false 92 hasVAStart: false 93 hasMustTailInVarArgFunc: false 94body: | 95 bb.0 (%ir-block.0): 96 successors: %bb.1(0x80000000) 97 98 ; CHECK: %3:gr64_nosp = LEA64r %2, 2, %2, 0, $noreg, debug-location !13 99 ; CHECK-NEXT: %4:gr64 = LEA64r %1, 4, %3, 0, $noreg, debug-location !13 100 ; CHECK-NOT: %0:gr64 = LEA64r %1, 4, %3, 8, $noreg, debug-location !14 101 ; CHECK: DBG_VALUE debug-use %4, debug-use $noreg, !11, !DIExpression(DW_OP_plus_uconst, 8, DW_OP_stack_value), debug-location !15 102 103 %1 = MOV64rm $rip, 1, $noreg, @c, $noreg, debug-location !13 :: (dereferenceable load 8 from @c) 104 %2 = MOVSX64rm32 $rip, 1, $noreg, @a, $noreg, debug-location !13 :: (dereferenceable load 4 from @a) 105 %3 = LEA64r %2, 2, %2, 0, $noreg, debug-location !13 106 %4 = LEA64r %1, 4, %3, 0, $noreg, debug-location !13 107 %5 = COPY %4.sub_32bit, debug-location !13 108 MOV32mr $rip, 1, $noreg, @d, $noreg, killed %5, debug-location !13 :: (store 4 into @d) 109 %0 = LEA64r %1, 4, %3, 8, $noreg, debug-location !14 110 DBG_VALUE debug-use %0, debug-use $noreg, !11, !DIExpression(), debug-location !15 111 112 ; CHECK-LABEL: bb.1 (%ir-block.8): 113 ; CHECK: %6:gr32 = MOV32rm %4, 1, $noreg, 8, $noreg, debug-location !17 :: (load 4 from %ir.7) 114 115 bb.1 (%ir-block.8): 116 successors: %bb.1(0x80000000) 117 118 %6 = MOV32rm %0, 1, $noreg, 0, $noreg, debug-location !17 :: (load 4 from %ir.7) 119 MOV32mr $rip, 1, $noreg, @d, $noreg, killed %6, debug-location !17 :: (store 4 into @d) 120 JMP_1 %bb.1, debug-location !18 121 122... 123