From 73eb8378422db4f5ddf69d511ddb9a1e54e15b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Fri, 10 Aug 2018 05:43:44 -0700 Subject: [PATCH] Bug 1481247: Don't compare pointers twice in MacroAssembler::compareStrings. r=tcampbell --- js/src/jit/MacroAssembler.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/js/src/jit/MacroAssembler.cpp b/js/src/jit/MacroAssembler.cpp index d09e88d97ea1..ce0e6c82d7e2 100644 --- a/js/src/jit/MacroAssembler.cpp +++ b/js/src/jit/MacroAssembler.cpp @@ -1429,26 +1429,28 @@ MacroAssembler::compareStrings(JSOp op, Register left, Register right, Register Label done; Label notPointerEqual; - // Fast path for identical strings. + // If operands point to the same instance, the strings are trivially equal. branchPtr(Assembler::NotEqual, left, right, ¬PointerEqual); move32(Imm32(op == JSOP_EQ || op == JSOP_STRICTEQ), result); jump(&done); bind(¬PointerEqual); - Label notAtom; - // Optimize the equality operation to a pointer compare for two atoms. + Label leftIsNotAtom; + Label setNotEqualResult; + // Atoms cannot be equal to each other if they point to different strings. Imm32 nonAtomBit(JSString::NON_ATOM_BIT); - branchTest32(Assembler::NonZero, Address(left, JSString::offsetOfFlags()), nonAtomBit, ¬Atom); - branchTest32(Assembler::NonZero, Address(right, JSString::offsetOfFlags()), nonAtomBit, ¬Atom); + branchTest32(Assembler::NonZero, Address(left, JSString::offsetOfFlags()), nonAtomBit, + &leftIsNotAtom); + branchTest32(Assembler::Zero, Address(right, JSString::offsetOfFlags()), nonAtomBit, + &setNotEqualResult); - cmpPtrSet(JSOpToCondition(MCompare::Compare_String, op), left, right, result); - jump(&done); - - bind(¬Atom); + bind(&leftIsNotAtom); // Strings of different length can never be equal. loadStringLength(left, result); branch32(Assembler::Equal, Address(right, JSString::offsetOfLength()), result, fail); + + bind(&setNotEqualResult); move32(Imm32(op == JSOP_NE || op == JSOP_STRICTNE), result); bind(&done);