Skip to content

Commit 1510473

Browse files
authored
[RemoveDIs] Insert PHIs before debug records in hardware loops (#85288)
Fixes: #85254 Hardware loops inserts PHIs at the position `getFirstNonPhi()`, which is incorrect - instead, `getFirstNonPhiIt()` is required to not insert the PHI after any debug records that immediately follow the last existing PHI.
1 parent dc55c44 commit 1510473

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

llvm/lib/CodeGen/HardwareLoops.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ PHINode* HardwareLoop::InsertPHICounter(Value *NumElts, Value *EltsRem) {
580580
BasicBlock *Preheader = L->getLoopPreheader();
581581
BasicBlock *Header = L->getHeader();
582582
BasicBlock *Latch = ExitBranch->getParent();
583-
IRBuilder<> Builder(Header->getFirstNonPHI());
583+
IRBuilder<> Builder(Header, Header->getFirstNonPHIIt());
584584
PHINode *Index = Builder.CreatePHI(NumElts->getType(), 2);
585585
Index->addIncoming(NumElts, Preheader);
586586
Index->addIncoming(EltsRem, Latch);
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
; RUN: llc --stop-after=hardware-loops < %s | FileCheck %s
2+
3+
;; Tests that Hardware Loop Insertion does not insert new phi nodes after debug
4+
;; records when they appear immediately after the last existing phi node.
5+
6+
; CHECK-LABEL: for.body:
7+
; CHECK-NEXT: = phi i32
8+
; CHECK-NEXT: = phi i32
9+
; CHECK-NEXT: call void @llvm.dbg.value
10+
11+
source_filename = "repro.c"
12+
target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
13+
target triple = "thumbv8.1m.main-arm-none-eabi"
14+
15+
@z = dso_local local_unnamed_addr global i32 42, align 4, !dbg !0
16+
@arr = dso_local local_unnamed_addr global [10 x i32] zeroinitializer, align 4, !dbg !5
17+
18+
define dso_local void @func1() local_unnamed_addr #0 !dbg !18 {
19+
entry:
20+
%0 = load i32, ptr @z, align 4, !tbaa !26
21+
br label %for.body, !dbg !30
22+
23+
for.body: ; preds = %entry, %for.body
24+
%p1.04 = phi ptr [ @arr, %entry ], [ %incdec.ptr, %for.body ]
25+
%i.03 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
26+
tail call void @llvm.dbg.value(metadata ptr %p1.04, metadata !23, metadata !DIExpression()), !dbg !25
27+
store i32 %0, ptr %p1.04, align 4, !dbg !32, !tbaa !26
28+
%inc = add nuw nsw i32 %i.03, 1, !dbg !34
29+
%incdec.ptr = getelementptr inbounds i8, ptr %p1.04, i32 4, !dbg !35
30+
%exitcond.not = icmp eq i32 %inc, 10, !dbg !36
31+
br i1 %exitcond.not, label %for.end, label %for.body, !dbg !30, !llvm.loop !37
32+
33+
for.end: ; preds = %for.body
34+
ret void, !dbg !41
35+
}
36+
37+
declare void @llvm.dbg.value(metadata, metadata, metadata)
38+
39+
!llvm.dbg.cu = !{!2}
40+
!llvm.module.flags = !{!11, !12, !13, !14, !15, !16}
41+
!llvm.ident = !{!17}
42+
43+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
44+
!1 = distinct !DIGlobalVariable(name: "z", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true)
45+
!2 = distinct !DICompileUnit(language: DW_LANG_C11, file: !3, producer: "clang version 19.0.0git", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
46+
!3 = !DIFile(filename: "repro.c", directory: "/home/gbtozers/dev/upstream-llvm")
47+
!4 = !{!0, !5}
48+
!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression())
49+
!6 = distinct !DIGlobalVariable(name: "arr", scope: !2, file: !3, line: 1, type: !7, isLocal: false, isDefinition: true)
50+
!7 = !DICompositeType(tag: DW_TAG_array_type, baseType: !8, size: 320, elements: !9)
51+
!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
52+
!9 = !{!10}
53+
!10 = !DISubrange(count: 10)
54+
!11 = !{i32 7, !"Dwarf Version", i32 5}
55+
!12 = !{i32 2, !"Debug Info Version", i32 3}
56+
!13 = !{i32 1, !"wchar_size", i32 4}
57+
!14 = !{i32 1, !"min_enum_size", i32 4}
58+
!15 = !{i32 7, !"frame-pointer", i32 2}
59+
!16 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
60+
!17 = !{!"clang version 19.0.0git"}
61+
!18 = distinct !DISubprogram(name: "func1", scope: !3, file: !3, line: 4, type: !19, scopeLine: 5, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !21)
62+
!19 = !DISubroutineType(types: !20)
63+
!20 = !{null}
64+
!21 = !{!23}
65+
!22 = !DILocalVariable(name: "i", scope: !18, file: !3, line: 6, type: !8)
66+
!23 = !DILocalVariable(name: "p1", scope: !18, file: !3, line: 7, type: !24)
67+
!24 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 32)
68+
!25 = !DILocation(line: 0, scope: !18)
69+
!26 = !{!27, !27, i64 0}
70+
!27 = !{!"int", !28, i64 0}
71+
!28 = !{!"omnipotent char", !29, i64 0}
72+
!29 = !{!"Simple C/C++ TBAA"}
73+
!30 = !DILocation(line: 8, column: 3, scope: !31)
74+
!31 = distinct !DILexicalBlock(scope: !18, file: !3, line: 8, column: 3)
75+
!32 = !DILocation(line: 9, column: 10, scope: !33)
76+
!33 = distinct !DILexicalBlock(scope: !31, file: !3, line: 8, column: 3)
77+
!34 = !DILocation(line: 8, column: 27, scope: !33)
78+
!35 = !DILocation(line: 8, column: 32, scope: !33)
79+
!36 = !DILocation(line: 8, column: 21, scope: !33)
80+
!37 = distinct !{!37, !30, !38, !39, !40}
81+
!38 = !DILocation(line: 9, column: 12, scope: !31)
82+
!39 = !{!"llvm.loop.mustprogress"}
83+
!40 = !{!"llvm.loop.unroll.disable"}
84+
!41 = !DILocation(line: 10, column: 1, scope: !18)

0 commit comments

Comments
 (0)