Repository navigation
[SPIR-V] Default to NewPM - #239489
[SPIR-V] Default to NewPM#239489aobolensk wants to merge 2 commits into
Conversation
SPIR-V CodeGen now works with the NewPM, so make clang and llc default to it
|
@llvm/pr-subscribers-backend-spir-v Author: Arseniy Obolenskiy (aobolensk) ChangesSPIR-V CodeGen now works with the NewPM, so make clang and llc default to it Full diff: https://github.com/llvm/llvm-project/pull/239489.diff 14 Files Affected:
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 %}
;;
|
boomanaiden154
left a comment
There was a problem hiding this comment.
Where exactly is the SPIRV backend used? I think there are some gaps I haven't finished up yet where runCodeGenPipeline isn't used, so we'll use the legacy pipeline by default (mainly in LTO I believe). I was hoping to get to those in the next couple of days. If it's just standard clang/the other SPIRV specific places you fixed, then this shouldn't be an issue.
Also, how much does SPIRV care about LoopStrengthReduction? Enabling the NewPM currently causes optimization regressions, at least for CPU backends, due to LSR not really understanding LCSSA, which the NewPM enforces for loop pipelines. I've started landing patches to fix this, but won't expect it to be done for the next week or two. But given SPIRV is different in that it's virtual ISA, maybe this is a moot point?
| @@ -0,0 +1,11 @@ | |||
| // REQUIRES: spirv-registered-target | |||
There was a problem hiding this comment.
I am unsure why we need this test if we're defaulting to the NewPM.
-force-new-pm-codegen has coverage elsewhere, and we shouldn't care about the LegacyPM pipeline anymore.
It is used for OpenCL, HLSL, HIP, OpenMP from clang perspective, and SPIRVTranslate (MLIR) The SPIR-V llvm-project/clang/lib/Driver/ToolChains/SPIRV.cpp Lines 196 to 208 in 4f2748f clang-sycl-linker and the offload JIT still use the legacy pipeline: llvm-project/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp Lines 657 to 663 in 4f2748f llvm-project/offload/plugins-nextgen/common/src/JIT.cpp Lines 174 to 182 in 4f2748f Anyway, I'd like to get more feedback from the different stakeholders, in case they have downstream projects that could be impacted by this change |
I don't know much about it, but SPIR-V does not have any customizations for LSR |
|
For this change it's necessary to evaluate the impact on the final output (spirv) - can we quantify how much it changes ? I.e. did you try to run it on a relatively large corpus of kernels ? |
|
Once the changes to LSR land, CodeGen should be identical. If we want to land this before that, then yes, looking at CodeGen would be good. |
I ran only on https://github.com/ORNL/HeCBench in HIP flow. 565/565 at -O0 - no difference, 563/565 - identical at -O3 (non-HIP use case, artificial). 2 differences are caused by LSR. With |
SPIR-V CodeGen now works with the NewPM, so make clang and llc default to it