[llvm] [MLIR] Fix triple mismatch warning for embedded libdevice (PR #121447)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 2 19:10:13 PST 2025


https://github.com/arthurqiu updated https://github.com/llvm/llvm-project/pull/121447

>From 51d183e3c9fbc48dee406680b6024291f35a1446 Mon Sep 17 00:00:00 2001
From: Arthurq Qiu <arthurq at nvidia.com>
Date: Wed, 1 Jan 2025 18:23:28 -0800
Subject: [PATCH] Remove libdevice filename check

---
 llvm/lib/Linker/IRMover.cpp                           |  8 ++------
 .../{not-a-libdevice.ll => not-a-libdevice-a.ll}      |  0
 llvm/test/Linker/Inputs/not-a-libdevice-b.ll          |  2 ++
 llvm/test/Linker/cuda-libdevice.ll                    | 11 ++++++-----
 4 files changed, 10 insertions(+), 11 deletions(-)
 rename llvm/test/Linker/Inputs/{not-a-libdevice.ll => not-a-libdevice-a.ll} (100%)
 create mode 100644 llvm/test/Linker/Inputs/not-a-libdevice-b.ll

diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index a0c3f2c5b0baf6..be3535ae94ff4e 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -1562,10 +1562,6 @@ Error IRLinker::run() {
   bool EnableDLWarning = true;
   bool EnableTripleWarning = true;
   if (SrcTriple.isNVPTX() && DstTriple.isNVPTX()) {
-    std::string ModuleId = SrcM->getModuleIdentifier();
-    StringRef FileName = llvm::sys::path::filename(ModuleId);
-    bool SrcIsLibDevice =
-        FileName.starts_with("libdevice") && FileName.ends_with(".10.bc");
     bool SrcHasLibDeviceDL =
         (SrcM->getDataLayoutStr().empty() ||
          SrcM->getDataLayoutStr() == "e-i64:64-v16:16-v32:32-n16:32:64");
@@ -1576,8 +1572,8 @@ Error IRLinker::run() {
                                   SrcTriple.getOSName() == "gpulibs") ||
                                  (SrcTriple.getVendorName() == "unknown" &&
                                   SrcTriple.getOSName() == "unknown");
-    EnableTripleWarning = !(SrcIsLibDevice && SrcHasLibDeviceTriple);
-    EnableDLWarning = !(SrcIsLibDevice && SrcHasLibDeviceDL);
+    EnableTripleWarning = !SrcHasLibDeviceTriple;
+    EnableDLWarning = !(SrcHasLibDeviceTriple && SrcHasLibDeviceDL);
   }
 
   if (EnableDLWarning && (SrcM->getDataLayout() != DstM.getDataLayout())) {
diff --git a/llvm/test/Linker/Inputs/not-a-libdevice.ll b/llvm/test/Linker/Inputs/not-a-libdevice-a.ll
similarity index 100%
rename from llvm/test/Linker/Inputs/not-a-libdevice.ll
rename to llvm/test/Linker/Inputs/not-a-libdevice-a.ll
diff --git a/llvm/test/Linker/Inputs/not-a-libdevice-b.ll b/llvm/test/Linker/Inputs/not-a-libdevice-b.ll
new file mode 100644
index 00000000000000..bb000ef836cd45
--- /dev/null
+++ b/llvm/test/Linker/Inputs/not-a-libdevice-b.ll
@@ -0,0 +1,2 @@
+target triple = "nvptx64-nvidia-gpulibs"
+target datalayout = "e-i64:64-i128:128-v32:32-n16:32:64"
diff --git a/llvm/test/Linker/cuda-libdevice.ll b/llvm/test/Linker/cuda-libdevice.ll
index 484e8339a136e2..5680554fe275b6 100644
--- a/llvm/test/Linker/cuda-libdevice.ll
+++ b/llvm/test/Linker/cuda-libdevice.ll
@@ -5,7 +5,8 @@
 ; RUN: llvm-as %p/Inputs/libdevice-cuda-10.ll -o %t/libdevice.10.bc
 ; RUN: llvm-as %p/Inputs/libdevice-cuda-11.ll -o %t/libdevice.11.10.bc
 ; RUN: llvm-as %p/Inputs/libdevice-cuda-9.ll -o %t/correct-libdevice-wrong-filename.bc
-; RUN: llvm-as %p/Inputs/not-a-libdevice.ll -o %t/libdevice-with-wrong-info.bc
+; RUN: llvm-as %p/Inputs/not-a-libdevice-a.ll -o %t/libdevice-with-wrong-info.bc
+; RUN: llvm-as %p/Inputs/not-a-libdevice-b.ll -o %t/libdevice-with-wrong-dl.bc
 
 ; No warnings expected when we link with libdevice variants
 ; RUN: llvm-link %t/main.bc %t/libdevice.compute_35.10.bc -S 2>&1 \
@@ -15,12 +16,12 @@
 ; RUN: llvm-link %t/main.bc %t/libdevice.11.10.bc -S 2>&1 \
 ; RUN:  | FileCheck --check-prefixes COMMON,NOWARN %s
 
-; But make sure we still issue warnings if we see unexpected filename, or
-; unexpected triple or datalayout within a libdevice filename.
-; RUN: llvm-link %t/main.bc %t/correct-libdevice-wrong-filename.bc -S 2>&1 \
-; RUN:  | FileCheck --check-prefixes COMMON,WARN-TRIPLE %s
+; But make sure we still issue warnings if we see unexpected triple or
+; datalayout within a libdevice filename.
 ; RUN: llvm-link %t/main.bc %t/libdevice-with-wrong-info.bc -S 2>&1 \
 ; RUN:  | FileCheck --check-prefixes COMMON,WARN-TRIPLE,WARN-DL %s
+; RUN: llvm-link %t/main.bc %t/libdevice-with-wrong-dl.bc -S 2>&1 \
+; RUN:  | FileCheck --check-prefixes COMMON,NOWARN,WARN-DL %s
 
 
 target triple = "nvptx64-nvidia-cuda"



More information about the llvm-commits mailing list