|
| 1 | +; RUN: opt -mtriple=aarch64-unknown-linux-gnu -S %s -passes=sroa -o - | FileCheck %s |
| 2 | + |
| 3 | +; In this test we want to ensure that the location of phi instruction merged from locations |
| 4 | +; of %mul3 and %mul9 belongs to the correct scope (DILexicalBlockFile), so that line |
| 5 | +; number of that location belongs to the corresponding file. |
| 6 | + |
| 7 | +; Generated with clang from |
| 8 | +; # 1 "1.c" 1 |
| 9 | +; # 1 "1.c" 2 |
| 10 | +; int foo(int a) { |
| 11 | +; int i = 0; |
| 12 | +; if ((a & 1) == 1) { |
| 13 | +; a -= 1; |
| 14 | +; # 1 "m.c" 1 |
| 15 | +; # 40 "m.c" |
| 16 | +; i += a; |
| 17 | +; i -= 10*a; |
| 18 | +; i *= a*a; |
| 19 | +; # 6 "1.c" 2 |
| 20 | +; } else { |
| 21 | +; a += 3; |
| 22 | +; # 1 "m.c" 1 |
| 23 | +; # 40 "m.c" |
| 24 | +; i += a; |
| 25 | +; i -= 10*a; |
| 26 | +; i *= a*a; |
| 27 | +; # 9 "1.c" 2 |
| 28 | +; } |
| 29 | +; return i; |
| 30 | +; } |
| 31 | + |
| 32 | +source_filename = "repro.c" |
| 33 | +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32" |
| 34 | +target triple = "aarch64-unknown-linux-gnu" |
| 35 | + |
| 36 | +; Function Attrs: nounwind uwtable |
| 37 | +define dso_local i32 @foo(i32 noundef %a) !dbg !9 { |
| 38 | +; CHECK: phi i32 {{.*}}, !dbg [[PHILOC:![0-9]+]] |
| 39 | +; |
| 40 | +entry: |
| 41 | + %a.addr = alloca i32, align 4, !DIAssignID !17 |
| 42 | + #dbg_assign(i1 undef, !15, !DIExpression(), !17, ptr %a.addr, !DIExpression(), !18) |
| 43 | + %i = alloca i32, align 4, !DIAssignID !19 |
| 44 | + #dbg_assign(i1 undef, !16, !DIExpression(), !19, ptr %i, !DIExpression(), !18) |
| 45 | + store i32 %a, ptr %a.addr, align 4, !tbaa !20, !DIAssignID !24 |
| 46 | + #dbg_assign(i32 %a, !15, !DIExpression(), !24, ptr %a.addr, !DIExpression(), !18) |
| 47 | + call void @llvm.lifetime.start.p0(i64 4, ptr %i), !dbg !25 |
| 48 | + store i32 0, ptr %i, align 4, !dbg !26, !tbaa !20, !DIAssignID !27 |
| 49 | + #dbg_assign(i32 0, !16, !DIExpression(), !27, ptr %i, !DIExpression(), !18) |
| 50 | + %0 = load i32, ptr %a.addr, align 4, !dbg !28, !tbaa !20 |
| 51 | + %and = and i32 %0, 1, !dbg !30 |
| 52 | + %cmp = icmp eq i32 %and, 1, !dbg !31 |
| 53 | + br i1 %cmp, label %if.then, label %if.else, !dbg !31 |
| 54 | + |
| 55 | +if.then: ; preds = %entry |
| 56 | + %1 = load i32, ptr %a.addr, align 4, !dbg !32, !tbaa !20 |
| 57 | + %sub = sub nsw i32 %1, 1, !dbg !32 |
| 58 | + store i32 %sub, ptr %a.addr, align 4, !dbg !32, !tbaa !20, !DIAssignID !34 |
| 59 | + #dbg_assign(i32 %sub, !15, !DIExpression(), !34, ptr %a.addr, !DIExpression(), !18) |
| 60 | + %2 = load i32, ptr %a.addr, align 4, !dbg !35, !tbaa !20 |
| 61 | + %3 = load i32, ptr %i, align 4, !dbg !38, !tbaa !20 |
| 62 | + %add = add nsw i32 %3, %2, !dbg !38 |
| 63 | + store i32 %add, ptr %i, align 4, !dbg !38, !tbaa !20, !DIAssignID !39 |
| 64 | + #dbg_assign(i32 %add, !16, !DIExpression(), !39, ptr %i, !DIExpression(), !18) |
| 65 | + %4 = load i32, ptr %a.addr, align 4, !dbg !40, !tbaa !20 |
| 66 | + %mul = mul nsw i32 10, %4, !dbg !41 |
| 67 | + %5 = load i32, ptr %i, align 4, !dbg !42, !tbaa !20 |
| 68 | + %sub1 = sub nsw i32 %5, %mul, !dbg !42 |
| 69 | + store i32 %sub1, ptr %i, align 4, !dbg !42, !tbaa !20, !DIAssignID !43 |
| 70 | + #dbg_assign(i32 %sub1, !16, !DIExpression(), !43, ptr %i, !DIExpression(), !18) |
| 71 | + %6 = load i32, ptr %a.addr, align 4, !dbg !44, !tbaa !20 |
| 72 | + %7 = load i32, ptr %a.addr, align 4, !dbg !45, !tbaa !20 |
| 73 | + %mul2 = mul nsw i32 %6, %7, !dbg !46 |
| 74 | + %8 = load i32, ptr %i, align 4, !dbg !47, !tbaa !20 |
| 75 | + %mul3 = mul nsw i32 %8, %mul2, !dbg !47 |
| 76 | + store i32 %mul3, ptr %i, align 4, !dbg !47, !tbaa !20, !DIAssignID !48 |
| 77 | + #dbg_assign(i32 %mul3, !16, !DIExpression(), !48, ptr %i, !DIExpression(), !18) |
| 78 | + br label %if.end, !dbg !49 |
| 79 | + |
| 80 | +if.else: ; preds = %entry |
| 81 | + %9 = load i32, ptr %a.addr, align 4, !dbg !51, !tbaa !20 |
| 82 | + %add4 = add nsw i32 %9, 3, !dbg !51 |
| 83 | + store i32 %add4, ptr %a.addr, align 4, !dbg !51, !tbaa !20, !DIAssignID !53 |
| 84 | + #dbg_assign(i32 %add4, !15, !DIExpression(), !53, ptr %a.addr, !DIExpression(), !18) |
| 85 | + %10 = load i32, ptr %a.addr, align 4, !dbg !54, !tbaa !20 |
| 86 | + %11 = load i32, ptr %i, align 4, !dbg !56, !tbaa !20 |
| 87 | + %add5 = add nsw i32 %11, %10, !dbg !56 |
| 88 | + store i32 %add5, ptr %i, align 4, !dbg !56, !tbaa !20, !DIAssignID !57 |
| 89 | + #dbg_assign(i32 %add5, !16, !DIExpression(), !57, ptr %i, !DIExpression(), !18) |
| 90 | + %12 = load i32, ptr %a.addr, align 4, !dbg !58, !tbaa !20 |
| 91 | + %mul6 = mul nsw i32 10, %12, !dbg !59 |
| 92 | + %13 = load i32, ptr %i, align 4, !dbg !60, !tbaa !20 |
| 93 | + %sub7 = sub nsw i32 %13, %mul6, !dbg !60 |
| 94 | + store i32 %sub7, ptr %i, align 4, !dbg !60, !tbaa !20, !DIAssignID !61 |
| 95 | + #dbg_assign(i32 %sub7, !16, !DIExpression(), !61, ptr %i, !DIExpression(), !18) |
| 96 | + %14 = load i32, ptr %a.addr, align 4, !dbg !62, !tbaa !20 |
| 97 | + %15 = load i32, ptr %a.addr, align 4, !dbg !63, !tbaa !20 |
| 98 | + %mul8 = mul nsw i32 %14, %15, !dbg !64 |
| 99 | + %16 = load i32, ptr %i, align 4, !dbg !65, !tbaa !20 |
| 100 | + %mul9 = mul nsw i32 %16, %mul8, !dbg !65 |
| 101 | + store i32 %mul9, ptr %i, align 4, !dbg !65, !tbaa !20, !DIAssignID !66 |
| 102 | + #dbg_assign(i32 %mul9, !16, !DIExpression(), !66, ptr %i, !DIExpression(), !18) |
| 103 | + br label %if.end |
| 104 | + |
| 105 | +if.end: ; preds = %if.else, %if.then |
| 106 | + %17 = load i32, ptr %i, align 4, !dbg !67, !tbaa !20 |
| 107 | + call void @llvm.lifetime.end.p0(i64 4, ptr %i), !dbg !68 |
| 108 | + ret i32 %17, !dbg !69 |
| 109 | +} |
| 110 | + |
| 111 | +; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) |
| 112 | +declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) |
| 113 | + |
| 114 | +; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) |
| 115 | +declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) |
| 116 | + |
| 117 | +!llvm.dbg.cu = !{!0} |
| 118 | +!llvm.module.flags = !{!2, !3} |
| 119 | +!llvm.ident = !{!8} |
| 120 | + |
| 121 | +!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 21.0.0git", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) |
| 122 | +!1 = !DIFile(filename: "repro.c", directory: "") |
| 123 | +!2 = !{i32 7, !"Dwarf Version", i32 5} |
| 124 | +!3 = !{i32 2, !"Debug Info Version", i32 3} |
| 125 | +!8 = !{!"clang version 21.0.0git"} |
| 126 | +!9 = distinct !DISubprogram(name: "foo", scope: !10, file: !10, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !14) |
| 127 | +!10 = !DIFile(filename: "1.c", directory: "") |
| 128 | +!11 = !DISubroutineType(types: !12) |
| 129 | +!12 = !{!13, !13} |
| 130 | +!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) |
| 131 | +!14 = !{!15, !16} |
| 132 | +!15 = !DILocalVariable(name: "a", arg: 1, scope: !9, file: !10, line: 1, type: !13) |
| 133 | +!16 = !DILocalVariable(name: "i", scope: !9, file: !10, line: 2, type: !13) |
| 134 | +!17 = distinct !DIAssignID() |
| 135 | +!18 = !DILocation(line: 0, scope: !9) |
| 136 | +!19 = distinct !DIAssignID() |
| 137 | +!20 = !{!21, !21, i64 0} |
| 138 | +!21 = !{!"int", !22, i64 0} |
| 139 | +!22 = !{!"omnipotent char", !23, i64 0} |
| 140 | +!23 = !{!"Simple C/C++ TBAA"} |
| 141 | +!24 = distinct !DIAssignID() |
| 142 | +!25 = !DILocation(line: 2, column: 3, scope: !9) |
| 143 | +!26 = !DILocation(line: 2, column: 7, scope: !9) |
| 144 | +!27 = distinct !DIAssignID() |
| 145 | +!28 = !DILocation(line: 3, column: 8, scope: !29) |
| 146 | +!29 = distinct !DILexicalBlock(scope: !9, file: !10, line: 3, column: 7) |
| 147 | +!30 = !DILocation(line: 3, column: 10, scope: !29) |
| 148 | +!31 = !DILocation(line: 3, column: 15, scope: !29) |
| 149 | +!32 = !DILocation(line: 4, column: 7, scope: !33) |
| 150 | +!33 = distinct !DILexicalBlock(scope: !29, file: !10, line: 3, column: 21) |
| 151 | +!34 = distinct !DIAssignID() |
| 152 | +!35 = !DILocation(line: 40, column: 6, scope: !36) |
| 153 | +!36 = !DILexicalBlockFile(scope: !33, file: !37, discriminator: 0) |
| 154 | +!37 = !DIFile(filename: "m.c", directory: "") |
| 155 | +!38 = !DILocation(line: 40, column: 3, scope: !36) |
| 156 | +!39 = distinct !DIAssignID() |
| 157 | +!40 = !DILocation(line: 41, column: 9, scope: !36) |
| 158 | +!41 = !DILocation(line: 41, column: 8, scope: !36) |
| 159 | +!42 = !DILocation(line: 41, column: 3, scope: !36) |
| 160 | +!43 = distinct !DIAssignID() |
| 161 | +!44 = !DILocation(line: 42, column: 6, scope: !36) |
| 162 | +!45 = !DILocation(line: 42, column: 8, scope: !36) |
| 163 | +!46 = !DILocation(line: 42, column: 7, scope: !36) |
| 164 | +!47 = !DILocation(line: 42, column: 3, scope: !36) |
| 165 | +!48 = distinct !DIAssignID() |
| 166 | +!49 = !DILocation(line: 6, column: 2, scope: !50) |
| 167 | +!50 = !DILexicalBlockFile(scope: !33, file: !10, discriminator: 0) |
| 168 | +!51 = !DILocation(line: 7, column: 7, scope: !52) |
| 169 | +!52 = distinct !DILexicalBlock(scope: !29, file: !10, line: 6, column: 9) |
| 170 | +!53 = distinct !DIAssignID() |
| 171 | +!54 = !DILocation(line: 40, column: 6, scope: !55) |
| 172 | +!55 = !DILexicalBlockFile(scope: !52, file: !37, discriminator: 0) |
| 173 | +!56 = !DILocation(line: 40, column: 3, scope: !55) |
| 174 | +!57 = distinct !DIAssignID() |
| 175 | +!58 = !DILocation(line: 41, column: 9, scope: !55) |
| 176 | +!59 = !DILocation(line: 41, column: 8, scope: !55) |
| 177 | +!60 = !DILocation(line: 41, column: 3, scope: !55) |
| 178 | +!61 = distinct !DIAssignID() |
| 179 | +!62 = !DILocation(line: 42, column: 6, scope: !55) |
| 180 | +!63 = !DILocation(line: 42, column: 8, scope: !55) |
| 181 | +!64 = !DILocation(line: 42, column: 7, scope: !55) |
| 182 | +!65 = !DILocation(line: 42, column: 3, scope: !55) |
| 183 | +!66 = distinct !DIAssignID() |
| 184 | +!67 = !DILocation(line: 10, column: 10, scope: !9) |
| 185 | +!68 = !DILocation(line: 11, column: 1, scope: !9) |
| 186 | +!69 = !DILocation(line: 10, column: 3, scope: !9) |
| 187 | + |
| 188 | +; CHECK: [[SP:![0-9]+]] = distinct !DISubprogram(name: "foo", scope: [[FILE1:![0-9]+]], file: [[FILE1]], line: 1 |
| 189 | +; CHECK: [[FILE1]] = !DIFile(filename: "1.c", directory: "") |
| 190 | +; CHECK: [[LB1:![0-9]+]] = distinct !DILexicalBlock(scope: [[SP]], file: [[FILE1]], line: 3, column: 7) |
| 191 | +; CHECK: [[LB2:![0-9]+]] = distinct !DILexicalBlock(scope: [[LB1]], file: [[FILE1]], line: 3, column: 21) |
| 192 | +; CHECK: [[LBF:![0-9]+]] = !DILexicalBlockFile(scope: [[LB2]], file: [[FILE2:![0-9]+]], discriminator: 0) |
| 193 | +; CHECK: [[FILE2]] = !DIFile(filename: "m.c", directory: "") |
| 194 | +; CHECK: [[PHILOC]] = !DILocation(line: 42, column: 3, scope: [[LBF]]) |
0 commit comments