-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[DebugInfo][GVNSink] Fix #77415: GVNSink fails to optimize LLVM IR with debug info #77602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
114218d
[GVNSink] Fix #77415: GVNSink fails to optimize LLVM IR with debug info
Apochens 78e8257
[GVNSink] Fix #77415: Remove redundant metadata
Apochens 0ea7153
[GVNSink] Fix #77415: Fix metadata
Apochens 39e5902
refine checks in the test
Apochens 131405f
test nit
Apochens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
llvm/test/Transforms/GVNSink/sink-ignore-dbg-intrinsics.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
; RUN: opt < %s -passes=gvn-sink -S | FileCheck %s | ||
|
||
; Test that GVNSink correctly performs the sink optimization in the presence of debug information | ||
|
||
; Function Attrs: noinline nounwind uwtable | ||
define dso_local i32 @fun(i32 noundef %a, i32 noundef %b) #0 !dbg !10 { | ||
entry: | ||
tail call void @llvm.dbg.value(metadata i32 %a, metadata !15, metadata !DIExpression()), !dbg !16 | ||
tail call void @llvm.dbg.value(metadata i32 %b, metadata !17, metadata !DIExpression()), !dbg !16 | ||
%cmp = icmp sgt i32 %b, 10, !dbg !18 | ||
br i1 %cmp, label %if.then, label %if.else, !dbg !20 | ||
|
||
if.then: ; preds = %entry | ||
%add = add nsw i32 %a, 1, !dbg !21 | ||
tail call void @llvm.dbg.value(metadata i32 %add, metadata !23, metadata !DIExpression()), !dbg !24 | ||
%xor = xor i32 %add, 1, !dbg !25 | ||
tail call void @llvm.dbg.value(metadata i32 %xor, metadata !26, metadata !DIExpression()), !dbg !24 | ||
tail call void @llvm.dbg.value(metadata i32 %xor, metadata !27, metadata !DIExpression()), !dbg !16 | ||
br label %if.end, !dbg !28 | ||
|
||
if.else: ; preds = %entry | ||
%add1 = add nsw i32 %b, 1, !dbg !29 | ||
tail call void @llvm.dbg.value(metadata i32 %add1, metadata !31, metadata !DIExpression()), !dbg !32 | ||
%xor2 = xor i32 %add1, 1, !dbg !33 | ||
tail call void @llvm.dbg.value(metadata i32 %xor2, metadata !34, metadata !DIExpression()), !dbg !32 | ||
tail call void @llvm.dbg.value(metadata i32 %xor2, metadata !27, metadata !DIExpression()), !dbg !16 | ||
br label %if.end | ||
|
||
; CHECK-LABEL: if.end: | ||
; CHECK: [[SINK:%.*sink]] = phi i32 [ {{.*}} ], [ {{.*}} ] | ||
; CHECK: [[ADD:%.*]] = add nsw i32 [[SINK]], 1 | ||
; CHECK: [[XOR:%.*]] = xor i32 [[ADD]], 1 | ||
if.end: ; preds = %if.else, %if.then | ||
%ret.0 = phi i32 [ %xor, %if.then ], [ %xor2, %if.else ], !dbg !35 | ||
tail call void @llvm.dbg.value(metadata i32 %ret.0, metadata !27, metadata !DIExpression()), !dbg !16 | ||
ret i32 %ret.0, !dbg !36 | ||
} | ||
|
||
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) | ||
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 | ||
|
||
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) | ||
declare void @llvm.dbg.value(metadata, metadata, metadata) #1 | ||
|
||
attributes #0 = { noinline nounwind uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } | ||
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } | ||
|
||
!llvm.dbg.cu = !{!0} | ||
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8} | ||
|
||
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 18.0.0git (https://github.com/llvm/llvm-project.git 5dfcb3e5d1d16bb4f8fce52b3c089119ed977e7f)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) | ||
!1 = !DIFile(filename: "main.c", directory: "/") | ||
!2 = !{i32 7, !"Dwarf Version", i32 5} | ||
!3 = !{i32 2, !"Debug Info Version", i32 3} | ||
!4 = !{i32 1, !"wchar_size", i32 4} | ||
!5 = !{i32 8, !"PIC Level", i32 2} | ||
!6 = !{i32 7, !"PIE Level", i32 2} | ||
!7 = !{i32 7, !"uwtable", i32 2} | ||
!8 = !{i32 7, !"frame-pointer", i32 2} | ||
!10 = distinct !DISubprogram(name: "fun", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !14) | ||
!11 = !DISubroutineType(types: !12) | ||
!12 = !{!13, !13, !13} | ||
!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) | ||
!14 = !{} | ||
!15 = !DILocalVariable(name: "a", arg: 1, scope: !10, file: !1, line: 1, type: !13) | ||
!16 = !DILocation(line: 0, scope: !10) | ||
!17 = !DILocalVariable(name: "b", arg: 2, scope: !10, file: !1, line: 1, type: !13) | ||
!18 = !DILocation(line: 3, column: 11, scope: !19) | ||
!19 = distinct !DILexicalBlock(scope: !10, file: !1, line: 3, column: 9) | ||
!20 = !DILocation(line: 3, column: 9, scope: !10) | ||
!21 = !DILocation(line: 4, column: 20, scope: !22) | ||
!22 = distinct !DILexicalBlock(scope: !19, file: !1, line: 3, column: 17) | ||
!23 = !DILocalVariable(name: "a1", scope: !22, file: !1, line: 4, type: !13) | ||
!24 = !DILocation(line: 0, scope: !22) | ||
!25 = !DILocation(line: 5, column: 21, scope: !22) | ||
!26 = !DILocalVariable(name: "a2", scope: !22, file: !1, line: 5, type: !13) | ||
!27 = !DILocalVariable(name: "ret", scope: !10, file: !1, line: 2, type: !13) | ||
!28 = !DILocation(line: 7, column: 5, scope: !22) | ||
!29 = !DILocation(line: 8, column: 20, scope: !30) | ||
!30 = distinct !DILexicalBlock(scope: !19, file: !1, line: 7, column: 12) | ||
!31 = !DILocalVariable(name: "b1", scope: !30, file: !1, line: 8, type: !13) | ||
!32 = !DILocation(line: 0, scope: !30) | ||
!33 = !DILocation(line: 9, column: 21, scope: !30) | ||
!34 = !DILocalVariable(name: "b2", scope: !30, file: !1, line: 9, type: !13) | ||
!35 = !DILocation(line: 0, scope: !19) | ||
!36 = !DILocation(line: 12, column: 5, scope: !10) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we should have a fixed order here.
maybe swap the PHI operands and see if that passed the check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or better use the
llvm-project/llvm/utils/update_test_checks.py
to update the testThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Now the incoming blocks has a fixed order.