1 ; RUN: opt < %s -passes=gvn -gvn-max-num-insns=22 -S | FileCheck %s
3 ; Debug information should not impact gvn. The following two functions have same
4 ; code except debug information. They should generate same optimized
7 %struct.a = type { i16 }
9 @f = local_unnamed_addr global i16 0, align 1
10 @m = local_unnamed_addr global ptr null, align 1
11 @h = global %struct.a zeroinitializer, align 1
13 define void @withdbg() {
14 ; CHECK-LABEL: @withdbg
15 ; CHECK: [[PRE_PRE1:%.*]] = load i16, ptr @f, align 1
16 ; CHECK-NEXT: [[PRE_PRE2:%.*]] = load ptr, ptr @m, align 1
17 ; CHECK-NEXT: br i1 true, label %[[BLOCK1:.*]], label %[[BLOCK2:.*]]
19 ; CHECK-NEXT: [[CONV:%.*]] = sext i16 [[PRE_PRE1]] to i32
20 ; CHECK-NEXT: store i32 [[CONV]], ptr [[PRE_PRE2]], align 1
23 %agg.tmp.ensured.sroa.0.i = alloca i16, align 1
24 %cmp = icmp ne ptr @withdbg, null
25 br i1 %cmp, label %lor.end, label %lor.rhs
27 lor.rhs: ; preds = %entry
28 call void @llvm.dbg.declare(metadata ptr undef, metadata !46, metadata !DIExpression()), !dbg !40
29 call void @llvm.dbg.declare(metadata ptr undef, metadata !47, metadata !DIExpression()), !dbg !40
30 call void @llvm.dbg.declare(metadata ptr undef, metadata !48, metadata !DIExpression()), !dbg !40
31 call void @llvm.dbg.declare(metadata ptr undef, metadata !49, metadata !DIExpression()), !dbg !40
32 call void @llvm.dbg.declare(metadata ptr undef, metadata !50, metadata !DIExpression()), !dbg !40
33 %agg.tmp.ensured.sroa.0.0.copyload.i = load volatile i16, ptr @h, align 1
34 store i16 %agg.tmp.ensured.sroa.0.0.copyload.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
35 %agg.tmp.ensured.sroa.0.0.copyload.1.i = load volatile i16, ptr @h, align 1
36 store i16 %agg.tmp.ensured.sroa.0.0.copyload.1.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
37 %agg.tmp.ensured.sroa.0.0.copyload.2.i = load volatile i16, ptr @h, align 1
38 store i16 %agg.tmp.ensured.sroa.0.0.copyload.2.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
39 %agg.tmp.ensured.sroa.0.0.copyload.3.i = load volatile i16, ptr @h, align 1
40 store i16 %agg.tmp.ensured.sroa.0.0.copyload.3.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
41 %agg.tmp.ensured.sroa.0.0.copyload.4.i = load volatile i16, ptr @h, align 1
42 store i16 %agg.tmp.ensured.sroa.0.0.copyload.4.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
43 %agg.tmp.ensured.sroa.0.0.copyload.5.i = load volatile i16, ptr @h, align 1
44 store i16 %agg.tmp.ensured.sroa.0.0.copyload.5.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
45 %agg.tmp.ensured.sroa.0.0.copyload.6.i = load volatile i16, ptr @h, align 1
46 store i16 %agg.tmp.ensured.sroa.0.0.copyload.6.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
47 %agg.tmp.ensured.sroa.0.0.copyload.7.i = load volatile i16, ptr @h, align 1
48 store i16 %agg.tmp.ensured.sroa.0.0.copyload.7.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
49 %agg.tmp.ensured.sroa.0.0.copyload.8.i = load volatile i16, ptr @h, align 1
50 store i16 %agg.tmp.ensured.sroa.0.0.copyload.8.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
51 %fvalue = load i16, ptr @f, align 1
52 %mvalue = load ptr, ptr @m, align 1
55 lor.end: ; preds = %lor.rhs, %entry
56 %tmp11 = load i16, ptr @f, align 1
57 %conv.i.i6 = sext i16 %tmp11 to i32
58 %tmp12 = load ptr, ptr @m, align 1
59 store i32 %conv.i.i6, ptr %tmp12, align 1
63 define void @lessdbg() {
64 ; CHECK-LABEL: @lessdbg
65 ; CHECK: [[PRE_PRE1:%.*]] = load i16, ptr @f, align 1
66 ; CHECK-NEXT: [[PRE_PRE2:%.*]] = load ptr, ptr @m, align 1
67 ; CHECK-NEXT: br i1 true, label %[[BLOCK1:.*]], label %[[BLOCK2:.*]]
69 ; CHECK-NEXT: [[CONV:%.*]] = sext i16 [[PRE_PRE1]] to i32
70 ; CHECK-NEXT: store i32 [[CONV]], ptr [[PRE_PRE2]], align 1
73 %agg.tmp.ensured.sroa.0.i = alloca i16, align 1
74 %cmp = icmp ne ptr @lessdbg, null
75 br i1 %cmp, label %lor.end, label %lor.rhs
77 lor.rhs: ; preds = %entry
78 %agg.tmp.ensured.sroa.0.0.copyload.i = load volatile i16, ptr @h, align 1
79 store i16 %agg.tmp.ensured.sroa.0.0.copyload.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
80 %agg.tmp.ensured.sroa.0.0.copyload.1.i = load volatile i16, ptr @h, align 1
81 store i16 %agg.tmp.ensured.sroa.0.0.copyload.1.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
82 %agg.tmp.ensured.sroa.0.0.copyload.2.i = load volatile i16, ptr @h, align 1
83 store i16 %agg.tmp.ensured.sroa.0.0.copyload.2.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
84 %agg.tmp.ensured.sroa.0.0.copyload.3.i = load volatile i16, ptr @h, align 1
85 store i16 %agg.tmp.ensured.sroa.0.0.copyload.3.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
86 %agg.tmp.ensured.sroa.0.0.copyload.4.i = load volatile i16, ptr @h, align 1
87 store i16 %agg.tmp.ensured.sroa.0.0.copyload.4.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
88 %agg.tmp.ensured.sroa.0.0.copyload.5.i = load volatile i16, ptr @h, align 1
89 store i16 %agg.tmp.ensured.sroa.0.0.copyload.5.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
90 %agg.tmp.ensured.sroa.0.0.copyload.6.i = load volatile i16, ptr @h, align 1
91 store i16 %agg.tmp.ensured.sroa.0.0.copyload.6.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
92 %agg.tmp.ensured.sroa.0.0.copyload.7.i = load volatile i16, ptr @h, align 1
93 store i16 %agg.tmp.ensured.sroa.0.0.copyload.7.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
94 %agg.tmp.ensured.sroa.0.0.copyload.8.i = load volatile i16, ptr @h, align 1
95 store i16 %agg.tmp.ensured.sroa.0.0.copyload.8.i, ptr %agg.tmp.ensured.sroa.0.i, align 1
96 %fvalue = load i16, ptr @f, align 1
97 %mvalue = load ptr, ptr @m, align 1
100 lor.end: ; preds = %lor.rhs, %entry
101 %tmp11 = load i16, ptr @f, align 1
102 %conv.i.i6 = sext i16 %tmp11 to i32
103 %tmp12 = load ptr, ptr @m, align 1
104 store i32 %conv.i.i6, ptr %tmp12, align 1
108 declare void @llvm.dbg.declare(metadata, metadata, metadata)
111 !llvm.module.flags = !{!35, !36}
113 !0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 17.0.0.prerel", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
114 !1 = !DIFile(filename: "bbi-78272.c", directory: "/tmp")
115 !5 = !DIBasicType(name: "int", size: 16, encoding: DW_ATE_signed)
117 !35 = !{i32 7, !"Dwarf Version", i32 4}
118 !36 = !{i32 2, !"Debug Info Version", i32 3}
119 !40 = !DILocation(line: 15, column: 7, scope: !41)
120 !41 = distinct !DISubprogram(name: "x", scope: !1, file: !1, line: 14, type: !42, scopeLine: 14, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !45)
121 !42 = !DISubroutineType(types: !43)
123 !45 = !{!46, !47, !48, !49, !50}
124 !46 = !DILocalVariable(name: "t", scope: !41, file: !1, line: 15, type: !5)
125 !47 = !DILocalVariable(name: "c", scope: !41, file: !1, line: 15, type: !5)
126 !48 = !DILocalVariable(name: "v", scope: !41, file: !1, line: 15, type: !5)
127 !49 = !DILocalVariable(name: "d", scope: !41, file: !1, line: 15, type: !5)
128 !50 = !DILocalVariable(name: "u", scope: !41, file: !1, line: 16, type: !5)