diff --git a/llvm/lib/CodeGen/MIRFSDiscriminator.cpp b/llvm/lib/CodeGen/MIRFSDiscriminator.cpp --- a/llvm/lib/CodeGen/MIRFSDiscriminator.cpp +++ b/llvm/lib/CodeGen/MIRFSDiscriminator.cpp @@ -68,6 +68,8 @@ bool MIRAddFSDiscriminators::runOnMachineFunction(MachineFunction &MF) { if (!EnableFSDiscriminator) return false; + if (!MF.getFunction().isDebugInfoForProfiling()) + return false; bool Changed = false; using LocationDiscriminator = std::tuple; diff --git a/llvm/test/CodeGen/X86/fsafdo_test1.ll b/llvm/test/CodeGen/X86/fsafdo_test1.ll --- a/llvm/test/CodeGen/X86/fsafdo_test1.ll +++ b/llvm/test/CodeGen/X86/fsafdo_test1.ll @@ -2,7 +2,7 @@ ; ; Check that fs-afdo discriminators are generated. ; CHECK: .loc 1 7 3 is_stmt 0 discriminator 2 # foo.c:7:3 -; Check: .loc 1 9 5 is_stmt 1 discriminator 2 # foo.c:9:5 +; ChECK: .loc 1 9 5 is_stmt 1 discriminator 2 # foo.c:9:5 ; CHECK: .loc 1 9 5 is_stmt 0 discriminator 11266 # foo.c:9:5 ; CHECK: .loc 1 7 3 is_stmt 1 discriminator 11266 # foo.c:7:3 ; Check that variable __llvm_fs_discriminator__ is generated. @@ -45,7 +45,7 @@ !llvm.dbg.cu = !{!0} !llvm.module.flags = !{!3, !4} -!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, emissionKind: LineTablesOnly) +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, debugInfoForProfiling: true, emissionKind: LineTablesOnly) !1 = !DIFile(filename: "foo.c", directory: "b/") !2 = !{} !3 = !{i32 2, !"Dwarf Version", i32 4} diff --git a/llvm/test/CodeGen/X86/fsafdo_test1.ll b/llvm/test/CodeGen/X86/fsafdo_test4.ll copy from llvm/test/CodeGen/X86/fsafdo_test1.ll copy to llvm/test/CodeGen/X86/fsafdo_test4.ll --- a/llvm/test/CodeGen/X86/fsafdo_test1.ll +++ b/llvm/test/CodeGen/X86/fsafdo_test4.ll @@ -1,17 +1,12 @@ ; RUN: llc -enable-fs-discriminator < %s | FileCheck %s ; -; Check that fs-afdo discriminators are generated. +; Check that fs-afdo discriminators are NOT generated, as debugInfoForProfiling is false (not set). ; CHECK: .loc 1 7 3 is_stmt 0 discriminator 2 # foo.c:7:3 -; Check: .loc 1 9 5 is_stmt 1 discriminator 2 # foo.c:9:5 -; CHECK: .loc 1 9 5 is_stmt 0 discriminator 11266 # foo.c:9:5 -; CHECK: .loc 1 7 3 is_stmt 1 discriminator 11266 # foo.c:7:3 -; Check that variable __llvm_fs_discriminator__ is generated. -; CHECK: .type __llvm_fs_discriminator__,@object # @__llvm_fs_discriminator__ -; CHECK: .section .rodata,"a",@progbits -; CHECK: .weak __llvm_fs_discriminator__ -; CHECK: __llvm_fs_discriminator__: -; CHECK: .byte 1 -; CHECK: .size __llvm_fs_discriminator__, 1 +; CHECK: .loc 1 9 5 is_stmt 1 discriminator 2 # foo.c:9:5 +; CHECK-NOT: .loc 1 9 5 is_stmt 0 discriminator 11266 # foo.c:9:5 +; CHECK-NOT: .loc 1 7 3 is_stmt 1 discriminator 11266 # foo.c:7:3 +; Check that variable __llvm_fs_discriminator__ is NOT generated. +; CHECK-NOT: __llvm_fs_discriminator__: target triple = "x86_64-unknown-linux-gnu"