Skip to content

Commit 565a9ac

Browse files
[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.
1 parent ca79e12 commit 565a9ac

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class SPIRVPassConfig : public TargetPassConfig {
102102
SPIRVTargetMachine &getSPIRVTargetMachine() const {
103103
return getTM<SPIRVTargetMachine>();
104104
}
105+
void addMachineSSAOptimization() override;
105106
void addIRPasses() override;
106107
void addISelPrepare() override;
107108

@@ -129,6 +130,16 @@ FunctionPass *SPIRVPassConfig::createTargetRegisterAllocator(bool) {
129130
return nullptr;
130131
}
131132

133+
// Disable passes that may break CFG.
134+
void SPIRVPassConfig::addMachineSSAOptimization() {
135+
// Some standard passes that optimize machine instructions in SSA form uses
136+
// MI.isPHI() that doesn't account for OpPhi in SPIR-V and so are able to
137+
// break the CFG (e.g., MachineSink).
138+
disablePass(&MachineSinkingID);
139+
140+
TargetPassConfig::addMachineSSAOptimization();
141+
}
142+
132143
// Disable passes that break from assuming no virtual registers exist.
133144
void SPIRVPassConfig::addPostRegAlloc() {
134145
// Do not work with vregs instead of physical regs.

0 commit comments

Comments
 (0)