-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[SPIR-V] Disable Machine Sink pass in SPIR-V Backend #116060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPIR-V] Disable Machine Sink pass in SPIR-V Backend #116060
Conversation
@llvm/pr-subscribers-backend-spir-v Author: Vyacheslav Levytskyy (VyacheslavLevytskyy) ChangesSome 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 llvm-project/llvm/lib/CodeGen/MachineSink.cpp Line 630 in 1884ffc
There is a reproducer of the issue that demonstrates how MachineSink is able to generate an invalid code for the SPIR-V Backend
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. Full diff: https://github.com/llvm/llvm-project/pull/116060.diff 1 Files Affected:
diff --git a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
index 194ce7c10bfd3f..bf4d974329de34 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.
|
@michalpaszkowski @Keenuts This PR is a reminder that #110507 doesn't resolve all issues related to OpPhi in SPIR-V. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for this PR.
Once #110507 is merged, shall the Machine Sink pass be updated to also use TII to query isPhi
?
Probably I would make it a part of a wider initiative, with a RFC and proper discussion. |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/88/builds/4774 Here is the relevant piece of the build log for the reference
|
…9202) This PR improves general validity of emitted code between passes due to generation of `TargetOpcode::PHI` instead of `SPIRV::OpPhi` after Instruction Selection, fixing generation of OpTypePointer instructions and using of proper virtual register classes. Using `TargetOpcode::PHI` instead of `SPIRV::OpPhi` after Instruction Selection has a benefit to support existing optimization passes immediately, as an alternative path to disable those passes that use `MI.isPHI()`. This PR makes it possible thus to revert #116060 actions and get back to use the `MachineSink` pass. This PR is a solution of the problem discussed in details in #110507. It accepts an advice from code reviewers of the PR #110507 to postpone generation of OpPhi rather than to patch CodeGen. This solution allows to unblock improvements wrt. expensive checks and makes it unrelated to the general points of the discussion about OpPhi vs. G_PHI/PHI. This PR contains numerous small patches of emitted code validity that allows to substantially pass rate with expensive checks. Namely, the test suite with expensive checks set ON now has only 12 fails out of 569 total test cases. FYI @bogner
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
llvm-project/llvm/lib/CodeGen/MachineSink.cpp
Line 630 in 1884ffc
There is a reproducer of the issue that demonstrates how MachineSink is able to generate an invalid code for the SPIR-V Backend
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.