[Mlir-commits] [mlir] 391d298 - [mlir][Target] Make nvptxcompiler passed options high priority to keep consistent with ptxas behavior (#121036)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Jul 28 04:52:39 PDT 2026


Author: Zichen Lu
Date: 2026-07-28T13:52:33+02:00
New Revision: 391d298c2ae471c28e7db8538d867a017f9d08df

URL: https://github.com/llvm/llvm-project/commit/391d298c2ae471c28e7db8538d867a017f9d08df
DIFF: https://github.com/llvm/llvm-project/commit/391d298c2ae471c28e7db8538d867a017f9d08df.diff

LOG: [mlir][Target] Make nvptxcompiler passed options high priority to keep consistent with ptxas behavior (#121036)

When using `ptxas` to do ptx->cubin, the options passed (via `cmd`) have
higher priority than the gpuModule target (such as `opt-level`). When
using `nvptxcompiler`, it is the opposite and we need to be consistent.

Added: 
    

Modified: 
    mlir/lib/Target/LLVM/NVVM/Target.cpp
    mlir/test/Integration/GPU/CUDA/command-line-arg.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/LLVM/NVVM/Target.cpp b/mlir/lib/Target/LLVM/NVVM/Target.cpp
index 2d197a162a7af..076a2d4350fc3 100644
--- a/mlir/lib/Target/LLVM/NVVM/Target.cpp
+++ b/mlir/lib/Target/LLVM/NVVM/Target.cpp
@@ -587,7 +587,8 @@ NVPTXSerializer::compileToBinaryNVPTX(StringRef ptxCode) {
   std::string optLevel = std::to_string(this->optLevel);
   std::pair<llvm::BumpPtrAllocator, SmallVector<const char *>> cmdOpts =
       targetOptions.tokenizeCmdOptions();
-  cmdOpts.second.append(
+  cmdOpts.second.insert(
+      cmdOpts.second.begin(),
       {"-arch", getTarget().getChip().data(), "--opt-level", optLevel.c_str()});
 
   // Set optional command line arguments

diff  --git a/mlir/test/Integration/GPU/CUDA/command-line-arg.mlir b/mlir/test/Integration/GPU/CUDA/command-line-arg.mlir
index 77a4fa089b62d..2a0ae2e34c641 100644
--- a/mlir/test/Integration/GPU/CUDA/command-line-arg.mlir
+++ b/mlir/test/Integration/GPU/CUDA/command-line-arg.mlir
@@ -1,5 +1,5 @@
 // RUN: mlir-opt %s \
-// RUN:  | mlir-opt -gpu-lower-to-nvvm-pipeline="cubin-chip=sm_80 ptxas-cmd-options='-v --register-usage-level=8' allow-pattern-rollback=0" -debug-only=serialize-to-binary \
+// RUN:  | mlir-opt -gpu-lower-to-nvvm-pipeline="cubin-chip=sm_80 opt-level=3 ptxas-cmd-options='-v --opt-level=2 --register-usage-level=8' allow-pattern-rollback=0" -debug-only=serialize-to-binary \
 // RUN:  2>&1 | FileCheck %s
 
 func.func @host_function(%arg0 : f32, %arg1 : memref<?xf32>) {
@@ -16,6 +16,8 @@ func.func @host_function(%arg0 : f32, %arg1 : memref<?xf32>) {
     return
 }
 
-// CHECK: ptxas -arch sm_80
-// CHECK-SAME: -v 
+// CHECK: {{ptxas args: ptxas|Arguments:}} -arch sm_80
+// CHECK-SAME: --opt-level 3
+// CHECK-SAME: -v
+// CHECK-SAME: --opt-level=2
 // CHECK-SAME: --register-usage-level=8


        


More information about the Mlir-commits mailing list