[llvm] [SDAG] Merge multiple-result libcall expansion into DAG.expandMultipleResultFPLibCall() (PR #114792)

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 4 12:11:49 PST 2024


================
@@ -270,6 +271,15 @@ SDValue VectorLegalizer::LegalizeOp(SDValue Op) {
   DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op);
   if (I != LegalizedNodes.end()) return I->second;
 
+  // Handle legalizing the root if it changes.
+  auto FixupRoot = make_scope_exit([&, OldRoot = DAG.getRoot()] {
+    SDValue Root = DAG.getRoot();
+    if (Root != OldRoot) {
+      if (SDValue LegalRoot = LegalizeOp(Root))
+        DAG.setRoot(LegalRoot);
+    }
+  });
----------------
MacDue wrote:

I mentioned this here https://github.com/llvm/llvm-project/pull/114792#discussion_r1827761815 (adding a `FIXME`). The weird change management originally done for `frexp` changes the root to point at the call's output chain. Changing the root out from under the vector legalization causes it to assert that the root has not been legalized. So, I needed to add this fixup to ensure if an expansion changes the root, the new root is still legalized.

I don't think this is ideal (hence the `FIXME`), but I'm not sure how else to fix it. Open to suggestions though :slightly_smiling_face: 

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


More information about the llvm-commits mailing list