Skip to content

RSInstructions encoding fix for IBM Z - #7965

Merged
hzongaro merged 1 commit into
eclipse-omr:masterfrom
ishitaR88:srda-bugfix
Nov 7, 2025
Merged

RSInstructions encoding fix for IBM Z#7965
hzongaro merged 1 commit into
eclipse-omr:masterfrom
ishitaR88:srda-bugfix

Conversation

@ishitaR88

@ishitaR88 ishitaR88 commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

Before this fix the r+1 register was getting encoded by uint8_t *TR::S390RSInstruction::generateBinaryEncoding() in ~/omr/compiler/z/codegen/S390Instruction.cpp as shown below, even though it is not actually a register SRDA instruction. For now this register encoding is ignored by hardware but it can cause an invalid instruction issue in future.
image
In this modification the encoding of r+1 register is skipped if the instruction is SRDA, r+1 register will be 0.

@ishitaR88
ishitaR88 marked this pull request as draft October 2, 2025 14:28

@r30shah r30shah 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.

Thanks @ishitaR88 - Couple of recommendations. This change fixes #5175 so please follow https://github.com/eclipse-omr/omr/blob/master/CONTRIBUTING.md#commit-guidelines for commit message and description guidelines.

Also this issue is not specific to z/OS only. It also applies to Linux on Z, commit title and PR title needs to be changed to IBM Z (Not z/OS). Also as we are updating this for other RSInstructions as well, update the title accordingly.

