[clang] [llvm] [SPIR-V] Default to NewPM (PR #239489)
Arseniy Obolenskiy via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 22 18:52:36 PST 2026
https://github.com/aobolensk updated https://github.com/llvm/llvm-project/pull/239489
>From 92584de70061ca528e944fba957e850bb328fe4e Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Fri, 6 Nov 2026 07:40:28 +0100
Subject: [PATCH 1/3] [SPIR-V] Default to NewPM
SPIR-V CodeGen now works with the NewPM, so make clang and llc default to it
---
clang/test/CodeGenSPIRV/newpm.c | 11 +++++++++++
llvm/lib/Target/SPIRV/SPIRVTargetMachine.h | 2 ++
llvm/test/CodeGen/SPIRV/debug-info/debug-declare.ll | 1 -
.../CodeGen/SPIRV/debug-info/debug-value-constant.ll | 1 -
llvm/test/CodeGen/SPIRV/debug-info/debug-value.ll | 1 -
.../extensions/SPV_KHR_float_controls2/decoration.ll | 1 -
.../SPIRV/hlsl-intrinsics/WaveActiveAnyTrue.ll | 2 --
.../CodeGen/SPIRV/instructions/undef-composite.ll | 2 --
llvm/test/CodeGen/SPIRV/llc-pipeline.ll | 8 ++++----
llvm/test/CodeGen/SPIRV/loop-unroll-nonshader.ll | 2 --
.../CodeGen/SPIRV/pointers/global-vars-untyped.ll | 1 -
.../CodeGen/SPIRV/structurizer/cf.while.continue.ll | 2 --
llvm/test/CodeGen/SPIRV/structurizer/do-continue.ll | 2 --
.../CodeGen/SPIRV/transcoding/NoSignedUnsignedWrap.ll | 1 -
14 files changed, 17 insertions(+), 20 deletions(-)
create mode 100644 clang/test/CodeGenSPIRV/newpm.c
diff --git a/clang/test/CodeGenSPIRV/newpm.c b/clang/test/CodeGenSPIRV/newpm.c
new file mode 100644
index 00000000000000..71902d838d8096
--- /dev/null
+++ b/clang/test/CodeGenSPIRV/newpm.c
@@ -0,0 +1,11 @@
+// REQUIRES: spirv-registered-target
+// RUN: %clang_cc1 -triple spirv64 -S -mllvm -print-after=spirv-asm-printer \
+// RUN: %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=NPM
+// RUN: %clang_cc1 -triple spirv64 -S -mllvm -print-after=spirv-asm-printer \
+// RUN: -mllvm -force-new-pm-codegen=false %s -o /dev/null 2>&1 \
+// RUN: | FileCheck %s --check-prefix=LEGACY
+
+// NPM: *** IR Dump After SPIRVAsmPrinterPass on foo ***
+// LEGACY: *** IR Dump After SPIRV Assembly Printer (spirv-asm-printer) ***
+
+void foo(void) {}
diff --git a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.h b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.h
index 2f2c1b2d666b6e..97d63774214801 100644
--- a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.h
+++ b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.h
@@ -54,6 +54,8 @@ class SPIRVTargetMachine : public CodeGenTargetMachineImpl {
CodeGenFileType FileType,
const CGPassBuilderOption &Opt, MCContext &Ctx,
PassInstrumentationCallbacks *PIC) override;
+
+ bool shouldDefaultToNewPM() const override { return true; }
};
} // namespace llvm
diff --git a/llvm/test/CodeGen/SPIRV/debug-info/debug-declare.ll b/llvm/test/CodeGen/SPIRV/debug-info/debug-declare.ll
index a766a46598c86b..0cb25fc35f9585 100644
--- a/llvm/test/CodeGen/SPIRV/debug-info/debug-declare.ll
+++ b/llvm/test/CodeGen/SPIRV/debug-info/debug-declare.ll
@@ -1,5 +1,4 @@
; RUN: llc --verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_KHR_non_semantic_info %s -o - | FileCheck %s --implicit-check-not=DebugValue
-; RUN: llc -enable-new-pm --verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_KHR_non_semantic_info %s -o - | FileCheck %s --implicit-check-not=DebugValue
; RUN: %if spirv-tools %{ llc --verify-machineinstrs --spirv-ext=+SPV_KHR_non_semantic_info -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
; A #dbg_declare on an alloca that survives to MIR: the parameter copy and a
diff --git a/llvm/test/CodeGen/SPIRV/debug-info/debug-value-constant.ll b/llvm/test/CodeGen/SPIRV/debug-info/debug-value-constant.ll
index 79a3e6c1f4c62b..1574c253d01d0f 100644
--- a/llvm/test/CodeGen/SPIRV/debug-info/debug-value-constant.ll
+++ b/llvm/test/CodeGen/SPIRV/debug-info/debug-value-constant.ll
@@ -1,5 +1,4 @@
; RUN: llc --verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --asm-verbose=0 --spirv-ext=+SPV_KHR_non_semantic_info %s -o - | FileCheck %s --implicit-check-not="OpCapability Int8" --implicit-check-not="OpCapability Int16" --implicit-check-not="OpCapability Int64" --implicit-check-not="OpCapability Float16" --implicit-check-not="OpCapability Float64"
-; RUN: llc -enable-new-pm --verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --asm-verbose=0 --spirv-ext=+SPV_KHR_non_semantic_info %s -o - | FileCheck %s --implicit-check-not="OpCapability Int8" --implicit-check-not="OpCapability Int16" --implicit-check-not="OpCapability Int64" --implicit-check-not="OpCapability Float16" --implicit-check-not="OpCapability Float64"
; RUN: llc --verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --asm-verbose=0 --spirv-ext=+SPV_KHR_non_semantic_info %s -o - | FileCheck %s --check-prefix=UNIQUE
; RUN: llc --verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --asm-verbose=0 --spirv-ext=+SPV_KHR_non_semantic_info %s -o - | FileCheck %s --check-prefix=DROPPED
; RUN: llc --verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --asm-verbose=0 --spirv-ext=+SPV_KHR_non_semantic_info %s -o - | FileCheck %s --check-prefix=DEDUP
diff --git a/llvm/test/CodeGen/SPIRV/debug-info/debug-value.ll b/llvm/test/CodeGen/SPIRV/debug-info/debug-value.ll
index 56c505e79f9650..ab2a233a20b7c0 100644
--- a/llvm/test/CodeGen/SPIRV/debug-info/debug-value.ll
+++ b/llvm/test/CodeGen/SPIRV/debug-info/debug-value.ll
@@ -1,7 +1,6 @@
; asm-verbose=0 keeps AsmPrinter's ;DEBUG_VALUE: comments out of the output so
; the CHECK-NEXT chains track SPIR-V instructions only.
; RUN: llc --verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --asm-verbose=0 --spirv-ext=+SPV_KHR_non_semantic_info %s -o - | FileCheck %s --implicit-check-not=DebugDeclare
-; RUN: llc -enable-new-pm --verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --asm-verbose=0 --spirv-ext=+SPV_KHR_non_semantic_info %s -o - | FileCheck %s --implicit-check-not=DebugDeclare
; RUN: %if spirv-tools %{ llc --verify-machineinstrs --spirv-ext=+SPV_KHR_non_semantic_info -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
; A direct DBG_VALUE whose virtual register is defined by an emitted SPIR-V
diff --git a/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_float_controls2/decoration.ll b/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_float_controls2/decoration.ll
index 2b6e2cd7eb5942..d9a40ac266d352 100644
--- a/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_float_controls2/decoration.ll
+++ b/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_float_controls2/decoration.ll
@@ -1,5 +1,4 @@
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_KHR_float_controls2 %s -o - | FileCheck %s
-; RUN: llc -enable-new-pm -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_KHR_float_controls2 %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_KHR_float_controls2 %s -o - -filetype=obj | spirv-val %}
; CHECK-DAG: Capability FloatControls2
diff --git a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveAnyTrue.ll b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveAnyTrue.ll
index 511ed5c1acf90c..88a0c88c99bf16 100644
--- a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveAnyTrue.ll
+++ b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveAnyTrue.ll
@@ -1,7 +1,5 @@
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}
-; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown -enable-new-pm %s -o - | FileCheck %s
-; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown -enable-new-pm %s -o - -filetype=obj | spirv-val %}
; CHECK-DAG: %[[#bool:]] = OpTypeBool
; CHECK-DAG: %[[#uint:]] = OpTypeInt 32 0
diff --git a/llvm/test/CodeGen/SPIRV/instructions/undef-composite.ll b/llvm/test/CodeGen/SPIRV/instructions/undef-composite.ll
index 9df2c895070d7b..4defc5a8d96363 100644
--- a/llvm/test/CodeGen/SPIRV/instructions/undef-composite.ll
+++ b/llvm/test/CodeGen/SPIRV/instructions/undef-composite.ll
@@ -1,7 +1,5 @@
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
-; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown -enable-new-pm %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
-; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown -enable-new-pm %s -o - -filetype=obj | spirv-val %}
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-vulkan-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-vulkan-unknown %s -o - -filetype=obj | spirv-val %}
diff --git a/llvm/test/CodeGen/SPIRV/llc-pipeline.ll b/llvm/test/CodeGen/SPIRV/llc-pipeline.ll
index 246e9e440bd7f4..b0a526f07baa9e 100644
--- a/llvm/test/CodeGen/SPIRV/llc-pipeline.ll
+++ b/llvm/test/CodeGen/SPIRV/llc-pipeline.ll
@@ -1,11 +1,11 @@
; UNSUPPORTED:expensive_checks
-; RUN:llc -O0 -mtriple=spirv-- -disable-verify -debug-pass=Structure < %s 2>&1 \
+; RUN:llc -O0 -mtriple=spirv-- -enable-new-pm=false -disable-verify -debug-pass=Structure < %s 2>&1 \
; RUN: | FileCheck -match-full-lines -strict-whitespace -check-prefix=SPIRV-O0 %s
-; RUN:llc -O1 -mtriple=spirv-- -disable-verify -debug-pass=Structure < %s 2>&1 \
+; RUN:llc -O1 -mtriple=spirv-- -enable-new-pm=false -disable-verify -debug-pass=Structure < %s 2>&1 \
; RUN: | FileCheck -match-full-lines -strict-whitespace -check-prefix=SPIRV-Opt %s
-; RUN:llc -O2 -mtriple=spirv-- -disable-verify -debug-pass=Structure < %s 2>&1 \
+; RUN:llc -O2 -mtriple=spirv-- -enable-new-pm=false -disable-verify -debug-pass=Structure < %s 2>&1 \
; RUN: | FileCheck -match-full-lines -strict-whitespace -check-prefix=SPIRV-Opt %s
-; RUN:llc -O3 -mtriple=spirv-- -disable-verify -debug-pass=Structure < %s 2>&1 \
+; RUN:llc -O3 -mtriple=spirv-- -enable-new-pm=false -disable-verify -debug-pass=Structure < %s 2>&1 \
; RUN: | FileCheck -match-full-lines -strict-whitespace -check-prefix=SPIRV-Opt %s
; RUN:llc -O0 -mtriple=spirv-- -enable-new-pm < %s \
; RUN: | FileCheck -check-prefix=SPIRV-NPM %s
diff --git a/llvm/test/CodeGen/SPIRV/loop-unroll-nonshader.ll b/llvm/test/CodeGen/SPIRV/loop-unroll-nonshader.ll
index a865bffea60637..d5f8eaefd7505a 100644
--- a/llvm/test/CodeGen/SPIRV/loop-unroll-nonshader.ll
+++ b/llvm/test/CodeGen/SPIRV/loop-unroll-nonshader.ll
@@ -1,7 +1,5 @@
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
-; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown -enable-new-pm %s -o - | FileCheck %s
-; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown -enable-new-pm %s -o - -filetype=obj | spirv-val %}
; Test that OpLoopMerge is emitted for non-shader targets without requiring
; SPV_INTEL_unstructured_loop_controls.
diff --git a/llvm/test/CodeGen/SPIRV/pointers/global-vars-untyped.ll b/llvm/test/CodeGen/SPIRV/pointers/global-vars-untyped.ll
index 319d24707a7d54..c6652e488cac75 100644
--- a/llvm/test/CodeGen/SPIRV/pointers/global-vars-untyped.ll
+++ b/llvm/test/CodeGen/SPIRV/pointers/global-vars-untyped.ll
@@ -1,5 +1,4 @@
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -stop-after=ir-translator -o - | FileCheck %s
-; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -stop-after=ir-translator -enable-new-pm -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
; CHECK: @__spirv_BuiltInLocalInvocationId = external addrspace(1) global ptr addrspace
diff --git a/llvm/test/CodeGen/SPIRV/structurizer/cf.while.continue.ll b/llvm/test/CodeGen/SPIRV/structurizer/cf.while.continue.ll
index 70edd56170efa9..e5545c62db5839 100644
--- a/llvm/test/CodeGen/SPIRV/structurizer/cf.while.continue.ll
+++ b/llvm/test/CodeGen/SPIRV/structurizer/cf.while.continue.ll
@@ -1,7 +1,5 @@
; RUN: llc -mtriple=spirv-unknown-vulkan-compute -O0 %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - -filetype=obj | spirv-val %}
-; RUN: llc -mtriple=spirv-unknown-vulkan-compute -O0 -enable-new-pm %s -o - | FileCheck %s
-; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan-compute -enable-new-pm %s -o - -filetype=obj | spirv-val %}
;
; int foo() { return true; }
diff --git a/llvm/test/CodeGen/SPIRV/structurizer/do-continue.ll b/llvm/test/CodeGen/SPIRV/structurizer/do-continue.ll
index 4f0e89dec65b24..b95642f51c9fee 100644
--- a/llvm/test/CodeGen/SPIRV/structurizer/do-continue.ll
+++ b/llvm/test/CodeGen/SPIRV/structurizer/do-continue.ll
@@ -1,7 +1,5 @@
; RUN: llc -mtriple=spirv-unknown-vulkan-compute -O0 %s -o - | FileCheck %s --match-full-lines
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - -filetype=obj | spirv-val %}
-; RUN: llc -mtriple=spirv-unknown-vulkan-compute -O0 -enable-new-pm %s -o - | FileCheck %s --match-full-lines
-; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan-compute -enable-new-pm %s -o - -filetype=obj | spirv-val %}
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"
target triple = "spirv-unknown-vulkan1.3-compute"
diff --git a/llvm/test/CodeGen/SPIRV/transcoding/NoSignedUnsignedWrap.ll b/llvm/test/CodeGen/SPIRV/transcoding/NoSignedUnsignedWrap.ll
index 71b4b87bec95ef..e66c4de5b65ac9 100644
--- a/llvm/test/CodeGen/SPIRV/transcoding/NoSignedUnsignedWrap.ll
+++ b/llvm/test/CodeGen/SPIRV/transcoding/NoSignedUnsignedWrap.ll
@@ -8,7 +8,6 @@
;; Positive tests:
;;
; RUN: llc -O0 -mtriple=spirv32v1.3-unknown-unknown --spirv-ext=+SPV_KHR_no_integer_wrap_decoration %s -o - | FileCheck %s --check-prefixes=CHECK-SPIRV
-; RUN: llc -enable-new-pm -O0 -mtriple=spirv32v1.3-unknown-unknown --spirv-ext=+SPV_KHR_no_integer_wrap_decoration %s -o - | FileCheck %s --check-prefixes=CHECK-SPIRV
; RUN: llc -O0 -mtriple=spirv32v1.4-unknown-unknown %s -o - | FileCheck %s --check-prefixes=CHECK-SPIRV,CHECK-SPIRV-NOEXT
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32v1.4-unknown-unknown %s -o - -filetype=obj | spirv-val --target-env spv1.4 %}
;;
>From 7385637baa4f00f5fbd01a92c9e6649bc8bd615f Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Fri, 6 Nov 2026 07:51:38 +0100
Subject: [PATCH 2/3] remove test
---
clang/test/CodeGenSPIRV/newpm.c | 11 -----------
1 file changed, 11 deletions(-)
delete mode 100644 clang/test/CodeGenSPIRV/newpm.c
diff --git a/clang/test/CodeGenSPIRV/newpm.c b/clang/test/CodeGenSPIRV/newpm.c
deleted file mode 100644
index 71902d838d8096..00000000000000
--- a/clang/test/CodeGenSPIRV/newpm.c
+++ /dev/null
@@ -1,11 +0,0 @@
-// REQUIRES: spirv-registered-target
-// RUN: %clang_cc1 -triple spirv64 -S -mllvm -print-after=spirv-asm-printer \
-// RUN: %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=NPM
-// RUN: %clang_cc1 -triple spirv64 -S -mllvm -print-after=spirv-asm-printer \
-// RUN: -mllvm -force-new-pm-codegen=false %s -o /dev/null 2>&1 \
-// RUN: | FileCheck %s --check-prefix=LEGACY
-
-// NPM: *** IR Dump After SPIRVAsmPrinterPass on foo ***
-// LEGACY: *** IR Dump After SPIRV Assembly Printer (spirv-asm-printer) ***
-
-void foo(void) {}
>From f40049b1f4a4b5f4decc17b5663c2d7853824657 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Mon, 9 Nov 2026 18:23:53 +0100
Subject: [PATCH 3/3] remove flag
---
llvm/unittests/Target/SPIRV/SPIRVAPITest.cpp | 18 ------------------
1 file changed, 18 deletions(-)
diff --git a/llvm/unittests/Target/SPIRV/SPIRVAPITest.cpp b/llvm/unittests/Target/SPIRV/SPIRVAPITest.cpp
index ddaadfc3374079..321c092bc7518f 100644
--- a/llvm/unittests/Target/SPIRV/SPIRVAPITest.cpp
+++ b/llvm/unittests/Target/SPIRV/SPIRVAPITest.cpp
@@ -15,7 +15,6 @@
#include "llvm/AsmParser/Parser.h"
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/IR/Module.h"
-#include "llvm/Support/CommandLine.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/TargetParser/Triple.h"
#include "gtest/gtest.h"
@@ -110,23 +109,6 @@ TEST_F(SPIRVAPITest, checkTranslateOk) {
}
}
-TEST_F(SPIRVAPITest, checkTranslateNewPM) {
- LLVMContext Context;
- const char *Args[] = {"prog", "-force-new-pm-codegen"};
- ASSERT_TRUE(cl::parseCommandLineOptions(Context.getLibraryOptions(), Args, "",
- &nulls()));
- SMDiagnostic ParseError;
- std::unique_ptr<Module> M =
- parseAssemblyString(OkAssembly, ParseError, Context);
- ASSERT_TRUE(M);
- std::string Result, Error;
- bool Status =
- SPIRVTranslate(M.get(), Result, Error, {}, CodeGenOptLevel::Default,
- Triple("spirv32-unknown-unknown"));
- EXPECT_TRUE(Status && Error.empty() && !Result.empty());
- EXPECT_EQ(identify_magic(Result), file_magic::spirv_object);
-}
-
TEST_F(SPIRVAPITest, checkTranslateSupportExtensionByArg) {
std::string Result, Error;
std::vector<std::string> ExtNames{"SPV_KHR_uniform_group_instructions"};
More information about the cfe-commits
mailing list