cmd/compile: partial cse of phi inputs? #37415
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
This is an optimization idea, one that is still very rough. I'm interested in feedback and ideas.
Consider the beginning of os/basename (on unix):
After decompose built-in, part of the loop here has SSA form
b1 is the entry block. v11 is
i
. v74 islen(name)
.Consider v11's args in more detail.
v10 is
Add64 <int> v26 v54 (i[int])
. v41 isAdd64 <int> v26 v11 (i[int])
. (v26 is const -1.) They are the same except for the second arg.So we could do a partial CSE and rewrite v11 as:
Add64 <int> v26 vNEW (i[int])
, where vNEW isPhi <int> v54 v11
. Which is to say, vNEW is the same as v74!So we end up with fewer phi values, and fewer Add64 values. We might even be able to eliminate a bounds check (v17) that was previously out of reach; I'm not sure.
Note that this transformation is I believe similar in effect to optimizing the code above to not modify name in the loop:
In this optimized code we have only a single phi value (for
i
), and we calculatelen(name)
from it when we need it. The CSE'ing approach discussed above generates code that has only a single phi value (forlen(name)
) and we calculatei
from it when we need it.In general terms, the idea is to look for phi values whose arguments are identical except for a single argument, and then to CSE those arguments, replacing the varying argument with a new phi value.
cc @randall77 @dr2chase @cherrymui
The text was updated successfully, but these errors were encountered: