[llvm] [llc] set canonical triple in module (PR #203725)
Alex MacLean via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 14 13:39:32 PDT 2026
https://github.com/AlexMaclean updated https://github.com/llvm/llvm-project/pull/203725
>From 45e58af1d93b49198ac52688f6ddaaf4f5b17764 Mon Sep 17 00:00:00 2001
From: Alex Maclean <amaclean at nvidia.com>
Date: Sat, 13 Jun 2026 13:00:36 -0700
Subject: [PATCH 1/2] [llc] set canonical triple in module
---
llvm/test/CodeGen/Generic/intrinsics.ll | 3 ---
llvm/tools/llc/llc.cpp | 4 ++--
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/llvm/test/CodeGen/Generic/intrinsics.ll b/llvm/test/CodeGen/Generic/intrinsics.ll
index 82e2b3ec7dee5..e5161c44a1df4 100644
--- a/llvm/test/CodeGen/Generic/intrinsics.ll
+++ b/llvm/test/CodeGen/Generic/intrinsics.ll
@@ -1,9 +1,6 @@
; RUN: llc < %s
; RUN: llc -O0 < %s
-; NVPTX can't select sinf(float)/sin(double)
-; XFAIL: target=nvptx{{.*}}
-
;; SQRT
declare float @llvm.sqrt.f32(float)
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index dcd54c18401d0..ad291c3e6a3ea 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -675,8 +675,8 @@ static int compileModule(char **argv, SmallVectorImpl<PassPlugin> &PluginList,
Err.print(argv[0], WithColor::error(errs(), argv[0]));
return 1;
}
- if (!TargetTriple.empty())
- M->setTargetTriple(Triple(Triple::normalize(TargetTriple)));
+
+ M->setTargetTriple(TheTriple);
std::optional<CodeModel::Model> CM_IR = M->getCodeModel();
if (!CM && CM_IR)
>From 516cf0ba90547107eafc05f61d04a938deb90ffd Mon Sep 17 00:00:00 2001
From: Alex Maclean <amaclean at nvidia.com>
Date: Sun, 14 Jun 2026 13:39:16 -0700
Subject: [PATCH 2/2] add tests
---
llvm/test/tools/llc/module-triple-default.ll | 14 ++++++++++++++
llvm/test/tools/llc/module-triple.ll | 16 ++++++++++++++++
2 files changed, 30 insertions(+)
create mode 100644 llvm/test/tools/llc/module-triple-default.ll
create mode 100644 llvm/test/tools/llc/module-triple.ll
diff --git a/llvm/test/tools/llc/module-triple-default.ll b/llvm/test/tools/llc/module-triple-default.ll
new file mode 100644
index 0000000000000..138e62097b9c8
--- /dev/null
+++ b/llvm/test/tools/llc/module-triple-default.ll
@@ -0,0 +1,14 @@
+;; Verify that llc correctly sets the module triple when one is not present.
+
+; RUN: llc -march=aarch64 -stop-after=finalize-isel -o - %s | FileCheck %s --check-prefix=MARCH
+; RUN: llc -mtriple=aarch64-unknown-linux-gnu -stop-after=finalize-isel -o - %s | FileCheck %s --check-prefix=MTRIPLE
+; RUN: llc -stop-after=finalize-isel -o - %s | FileCheck %s --check-prefix=DEFAULT
+
+; REQUIRES: aarch64-registered-target
+; REQUIRES: default_triple
+
+; MARCH: target triple = "aarch64-{{.*}}-{{.*}}"
+; MTRIPLE: target triple = "aarch64-unknown-linux-gnu"
+; DEFAULT: target triple = "{{.*}}-{{.*}}-{{.*}}"
+
+define void @f() { ret void }
diff --git a/llvm/test/tools/llc/module-triple.ll b/llvm/test/tools/llc/module-triple.ll
new file mode 100644
index 0000000000000..c9b4c3016bace
--- /dev/null
+++ b/llvm/test/tools/llc/module-triple.ll
@@ -0,0 +1,16 @@
+;; Verify that llc correctly sets the module triple when one is present.
+
+; RUN: llc -march=aarch64 -stop-after=finalize-isel -o - %s | FileCheck %s --check-prefix=MARCH
+; RUN: llc -mtriple=aarch64-unknown-unknown -stop-after=finalize-isel -o - %s | FileCheck %s --check-prefix=MTRIPLE
+; RUN: llc -stop-after=finalize-isel -o - %s | FileCheck %s --check-prefix=MODULE
+
+; REQUIRES: aarch64-registered-target
+; REQUIRES: x86-registered-target
+
+; MARCH: target triple = "aarch64-unknown-linux-gnu"
+; MTRIPLE: target triple = "aarch64-unknown-unknown"
+; MODULE: target triple = "x86_64-unknown-linux-gnu"
+
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @f() { ret void }
More information about the llvm-commits
mailing list