Comment thread compiler/z/codegen/S390Instruction.cpp Outdated
toRealRegister(getSecondRegister()->getHighOrder())->setRegister2Field((uint32_t *)cursor);
} else if (getLastRegister()) {
toRealRegister(getLastRegister())->setRegister2Field((uint32_t *)cursor);
if (op != TR::InstOpCode::SRDA ) {

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.

Thinking bit more about this, Can we use something like getOpCode().usesRegPairForTarget() to identify the instruction which uses register pair in which case we do not need to encode the lastRegister.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have added 3 more opcodes besides SRDA that do not need the odd register encoding

Comment thread compiler/z/codegen/S390Instruction.cpp Outdated
toRealRegister(getSecondRegister()->getHighOrder())->setRegister2Field((uint32_t *)cursor);
} else if (getLastRegister()) {
toRealRegister(getLastRegister())->setRegister2Field((uint32_t *)cursor);
if (op != TR::InstOpCode::SRDA ) {

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.

Can we use getOpCode().usesRegPairForTarget() to recognize cases where the instruction uses register pair for target (In which case we do not need to encode the lastRegister).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am investigating this part

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added getOpCode().usesRegPairForTarget() check. Please let me know if I need to modify anything else.

@ishitaR88
ishitaR88 force-pushed the srda-bugfix branch 3 times, most recently from aff3b9f to c8be5d5 Compare October 7, 2025 03:54
@ishitaR88

Copy link
Copy Markdown
Contributor Author

Thanks @ishitaR88 - Couple of recommendations. This change fixes #5175 so please follow https://github.com/eclipse-omr/omr/blob/master/CONTRIBUTING.md#commit-guidelines for commit message and description guidelines.
Also this issue is not specific to z/OS only. It also applies to Linux on Z, commit title and PR title needs to be changed to IBM Z (Not z/OS). Also as we are updating this for other RSInstructions as well, update the title accordingly.

Changed commit message as suggested. Please let me know if I should add anymore details.

@ishitaR88 ishitaR88 changed the title WIP:SRDA encoding fix for z/OS RSInstructions encoding fix for IBM Z Oct 8, 2025
Comment thread compiler/z/codegen/S390Instruction.cpp Outdated
toRealRegister(getSecondRegister()->getHighOrder())->setRegister2Field((uint32_t *)cursor);
} else if (getLastRegister()) {
toRealRegister(getLastRegister())->setRegister2Field((uint32_t *)cursor);
} else if (!opCode.usesRegPairForTarget() && getLastRegister()) {

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.

I think this should resolve the issue, but I would appreciate going through the list of instructions (That are not checked in condition before - which will use this code (RS*_FORMAT) and ensure this is fine.

Changes overall are good - Just a sanity check would confirm. I think you should remove PR from Draft to Ready once you address those two comments.

@ishitaR88
ishitaR88 marked this pull request as ready for review October 14, 2025 19:49

@r30shah r30shah 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.

@ishitaR88 - So encoding of the second register from the pair is incorrect. So make changes to commit message / body to reflect that.

Please take a look at the Instruction type that extends RSInstruction as well to ensure that those are fine.

@ishitaR88

Copy link
Copy Markdown
Contributor Author

@ishitaR88 - So encoding of the second register from the pair is incorrect. So make changes to commit message / body to reflect that.

Please take a look at the Instruction type that extends RSInstruction as well to ensure that those are fine.

Changed the commit message please let me know if it's alright.

@r30shah

r30shah commented Oct 29, 2025

Copy link
Copy Markdown
Contributor

Jenkins build zos,zlinux

@r30shah r30shah 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 the changes based on the last comment from Ishita confirming the verification. @joransiu Can I also request your review on this change ?

@hzongaro Can We request your review as well and merge the changes.

@joransiu joransiu 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.

LGTM

@hzongaro hzongaro self-assigned this Nov 4, 2025

@hzongaro hzongaro 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.

I think the change looks fine, but I wanted to point out one more issue with the commit message. According to https://github.com/eclipse-omr/omr/blob/master/CONTRIBUTING.md#commit-guidelines, the first line of commit messages should be written in the imperative mood. May I ask you to change "RSInstructions encoding fix for IBM Z" to something like "Fix encoding of RSInstructions for IBM Z"?

Also, the description of the fix contains a link to a particular line in compiler/z/codegen/S390Instruction.cpp on the master branch. However, those line numbers will change whenever someone makes changes to that file, making it difficult for anyone who looks at this pull request in the future to figure out which line it was referring to.

I would suggest either replacing that link with the name of the method that's involved, or using a link based on the most recent commit to OMR — i.e., https://github.com/eclipse-omr/omr/blob/0fba1d563edc52877796d12d1121f68cc2c265f7/compiler/z/codegen/S390Instruction.cpp#L2144

This commit fixes the encoding issue reported in eclipse-omr#5175 for RS
instructions on IBM Z. The second register of the register pair
was previously encoded irrespective of if it needed and it might
cause some unexpected behavior in future. This fix will skip
encoding the second register for the opcodes that do not use it.

Issue:eclipse-omr#5175
@ishitaR88

Copy link
Copy Markdown
Contributor Author

I think the change looks fine, but I wanted to point out one more issue with the commit message. According to https://github.com/eclipse-omr/omr/blob/master/CONTRIBUTING.md#commit-guidelines, the first line of commit messages should be written in the imperative mood. May I ask you to change "RSInstructions encoding fix for IBM Z" to something like "Fix encoding of RSInstructions for IBM Z"?

Changed the commit message as per your suggestion. Please let me know if I need to change anything else.

Also, the description of the fix contains a link to a particular line in compiler/z/codegen/S390Instruction.cpp on the master branch. However, those line numbers will change whenever someone makes changes to that file, making it difficult for anyone who looks at this pull request in the future to figure out which line it was referring to.

I would suggest either replacing that link with the name of the method that's involved, or using a link based on the most recent commit to OMR — i.e., https://github.com/eclipse-omr/omr/blob/0fba1d563edc52877796d12d1121f68cc2c265f7/compiler/z/codegen/S390Instruction.cpp#L2144

-- Added the function name and class path instead of using link.

@hzongaro hzongaro 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.

I think the changes look good. Thanks!

@hzongaro

hzongaro commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

Jenkins build all

@hzongaro

hzongaro commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

Test was successful and reviews approved. Merging.

@hzongaro
hzongaro merged commit a7b3261 into eclipse-omr:master Nov 7, 2025
14 checks passed
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