Skip to content

Fix errors from ordered comparisons in iselectEvaluator - #6815

Merged
0xdaryl merged 1 commit into
eclipse-omr:masterfrom
kevindean12:fix-iselectevaluator
Dec 8, 2022
Merged

0xdaryl merged 1 commit into
eclipse-omr:masterfrom
kevindean12:fix-iselectevaluator

Conversation

@kevindean12

Copy link
Copy Markdown
Contributor

In compareIntegersForOrder, check size of comparisons in the condition node of the iselect/lselect (the datatype of the condition is always int32, but it may be a comparison operation with operands of a different size - for example, a bcmpgt). Then emit the appropriate compare instruction for 1 and 2 byte compares in order to avoid issuing a 4-byte cmp for comparison operands smaller than 4 bytes, which potentially includes garbage in the upper part of the register in the comparison. Use unsigned cmovcc (cmova/cmovb vs cmovg/cmovl) instructions in iselectEvaluator when evaluating an unsigned comparison for the select condition.

FEATURES(0)),
INSTRUCTION(CMOVA4RegReg, cmova,
BINARY(VEX_L___, VEX_vNONE, PREFIX___, REX__, ESCAPE_0F__, 0x47, 0, ModRM_RM__, Immediate_0),
PROPERTY0(IA32OpProp_ModifiesTarget | IA32OpProp_SourceRegisterInModRM | IA32OpProp_IntSource | IA32OpProp_IntTarget | IA32OpProp_TestsCarryFlag | IA32OpProp_TestsZeroFlag),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@0xdaryl @kevindean12 Can we please review IA32OpProp properties more closely for the newly added X86Ops, especially - IA32OpProp_IntSource and IA32OpProp_IntTarget ?

}
else if (compareSize == 2)
{
//shouldn't use Imm2 instructions

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 you explain this comment?

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'm following an approach taken in similar circumstances in compareIntegersForEquality() where 2-byte immediates are avoided in favor of using the MemReg form instead, which as I understand is due to the fact that using 16-bit immediate operands can result in slower instruction decoding because of the need for an operand-size prefix in the encoding to specify the 2-byte size.

@0xdaryl 0xdaryl self-assigned this Nov 29, 2022
@0xdaryl

0xdaryl commented Dec 7, 2022

Copy link
Copy Markdown
Contributor

Would you mind rebasing this PR please so I can conduct some tests with OpenJ9?

-Check size of comparison and emit appropriate compare instruction
for 1 and 2 byte compares in compareIntegersForOrder
-Use unsigned cmovcc instructions in iselectEvaluator when evaluating
an unsigned comparison for the select condition
@kevindean12

Copy link
Copy Markdown
Contributor Author

Rebased!

@0xdaryl

0xdaryl commented Dec 8, 2022

Copy link
Copy Markdown
Contributor

Downstream testing is successful. Merging.

@0xdaryl
0xdaryl merged commit 8ae3140 into eclipse-omr:master Dec 8, 2022
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