From de9f998062ba072c2d199d4c87bea364ab3b640e Mon Sep 17 00:00:00 2001 From: Daisuke Yamazaki Date: Sat, 4 Jul 2026 05:19:05 +0900 Subject: [PATCH] 8386861: [lworld] emit_opSubstitutabilityCheck speedup --- .../cpu/aarch64/c1_LIRAssembler_aarch64.cpp | 8 ++++++-- src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp | 16 ++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp b/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp index 93a7f2a9733..e2e72101027 100644 --- a/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp @@ -1587,8 +1587,12 @@ void LIR_Assembler::emit_opSubstitutabilityCheck(LIR_OpSubstitutabilityCheck* op Register left = op->left()->as_register(); Register right = op->right()->as_register(); - __ cmp(left, right); - __ br(Assembler::EQ, L_oops_equal); + if (left == right) { + __ b(L_oops_equal); + } else { + __ cmp(left, right); + __ br(Assembler::EQ, L_oops_equal); + } // (1) Null check -- if one of the operands is null, the other must not be null (because // the two references are not equal), so they are not substitutable, diff --git a/src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp b/src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp index 9e89bbed6fb..42de2b234da 100644 --- a/src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp +++ b/src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp @@ -1595,8 +1595,12 @@ void LIR_Assembler::emit_opSubstitutabilityCheck(LIR_OpSubstitutabilityCheck* op Register left = op->left()->as_register(); Register right = op->right()->as_register(); - __ cmpptr(left, right); - __ jcc(Assembler::equal, L_oops_equal); + if (left == right) { + __ jmp(L_oops_equal); + } else { + __ cmpptr(left, right); + __ jcc(Assembler::equal, L_oops_equal); + } // (1) Null check -- if one of the operands is null, the other must not be null (because // the two references are not equal), so they are not substitutable, @@ -1628,12 +1632,8 @@ void LIR_Assembler::emit_opSubstitutabilityCheck(LIR_OpSubstitutabilityCheck* op } else { Register tmp1 = op->tmp1()->as_register(); Register tmp2 = op->tmp2()->as_register(); - if (left == right) { // same operand, so clearly the same klasses, let's save the check - __ jmp (*op->stub()->entry()); // -> do slow check - } else { - __ cmp_klasses_from_objects(left, right, tmp1, tmp2); - __ jcc(Assembler::equal, *op->stub()->entry()); // same klass -> do slow check - } + __ cmp_klasses_from_objects(left, right, tmp1, tmp2); + __ jcc(Assembler::equal, *op->stub()->entry()); // same klass -> do slow check // fall through to L_oops_not_equal }