1; RUN: opt -S -codegenprepare < %s | FileCheck %s 2; 3; This test case was generated from the following source code: 4; 5; long long foo(int *ptr, int cond) { 6; long long result = 3; 7; unsigned val = *ptr; // line 3 8; switch (cond) { 9; case 3: 10; result = val; // line 6 11; break; 12; case 4: 13; result += 2; 14; } 15; 16; return result + val; 17; }; 18; 19; When CGP moves a zext Z of a load L to the block where L lives, Z should not 20; retain its original debug location. Instead, Z should reuse the debug location 21; associated with L. Logically the zero extend will become part of the load; the 22; code generator will attempt to fuse the two instructions into a zextload. 23 24; CHECK-LABEL: @test 25; CHECK: [[LOADVAL:%[0-9]+]] = load i32, i32* %ptr, align 4, !dbg [[DEBUGLOC:![0-9]+]] 26; CHECK-NEXT: zext i32 [[LOADVAL]] to i64, !dbg [[DEBUGLOC]] 27; CHECK: [[DEBUGLOC]] = !DILocation(line: 3 28 29target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 30target triple = "x86_64-unknown-linux-gnu" 31 32define i64 @test(i32* %ptr, i32 %cond) !dbg !5 { 33entry: 34 %0 = load i32, i32* %ptr, align 4, !dbg !7 35 switch i32 %cond, label %sw.epilog [ 36 i32 3, label %sw.bb 37 i32 4, label %sw.bb1 38 ], !dbg !8 39 40sw.bb: ; preds = %entry 41 %conv = zext i32 %0 to i64, !dbg !9 42 br label %sw.epilog, !dbg !10 43 44sw.bb1: ; preds = %entry 45 br label %sw.epilog, !dbg !11 46 47sw.epilog: ; preds = %sw.bb1, %entry, %sw.bb 48 %result.0 = phi i64 [ 3, %entry ], [ 5, %sw.bb1 ], [ %conv, %sw.bb ] 49 %conv2 = zext i32 %0 to i64, !dbg !12 50 %add3 = add nuw nsw i64 %result.0, %conv2, !dbg !13 51 ret i64 %add3, !dbg !14 52} 53 54!llvm.dbg.cu = !{!0} 55!llvm.module.flags = !{!3, !4} 56 57!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2) 58!1 = !DIFile(filename: "test.c", directory: "") 59!2 = !{} 60!3 = !{i32 2, !"Dwarf Version", i32 4} 61!4 = !{i32 2, !"Debug Info Version", i32 3} 62!5 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2) 63!6 = !DISubroutineType(types: !2) 64!7 = !DILocation(line: 3, column: 18, scope: !5) 65!8 = !DILocation(line: 4, column: 3, scope: !5) 66!9 = !DILocation(line: 6, column: 14, scope: !5) 67!10 = !DILocation(line: 7, column: 5, scope: !5) 68!11 = !DILocation(line: 10, column: 3, scope: !5) 69!12 = !DILocation(line: 12, column: 19, scope: !5) 70!13 = !DILocation(line: 12, column: 17, scope: !5) 71!14 = !DILocation(line: 12, column: 3, scope: !5) 72