[llvm] [RISCV] Move RISCVInsertVSETVLI to after phi elimination (PR #91440)

Min-Yih Hsu via llvm-commits llvm-commits at lists.llvm.org
Wed May 15 11:33:26 PDT 2024


================
@@ -541,9 +541,16 @@ void RISCVPassConfig::addPreRegAlloc() {
   addPass(createRISCVPreRAExpandPseudoPass());
   if (TM->getOptLevel() != CodeGenOptLevel::None)
     addPass(createRISCVMergeBaseOffsetOptPass());
+
   addPass(createRISCVInsertReadWriteCSRPass());
   addPass(createRISCVInsertWriteVXRMPass());
-  addPass(createRISCVInsertVSETVLIPass());
+
+  // Run RISCVInsertVSETVLI after PHI elimination. On O1 and above do it after
+  // register coalescing so needVSETVLIPHI doesn't need to look through COPYs.
+  if (TM->getOptLevel() == CodeGenOptLevel::None)
+    insertPass(&PHIEliminationID, createRISCVInsertVSETVLIPass());
----------------
mshockwave wrote:

> One possible fix is if we're deleting a pass because we've reached the cut off point, we could delete any other passes in InsertedPass that are waiting on it?

A quick fix for this particular PR can be using `insertPass(&PHIEliminationID, &RISCVInsertVSETVLIID);` (although I guess we don't have a PassID for RISCVInsertVSETVLI?) The `insertPass` in this form won't cause the problem since it creates `Pass` pointer on-demand/on-the-fly rather than storing it.

But aside from this PR, yeah I think this is a bug in TargetPassConfig and your proposed fix makes sense to me. 

https://github.com/llvm/llvm-project/pull/91440


More information about the llvm-commits mailing list