Skip to content

X86: Check if two addresses are equal in arraycmp - #6439

Merged
0xdaryl merged 1 commit into
eclipse-omr:masterfrom
a7ehuo:enhance-SSE2ArraycmpEvaluator
Mar 29, 2022
Merged

0xdaryl merged 1 commit into
eclipse-omr:masterfrom
a7ehuo:enhance-SSE2ArraycmpEvaluator

Conversation

@a7ehuo

@a7ehuo a7ehuo commented Mar 28, 2022 •

Copy link
Copy Markdown
Contributor

If s1 and s2 point to the same address, jmp directly to equalLabel.

Signed-off-by: Annabelle Huo Annabelle.Huo@ibm.com

If s1 and s2 points to the same address, jmp directly to
equalLabel.

Signed-off-by: Annabelle Huo <Annabelle.Huo@ibm.com>
@a7ehuo
a7ehuo requested review from 0xdaryl and mstoodle as code owners March 28, 2022 16:40
@a7ehuo
a7ehuo requested review from vijaysun-omr and removed request for mstoodle March 28, 2022 16:40
@a7ehuo

a7ehuo commented Mar 28, 2022

Copy link
Copy Markdown
Contributor Author

@0xdaryl @vijaysun-omr May I ask you to review this change? Thank you!

@0xdaryl

0xdaryl commented Mar 28, 2022

Copy link
Copy Markdown
Contributor

Is this short-circuit optimization applicable on the other platforms as well?

@a7ehuo a7ehuo changed the title Check if two addresses are equal in arraycmp X86: Check if two addresses are equal in arraycmp Mar 28, 2022
@a7ehuo

a7ehuo commented Mar 28, 2022

Copy link
Copy Markdown
Contributor Author

Is this short-circuit optimization applicable on the other platforms as well?

The implementation of arraycmpEvaluator on other platforms look quite different to me.

  • aarch64: unimplemented
  • Power:
    Based on my very limited understanding of power instructions, it doesn't look to me the implementation in inlineArrayCmp or inlineArrayCmpP10 checks if src1Addr is the same as src2Addr (I could be wrong). @zl-wang I'm wondering if you know if there is a reason that the implementation for arraycmpEvaluator in power doesn't check if src1Addr is the same as src2Addr first before comparing the memory? Is this something that could be explored and implemented in p for potential performance enhancement?
  • Z:
    arraycmp is implemented in multiple places in Z::TreeEvaluator::arraycmpEvaluator. I checked Z::TreeEvaluator::arraycmpEvaluator, TR::TreeEvaluator::arraycmpHelper, and TreeEvaluator::arraycmpSIMDHelper. Based on my very limited understanding of z instructions, it doesn't look to me it checks if both addresses are the same address before doing the memory comparison (I could be wrong). @joransiu I'm wondering if you could shed some light on if Z should check if source1 and source2 are the same address in various arraycmp evaluator implementations. Is this something that could be explored and implemented in z for potential performance enhancement?

@joransiu

Copy link
Copy Markdown
Contributor

I'm wondering if you could shed some light on if Z should check if source1 and source2 are the same address in various arraycmp evaluator implementations. Is this something that could be explored and implemented in z for potential performance enhancement?

@a7ehuo : Thanks for highlighting this. I suspect we simply never considered this case, but agree if the two source operands are identical, we can short circuit the logic. Did you happen to observe this pattern as common in some workload?

@0xdaryl 0xdaryl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving x64/x86 code.

@0xdaryl

0xdaryl commented Mar 29, 2022

Copy link
Copy Markdown
Contributor

Jenkins build xlinux,win,osx,x32linux

@zl-wang

zl-wang commented Mar 29, 2022

Copy link
Copy Markdown
Contributor

@a7ehuo thanks for the reminder. i am also wondering how common this situation is in general workloads (e.g. dt7, acmeair, etc).

@a7ehuo

a7ehuo commented Mar 29, 2022

Copy link
Copy Markdown
Contributor Author

@joransiu @zl-wang I haven't observed this case (src1 == src2) in any existing workload. However we are exploring to use arraycmp to transform some of the value type acmp non-helper calls. In value type comparison, I think the case where src1 == src2 is not uncommon.

@vijaysun-omr

Copy link
Copy Markdown
Contributor

I feel there is a bit of a tradeoff here, i.e. we will slightly increase the path length for arraycmps where the two addresses are not equal in order to significantly decrease the path length for arraycmps where the two addresses are equal. The latter case may not be common enough for this to be a net win (others seem to be expressing similar thoughts).

@0xdaryl

0xdaryl commented Mar 29, 2022

Copy link
Copy Markdown
Contributor

In this particular case, just an extra branch is being added that piggybacks on an existing "test" (i.e, an explicit test for sameness is not being added to handle this case, just a branch). I believe that's an acceptable tradeoff. @vijaysun-omr : do you want more study done here?

@vijaysun-omr

vijaysun-omr commented Mar 29, 2022 •

Copy link
Copy Markdown
Contributor

I would probably defer to your experience here @0xdaryl but I don't know if a study is warranted. It may well be something that is decided more on the basis of our judgement, e.g. what would the various instruction pipelines do. If the extra instruction is effectively expected to be "hidden" in most cases by the pipeline, then we could go ahead. If not, we may still go ahead but it is less clear-cut.

@0xdaryl

0xdaryl commented Mar 29, 2022

Copy link
Copy Markdown
Contributor

I'm comfortable with the change on x64. A SUB and JE will macrofuse and dispatch in a single cycle.

@vijaysun-omr

Copy link
Copy Markdown
Contributor

Okay, then we can go ahead on X86. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants