-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
JIT: simple redundant compare optimization #43811
Conversation
For a relop, walk up the dominator tree to see if any dominating block has a similar compare. If so, and there's just one path from that block to the relop, the relop's value is known. Closes dotnet#11909.
@briansull PTAL. This will eventually feed into optimizing redundant class checks we'll see in dynamic PGO.
Diff from #11909 ; Assembly listing for method String:EndsWith(String,int):bool:this
;; BEFORE
G_M26632_IG11:
mov ebx, dword ptr [rdi+8]
mov r8d, ebx
sub r8d, r9d
cmp ebx, r8d
jb SHORT G_M26632_IG16
cmp ebx, r8d
jb G_M26632_IG22
G_M26632_IG12:
add rdi, 12
;; AFTER
G_M26632_IG11:
mov ebx, dword ptr [rdi+8]
mov r8d, ebx
sub r8d, r9d
cmp ebx, r8d
jb SHORT G_M26632_IG15
add rdi, 12 |
Note it feels a bit odd to be doing this opt here, as it's not strictly related to assertion prop, but it doesn't seem to warrant its own phase. Feel free to suggest a better home. |
@dotnet/jit-contrib anyone able to take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with doc suggestion
@@ -3215,6 +3215,153 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions, Gen | |||
GenTree* op1 = tree->AsOp()->gtOp1; | |||
GenTree* op2 = tree->AsOp()->gtOp2; | |||
|
|||
// First, walk up the dom tree and see if any dominating block has branched on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should update the method header to the standard header and under Note: add comment saying that we also do this special case optimization.
One test failure on x64 osx: profiler/elt/slowpatheltleave/slowpatheltleave.sh This test seems to fail sporadically once a day or so. It looks like the test "passes" but then perhaps the runtime crashes on exit? @davmason is this on your radar? |
No, I haven't seen that before. I'll take a look |
I'm going to merge as the one failure above does not seem related. |
@AndyAyersMS should have also fixed #35348 |
For a relop, walk up the dominator tree to see if any dominating
block has a similar compare. If so, and there's just one path from
that block to the relop, the relop's value is known.
Closes #11909.