Fix RAM usage by splitting deeply nested expressions#783
Merged
Conversation
antoyo
commented
Oct 26, 2025
pinskia
reviewed
Oct 26, 2025
| self.bitcast_if_needed(res, result_type) | ||
| } | ||
|
|
||
| // GCC doesn't like deeply nested expressions. |
There was a problem hiding this comment.
This is due to:
/* Pre-mark tree nodes with TREE_VISITED so that they can be
deeply unshared during gimplification (including across
functions); this requires LANG_HOOKS_DEEP_UNSHARING to be true. */
TREE_VISITED (inner) = 1;
In jit-playback.h.
It is NOT GCC that does not like deeply nested expressions BUT rather libgccjit that does not like it.
Contributor
Author
There was a problem hiding this comment.
I tried this patch and it doesn't help with memory usage:
From 6e5317dacd4930be53d0ea37de0104d009189319 Mon Sep 17 00:00:00 2001
From: Antoni Boucher <bouanto@zoho.com>
Date: Sun, 26 Oct 2025 10:06:53 -0400
Subject: [PATCH] Fix TREE_VISITED
---
gcc/jit/jit-playback.cc | 2 ++
gcc/jit/jit-playback.h | 5 ++++-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
index e41408b635c..554057255bc 100644
--- a/gcc/jit/jit-playback.cc
+++ b/gcc/jit/jit-playback.cc
@@ -2186,6 +2186,7 @@ get_address (location *loc)
tree t_thistype = TREE_TYPE (t_lvalue);
tree t_ptrtype = build_pointer_type (t_thistype);
tree ptr = fold_build1 (ADDR_EXPR, t_ptrtype, t_lvalue);
+ TREE_VISITED (ptr) = 1;
if (loc)
get_context ()->set_tree_location (ptr, loc);
if (mark_addressable (loc))
@@ -2342,6 +2343,7 @@ playback::function::get_address (location *loc)
tree t_fndecl = as_fndecl ();
tree t_fntype = TREE_TYPE (t_fndecl);
tree t_fnptr = build1 (ADDR_EXPR, build_pointer_type (t_fntype), t_fndecl);
+ TREE_VISITED (t_fnptr) = 1;
if (loc)
m_ctxt->set_tree_location (t_fnptr, loc);
return new rvalue (m_ctxt, t_fnptr);
diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h
index 6f297136edc..fb1914e8bc7 100644
--- a/gcc/jit/jit-playback.h
+++ b/gcc/jit/jit-playback.h
@@ -757,7 +757,10 @@ public:
/* Pre-mark tree nodes with TREE_VISITED so that they can be
deeply unshared during gimplification (including across
functions); this requires LANG_HOOKS_DEEP_UNSHARING to be true. */
- TREE_VISITED (inner) = 1;
+ // TODO: try only setting TREE_VISITED on the ADDR_EXPR in
+ // playback::function::get_address and the ADDR_EXPR in
+ // playback::lvalue::get_address.
+ //TREE_VISITED (inner) = 1;
}
rvalue *
--
2.51.1
Contributor
Author
There was a problem hiding this comment.
If this helps, the memory usage happens in gimplify_function_tree.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #777
TREE_VISITEDon theADDR_EXPRinplayback::function::get_addressand theADDR_EXPRinplayback::lvalue::get_address. (edit: doesn't work)I was able to build
cargowith 5-10 GB RAM while it used to take +64 GB.This function would generate deeply nested expressions which made GCC use huge amount of RAM.