[llvm] 4277c1b - [Attributor][FIX] Avoid metadata and duplicate replication assertion

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 9 03:03:42 PDT 2022


Author: Johannes Doerfert
Date: 2022-06-09T12:00:26+02:00
New Revision: 4277c1be881b82ed98eb4c873c3a8154ad726986

URL: https://github.com/llvm/llvm-project/commit/4277c1be881b82ed98eb4c873c3a8154ad726986
DIFF: https://github.com/llvm/llvm-project/commit/4277c1be881b82ed98eb4c873c3a8154ad726986.diff

LOG: [Attributor][FIX] Avoid metadata and duplicate replication assertion

When we recreate instructions as part of simplification we need to take
care of debug metadata and replacing the value multiple times. For now,
we handle both conservatively.

Added: 
    llvm/test/Transforms/Attributor/value-simplify-dbg.ll

Modified: 
    llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 8d21f2ae77c77..f544616f30a16 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -5452,6 +5452,8 @@ struct AAValueSimplifyImpl : AAValueSimplify {
       return &I;
 
     Instruction *CloneI = I.clone();
+    // TODO: Try to salvage debug information here.
+    CloneI->setDebugLoc(DebugLoc());
     VMap[&I] = CloneI;
     CloneI->insertBefore(CtxI);
     RemapInstruction(CloneI, VMap);
@@ -6018,6 +6020,11 @@ struct AAValueSimplifyCallSiteArgument : AAValueSimplifyFloating {
   /// See AbstractAttribute::manifest(...).
   ChangeStatus manifest(Attributor &A) override {
     ChangeStatus Changed = ChangeStatus::UNCHANGED;
+    // TODO: We should avoid simplification duplication to begin with.
+    auto *FloatAA = A.lookupAAFor<AAValueSimplify>(
+        IRPosition::value(getAssociatedValue()), this, DepClassTy::NONE);
+    if (FloatAA && FloatAA->getState().isValidState())
+      return Changed;
 
     if (auto *NewV = manifestReplacementValue(A, getCtxI())) {
       Use &U = cast<CallBase>(&getAnchorValue())

diff  --git a/llvm/test/Transforms/Attributor/value-simplify-dbg.ll b/llvm/test/Transforms/Attributor/value-simplify-dbg.ll
new file mode 100644
index 0000000000000..3be91222f0ff8
--- /dev/null
+++ b/llvm/test/Transforms/Attributor/value-simplify-dbg.ll
@@ -0,0 +1,150 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals
+; RUN: opt -attributor -enable-new-pm=0 -attributor-manifest-internal  -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=2 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_NPM,NOT_CGSCC_OPM,NOT_TUNIT_NPM,IS__TUNIT____,IS________OPM,IS__TUNIT_OPM
+; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal  -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=2 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_OPM,NOT_CGSCC_NPM,NOT_TUNIT_OPM,IS__TUNIT____,IS________NPM,IS__TUNIT_NPM
+; RUN: opt -attributor-cgscc -enable-new-pm=0 -attributor-manifest-internal  -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_NPM,IS__CGSCC____,IS________OPM,IS__CGSCC_OPM
+; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal  -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_OPM,IS__CGSCC____,IS________NPM,IS__CGSCC_NPM
+
+ at G = internal global i32 undef, align 4, !dbg !0
+
+;.
+; CHECK: @[[G:[a-zA-Z0-9_$"\\.-]+]] = internal global i32 undef, align 4, !dbg [[DBG0:![0-9]+]]
+;.
+define void @dest() !dbg !15 {
+; IS__TUNIT____-LABEL: define {{[^@]+}}@dest
+; IS__TUNIT____-SAME: () !dbg [[DBG15:![0-9]+]] {
+; IS__TUNIT____-NEXT:  entry:
+; IS__TUNIT____-NEXT:    [[TMP0:%.*]] = call i32 @speculatable()
+; IS__TUNIT____-NEXT:    [[TMP1:%.*]] = add i32 [[TMP0]], 1
+; IS__TUNIT____-NEXT:    call void @use(i32 noundef [[TMP1]]), !dbg [[DBG19:![0-9]+]]
+; IS__TUNIT____-NEXT:    ret void, !dbg [[DBG20:![0-9]+]]
+;
+; IS__CGSCC____-LABEL: define {{[^@]+}}@dest
+; IS__CGSCC____-SAME: () !dbg [[DBG15:![0-9]+]] {
+; IS__CGSCC____-NEXT:  entry:
+; IS__CGSCC____-NEXT:    [[TMP0:%.*]] = load i32, ptr @G, align 4, !dbg [[DBG19:![0-9]+]]
+; IS__CGSCC____-NEXT:    call void @use(i32 noundef [[TMP0]]), !dbg [[DBG20:![0-9]+]]
+; IS__CGSCC____-NEXT:    ret void, !dbg [[DBG21:![0-9]+]]
+;
+entry:
+  %0 = load i32, ptr @G, align 4, !dbg !19
+  call void @use(i32 noundef %0), !dbg !20
+  ret void, !dbg !21
+}
+
+declare void @use(i32 noundef)
+
+define void @src() norecurse !dbg !22 {
+; IS__TUNIT____: Function Attrs: norecurse nosync writeonly
+; IS__TUNIT____-LABEL: define {{[^@]+}}@src
+; IS__TUNIT____-SAME: () #[[ATTR0:[0-9]+]] !dbg [[DBG21:![0-9]+]] {
+; IS__TUNIT____-NEXT:  entry:
+; IS__TUNIT____-NEXT:    [[CALL:%.*]] = call i32 @speculatable(), !dbg [[DBG22:![0-9]+]]
+; IS__TUNIT____-NEXT:    [[PLUS1:%.*]] = add i32 [[CALL]], 1
+; IS__TUNIT____-NEXT:    store i32 [[PLUS1]], ptr @G, align 4, !dbg [[DBG23:![0-9]+]]
+; IS__TUNIT____-NEXT:    ret void, !dbg [[DBG24:![0-9]+]]
+;
+; IS__CGSCC____: Function Attrs: norecurse nosync writeonly
+; IS__CGSCC____-LABEL: define {{[^@]+}}@src
+; IS__CGSCC____-SAME: () #[[ATTR0:[0-9]+]] !dbg [[DBG22:![0-9]+]] {
+; IS__CGSCC____-NEXT:  entry:
+; IS__CGSCC____-NEXT:    [[CALL:%.*]] = call i32 @speculatable(), !dbg [[DBG23:![0-9]+]]
+; IS__CGSCC____-NEXT:    [[PLUS1:%.*]] = add i32 [[CALL]], 1
+; IS__CGSCC____-NEXT:    store i32 [[PLUS1]], ptr @G, align 4, !dbg [[DBG24:![0-9]+]]
+; IS__CGSCC____-NEXT:    ret void, !dbg [[DBG25:![0-9]+]]
+;
+entry:
+  %call = call i32 @speculatable(), !dbg !23
+  %plus1 = add i32 %call, 1
+  store i32 %plus1, ptr @G, align 4, !dbg !24
+  ret void, !dbg !25
+}
+
+declare i32 @speculatable() speculatable readnone
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!7, !8, !9, !10, !11, !12, !13}
+!llvm.ident = !{!14}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "G", scope: !2, file: !5, line: 1, type: !6, isLocal: true, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 15.0.0 (https://github.com/llvm/llvm-project.git ef94609d6ebe981767788e6877b0b3b731d425af)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "/app/example.c", directory: "/app", checksumkind: CSK_MD5, checksum: "b456b90cec5c3705a028b274d88ee970")
+!4 = !{!0}
+!5 = !DIFile(filename: "example.c", directory: "/app", checksumkind: CSK_MD5, checksum: "b456b90cec5c3705a028b274d88ee970")
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!7 = !{i32 7, !"Dwarf Version", i32 5}
+!8 = !{i32 2, !"Debug Info Version", i32 3}
+!9 = !{i32 1, !"wchar_size", i32 4}
+!10 = !{i32 7, !"PIC Level", i32 2}
+!11 = !{i32 7, !"PIE Level", i32 2}
+!12 = !{i32 7, !"uwtable", i32 2}
+!13 = !{i32 7, !"frame-pointer", i32 2}
+!14 = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project.git ef94609d6ebe981767788e6877b0b3b731d425af)"}
+!15 = distinct !DISubprogram(name: "dest", scope: !5, file: !5, line: 4, type: !16, scopeLine: 4, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !18)
+!16 = !DISubroutineType(types: !17)
+!17 = !{null}
+!18 = !{}
+!19 = !DILocation(line: 5, column: 9, scope: !15)
+!20 = !DILocation(line: 5, column: 5, scope: !15)
+!21 = !DILocation(line: 6, column: 1, scope: !15)
+!22 = distinct !DISubprogram(name: "src", scope: !5, file: !5, line: 9, type: !16, scopeLine: 9, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !18)
+!23 = !DILocation(line: 10, column: 9, scope: !22)
+!24 = !DILocation(line: 10, column: 7, scope: !22)
+!25 = !DILocation(line: 11, column: 1, scope: !22)
+;.
+; CHECK: attributes #[[ATTR0:[0-9]+]] = { norecurse nosync writeonly }
+; CHECK: attributes #[[ATTR1:[0-9]+]] = { readnone speculatable }
+;.
+; IS__TUNIT____: [[DBG0]] = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+; IS__TUNIT____: [[META1:![0-9]+]] = distinct !DIGlobalVariable(name: "G", scope: !2, file: !5, line: 1, type: !6, isLocal: true, isDefinition: true)
+; IS__TUNIT____: [[META2:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 15.0.0 (https://github.com/llvm/llvm-project.git ef94609d6ebe981767788e6877b0b3b731d425af)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+; IS__TUNIT____: [[META3:![0-9]+]] = !DIFile(filename: "/app/example.c", directory: "/app", checksumkind: CSK_MD5, checksum: "b456b90cec5c3705a028b274d88ee970")
+; IS__TUNIT____: [[META4:![0-9]+]] = !{!0}
+; IS__TUNIT____: [[META5:![0-9]+]] = !DIFile(filename: "example.c", directory: "/app", checksumkind: CSK_MD5, checksum: "b456b90cec5c3705a028b274d88ee970")
+; IS__TUNIT____: [[META6:![0-9]+]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+; IS__TUNIT____: [[META7:![0-9]+]] = !{i32 7, !"Dwarf Version", i32 5}
+; IS__TUNIT____: [[META8:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3}
+; IS__TUNIT____: [[META9:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
+; IS__TUNIT____: [[META10:![0-9]+]] = !{i32 7, !"PIC Level", i32 2}
+; IS__TUNIT____: [[META11:![0-9]+]] = !{i32 7, !"PIE Level", i32 2}
+; IS__TUNIT____: [[META12:![0-9]+]] = !{i32 7, !"uwtable", i32 2}
+; IS__TUNIT____: [[META13:![0-9]+]] = !{i32 7, !"frame-pointer", i32 2}
+; IS__TUNIT____: [[META14:![0-9]+]] = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project.git ef94609d6ebe981767788e6877b0b3b731d425af)"}
+; IS__TUNIT____: [[DBG15]] = distinct !DISubprogram(name: "dest", scope: !5, file: !5, line: 4, type: !16, scopeLine: 4, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !18)
+; IS__TUNIT____: [[META16:![0-9]+]] = !DISubroutineType(types: !17)
+; IS__TUNIT____: [[META17:![0-9]+]] = !{null}
+; IS__TUNIT____: [[META18:![0-9]+]] = !{}
+; IS__TUNIT____: [[DBG19]] = !DILocation(line: 5, column: 5, scope: !15)
+; IS__TUNIT____: [[DBG20]] = !DILocation(line: 6, column: 1, scope: !15)
+; IS__TUNIT____: [[DBG21]] = distinct !DISubprogram(name: "src", scope: !5, file: !5, line: 9, type: !16, scopeLine: 9, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !18)
+; IS__TUNIT____: [[DBG22]] = !DILocation(line: 10, column: 9, scope: !21)
+; IS__TUNIT____: [[DBG23]] = !DILocation(line: 10, column: 7, scope: !21)
+; IS__TUNIT____: [[DBG24]] = !DILocation(line: 11, column: 1, scope: !21)
+;.
+; IS__CGSCC____: [[DBG0]] = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+; IS__CGSCC____: [[META1:![0-9]+]] = distinct !DIGlobalVariable(name: "G", scope: !2, file: !5, line: 1, type: !6, isLocal: true, isDefinition: true)
+; IS__CGSCC____: [[META2:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 15.0.0 (https://github.com/llvm/llvm-project.git ef94609d6ebe981767788e6877b0b3b731d425af)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+; IS__CGSCC____: [[META3:![0-9]+]] = !DIFile(filename: "/app/example.c", directory: "/app", checksumkind: CSK_MD5, checksum: "b456b90cec5c3705a028b274d88ee970")
+; IS__CGSCC____: [[META4:![0-9]+]] = !{!0}
+; IS__CGSCC____: [[META5:![0-9]+]] = !DIFile(filename: "example.c", directory: "/app", checksumkind: CSK_MD5, checksum: "b456b90cec5c3705a028b274d88ee970")
+; IS__CGSCC____: [[META6:![0-9]+]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+; IS__CGSCC____: [[META7:![0-9]+]] = !{i32 7, !"Dwarf Version", i32 5}
+; IS__CGSCC____: [[META8:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3}
+; IS__CGSCC____: [[META9:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
+; IS__CGSCC____: [[META10:![0-9]+]] = !{i32 7, !"PIC Level", i32 2}
+; IS__CGSCC____: [[META11:![0-9]+]] = !{i32 7, !"PIE Level", i32 2}
+; IS__CGSCC____: [[META12:![0-9]+]] = !{i32 7, !"uwtable", i32 2}
+; IS__CGSCC____: [[META13:![0-9]+]] = !{i32 7, !"frame-pointer", i32 2}
+; IS__CGSCC____: [[META14:![0-9]+]] = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project.git ef94609d6ebe981767788e6877b0b3b731d425af)"}
+; IS__CGSCC____: [[DBG15]] = distinct !DISubprogram(name: "dest", scope: !5, file: !5, line: 4, type: !16, scopeLine: 4, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !18)
+; IS__CGSCC____: [[META16:![0-9]+]] = !DISubroutineType(types: !17)
+; IS__CGSCC____: [[META17:![0-9]+]] = !{null}
+; IS__CGSCC____: [[META18:![0-9]+]] = !{}
+; IS__CGSCC____: [[DBG19]] = !DILocation(line: 5, column: 9, scope: !15)
+; IS__CGSCC____: [[DBG20]] = !DILocation(line: 5, column: 5, scope: !15)
+; IS__CGSCC____: [[DBG21]] = !DILocation(line: 6, column: 1, scope: !15)
+; IS__CGSCC____: [[DBG22]] = distinct !DISubprogram(name: "src", scope: !5, file: !5, line: 9, type: !16, scopeLine: 9, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !18)
+; IS__CGSCC____: [[DBG23]] = !DILocation(line: 10, column: 9, scope: !22)
+; IS__CGSCC____: [[DBG24]] = !DILocation(line: 10, column: 7, scope: !22)
+; IS__CGSCC____: [[DBG25]] = !DILocation(line: 11, column: 1, scope: !22)
+;.


        


More information about the llvm-commits mailing list