[llvm] [LTO] Reset DiscardValueNames in optimize(). (PR #78705)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 20 06:07:45 PST 2024


https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/78705

>From bcbc97d0cd9b258d8ab246016484fb93cec32ed4 Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Fri, 5 Jan 2024 22:01:21 +0000
Subject: [PATCH] [LTO] Reset DiscardValueNames in optimize().

libLTO parses options late, so re-set them in optimize(). When
LTOCodeGenerator's constructor executes, the options haven't been passed
by the linker to libLTO yet.

Note that we keep the value name of `%add = add..` because when the
module is imported, DiscardValueNames is still set to false (the default
when building wiht assertions).

I tried to improve this in libLTO, but I am not sure if there's a
suitable callback when all options have been set.
---
 llvm/lib/LTO/LTOCodeGenerator.cpp          | 3 +++
 llvm/test/tools/lto/discard-value-names.ll | 3 +--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index 52d8fff14be9ce..727ab7b0db41a6 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -582,6 +582,9 @@ bool LTOCodeGenerator::optimize() {
   if (!this->determineTarget())
     return false;
 
+  // libLTO parses options late, so re-set them here.
+  Context.setDiscardValueNames(LTODiscardValueNames);
+
   auto DiagFileOrErr = lto::setupLLVMOptimizationRemarks(
       Context, RemarksFilename, RemarksPasses, RemarksFormat,
       RemarksWithHotness, RemarksHotnessThreshold);
diff --git a/llvm/test/tools/lto/discard-value-names.ll b/llvm/test/tools/lto/discard-value-names.ll
index 723b0701ae22ce..04d25eaf6067c5 100644
--- a/llvm/test/tools/lto/discard-value-names.ll
+++ b/llvm/test/tools/lto/discard-value-names.ll
@@ -7,11 +7,10 @@
 
 ; The test requires asserts, as it depends on the default value for
 ; -lto-discard-value-names at the moment.
-; FIXME: -lto-discard-value-names is ignored at the moment.
 
 ; REQUIRES: asserts
 
-; DISCARD: %cmp.i = icmp
+; DISCARD: %{{[0-9]+}} = icmp
 ; DISCARD: %add = add i32
 
 ; KEEP: %cmp.i = icmp



More information about the llvm-commits mailing list