1 ; RUN: opt -S -codegenprepare < %s | FileCheck %s
3 ; This test case was generated from the following source code:
5 ; long long foo(int *ptr, int cond) {
6 ; long long result = 3;
7 ; unsigned val = *ptr; // line 3
10 ; result = val; // line 6
16 ; return result + val;
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.
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
29 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
30 target triple = "x86_64-unknown-linux-gnu"
32 define i64 @test(i32* %ptr, i32 %cond) !dbg !5 {
34 %0 = load i32, i32* %ptr, align 4, !dbg !7
35 switch i32 %cond, label %sw.epilog [
40 sw.bb: ; preds = %entry
41 %conv = zext i32 %0 to i64, !dbg !9
42 br label %sw.epilog, !dbg !10
44 sw.bb1: ; preds = %entry
45 br label %sw.epilog, !dbg !11
47 sw.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
55 !llvm.module.flags = !{!3, !4}
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: "")
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)