[llvm] [llc] set canonical triple in module (PR #203725)
Alex MacLean via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 15 08:20:41 PDT 2026
================
@@ -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"
----------------
AlexMaclean wrote:
The `-mtriple` command line flag has long overridden the triple set in the file in both `opt` and `llc`. I don't want to open the can of worms that changing that would be nor do I think it is directly related to this PR.
This change is just about making sure that irrespective of what precedence rules we use to choose the canonical triple, that triple is consistent across both the module and the TM. This is important to prevent crashes and mis-compilations. I'm specifically trying to fix the case where `LLVM_DEFAULT_TARGET_TRIPLE` is set to `nvptx` and a module doesn't have a triple. Currently we have lots of issues on this path because passes like `ExpandVariadics` and `TargetLibraryInfo` consult the (previously unset) module triple to decide what to do.
https://github.com/llvm/llvm-project/pull/203725
More information about the llvm-commits
mailing list