[llvm] 565a9ac - [SPIR-V] Disable Machine Sink pass in SPIR-V Backend (#116060)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 19 12:42:47 PST 2024
Author: Vyacheslav Levytskyy
Date: 2024-11-19T21:42:44+01:00
New Revision: 565a9ac7df3815ed038938942be4cf1471de4755
URL: https://github.com/llvm/llvm-project/commit/565a9ac7df3815ed038938942be4cf1471de4755
DIFF: https://github.com/llvm/llvm-project/commit/565a9ac7df3815ed038938942be4cf1471de4755.diff
LOG: [SPIR-V] Disable Machine Sink pass in SPIR-V Backend (#116060)
Some standard passes that optimize machine instructions in SSA form uses
MI.isPHI() that doesn't account for OpPhi in SPIR-V and so are able to
break the CFG. MachineSink is among such passes (see for example
https://github.com/llvm/llvm-project/blob/1884ffc41c20b1e08b30eef4e8ebbcc54543a139/llvm/lib/CodeGen/MachineSink.cpp#L630),
so this PR disables the pass to ensure correctness of the generated
code.
There is a reproducer of the issue that demonstrates how MachineSink is
able to generate an invalid code for the SPIR-V Backend
```
error: line 6837: OpPhi must appear within a non-entry block before all non-OpPhi instructions (except for OpLine, which can be mixed with OpPhi).
%z_fra_3_1 = OpPhi %uint %and187 %4250 %inc194 %4257 %uint_0 %4264
```
The reproducer is a part of SYCL end-to-end test suite
(https://github.com/intel/llvm/blob/sycl/sycl/test-e2e/DeviceLib/imf_fp32_rounding_test.cpp).
At the moment it doesn't seem feasible to make it a part of the SPIR-V
Backend test suite due to a far too big size of the intermediate LLVM IR
that causes the problem.
Added:
Modified:
llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
index 6646795408feaa..8f38d4b8307da2 100644
--- a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
@@ -102,6 +102,7 @@ class SPIRVPassConfig : public TargetPassConfig {
SPIRVTargetMachine &getSPIRVTargetMachine() const {
return getTM<SPIRVTargetMachine>();
}
+ void addMachineSSAOptimization() override;
void addIRPasses() override;
void addISelPrepare() override;
@@ -129,6 +130,16 @@ FunctionPass *SPIRVPassConfig::createTargetRegisterAllocator(bool) {
return nullptr;
}
+// Disable passes that may break CFG.
+void SPIRVPassConfig::addMachineSSAOptimization() {
+ // Some standard passes that optimize machine instructions in SSA form uses
+ // MI.isPHI() that doesn't account for OpPhi in SPIR-V and so are able to
+ // break the CFG (e.g., MachineSink).
+ disablePass(&MachineSinkingID);
+
+ TargetPassConfig::addMachineSSAOptimization();
+}
+
// Disable passes that break from assuming no virtual registers exist.
void SPIRVPassConfig::addPostRegAlloc() {
// Do not work with vregs instead of physical regs.
More information about the llvm-commits
mailing list