Skip to content

Conversation

ishitaR88
Copy link

Before this fix the r+1 register was getting encoded by https://github.com/eclipse-omr/omr/blob/master/compiler/z/codegen/S390Instruction.cpp#L2144 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
Copy link
Contributor

@r30shah r30shah left a comment

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.

toRealRegister(getSecondRegister()->getHighOrder())->setRegister2Field((uint32_t *)cursor);
} else if (getLastRegister()) {
toRealRegister(getLastRegister())->setRegister2Field((uint32_t *)cursor);
if (op != TR::InstOpCode::SRDA ) {
Copy link
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
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

toRealRegister(getSecondRegister()->getHighOrder())->setRegister2Field((uint32_t *)cursor);
} else if (getLastRegister()) {
toRealRegister(getLastRegister())->setRegister2Field((uint32_t *)cursor);
if (op != TR::InstOpCode::SRDA ) {
Copy link
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
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
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
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
} else if (getLastRegister()) {
toRealRegister(getLastRegister())->setRegister2Field((uint32_t *)cursor);
} else if (!opCode.usesRegPairForTarget() && getLastRegister()) {
toRealRegister(getLastRegister())->setRegister2Field((uint32_t *)cursor);
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like an extra indentation here. Please fix this.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

toRealRegister(getSecondRegister()->getHighOrder())->setRegister2Field((uint32_t *)cursor);
} else if (getLastRegister()) {
toRealRegister(getLastRegister())->setRegister2Field((uint32_t *)cursor);
} else if (!opCode.usesRegPairForTarget() && getLastRegister()) {
Copy link
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.

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

Issue:eclipse-omr#5175
@ishitaR88 ishitaR88 marked this pull request as ready for review October 14, 2025 19:49
Copy link
Contributor

@r30shah r30shah left a comment

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.

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.

3 participants