Skip to content

Fix phi node value renumbering issue #28099

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

Merged
merged 2 commits into from
Jul 16, 2018
Merged

Fix phi node value renumbering issue #28099

merged 2 commits into from
Jul 16, 2018

Conversation

martinholters
Copy link
Member

If a φ node got placed at a position one of its values referenced, that reference wasn't updated.
Fixes #28077.

@martinholters martinholters added the bugfix This change fixes an existing bug label Jul 13, 2018
@martinholters martinholters requested a review from Keno July 13, 2018 12:54
@@ -679,7 +679,7 @@ function process_phinode_values(old_values::Vector{Any}, late_fixup::Vector{Int}
used_ssas[val.id] += 1
end
elseif isa(val, OldSSAValue)
if val.id > processed_idx
if val.id >= processed_idx
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test passes without this one. I do think the change is correct, but if someone can come up with a piece of code that comes here with val.id==processed_idx to build a test case, that would be appreciated.

@JeffBezanson JeffBezanson added the compiler:optimizer Optimization passes (mostly in base/compiler/ssair/) label Jul 13, 2018
@martinholters
Copy link
Member Author

freebsd failure is #28101.
Circle says: "Your current usage represents 78% of your JuliaLang Linux plan's limit." Looking at the queue, that percentage sounds, eh, slightly underestimated.

@Keno
Copy link
Member

Keno commented Jul 14, 2018

Thanks. I'm very happy that other people are starting to be able to make changes to this code. I particularly appreciate the test case in this PR. However, I think the real bug here is different. Adding the current statement to the rename table is supposed to happen before renaming of the phinode arguments, so it seemed to me the original code is correct. Instead I think what's happening is that the processed_idx is wrong for newly inserted nodes (passing the old idx of the reference statement instead). I think something like this may work:

diff --git a/base/compiler/ssair/ir.jl b/base/compiler/ssair/ir.jl
index 1db42da..6e3f23b 100644
--- a/base/compiler/ssair/ir.jl
+++ b/base/compiler/ssair/ir.jl
@@ -836,14 +836,16 @@ function iterate(compact::IncrementalCompact, (idx, active_bb)::Tuple{Int, Int}=
         compact.new_nodes_idx += 1
         new_node_entry = compact.ir.new_nodes[new_idx]
         new_idx += length(compact.ir.stmts)
-        return process_newnode!(compact, new_idx, new_node_entry, idx, active_bb, true)
+        return process_newnode!(compact, new_idx, new_node_entry,
+            entry.attach_after ? idx : idx - 1, active_bb, true)
     elseif !isempty(compact.pending_perm) &&
         (entry = compact.pending_nodes[compact.pending_perm[1]];
          entry.attach_after ? entry.pos == idx - 1 : entry.pos == idx)
         new_idx = popfirst!(compact.pending_perm)
         new_node_entry = compact.pending_nodes[new_idx]
         new_idx += length(compact.ir.stmts) + length(compact.ir.new_nodes)
-        return process_newnode!(compact, new_idx, new_node_entry, idx, active_bb, false)
+        return process_newnode!(compact, new_idx, new_node_entry,
+            entry.attach_after ? idx : idx - 1, active_bb, false)
     end
     # This will get overwritten in future iterations if
     # result_idx is not, incremented, but that's ok and expected

@martinholters
Copy link
Member Author

Yep, that patch seems to be working. Updated PR accordingly. (I don't fully understand what's happening, so @Keno if you can come up with a more descriptive commit message...)

@Keno
Copy link
Member

Keno commented Jul 16, 2018

Actually, that's still incorrect. I think idx-1 is always correct. I'll update the PR.

Keno and others added 2 commits July 16, 2018 14:54
When inserting new nodes during compaction, we need to rename all arguments.
For performance, we keep track of which nodes we have already processed,
renaming them immediately, and only scheduling those we have not for later
re-processing. However, the was an off-by-one error in this logic such that a phi
node refering to the statement it is being attached to would not get scheduled
for later fixup.
The test is not an exact replica of that issue, but modifies it to
compute a testable value (summing the numbers 1 to 10 in a goto-loop).
@Keno Keno merged commit 916c193 into master Jul 16, 2018
@StefanKarpinski StefanKarpinski deleted the mh/fix_28077 branch July 17, 2018 01:19
@martinholters
Copy link
Member Author

The fact that we had three similar, but not equivalent patches that all fixed the issue and did not break any other tests makes me a bit uneasy. Ideally, we would have tests that had failed for the wrong fixes here. I'm clueless how to construct such tests, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants