Ignore:
Timestamp:
Jan 21, 2019, 12:50:59 PM (6 years ago)
Author:
[email protected]
Message:

[JSC] sub op with 0 should be optimized
https://bugs.webkit.org/show_bug.cgi?id=190751

Reviewed by Mark Lam.

LLInt sometimes emit subp 0, %rxx. For example, maxFrameExtentForSlowPathCall is 0 in X86_64, ARM64, and ARM64E.
So subp maxFrameExtentForSlowPathCall sp becomes subp 0, %rsp. While addp 0, %rsp is removed in offlineasm,
sub operation does not have such an optimization. This patch applies the same optimization to sub operation already
done in add operation. Since the CPU flags changed in offlineasm's these operations are not considered (if these flags
are required, we use special branch operations instead), this optimization is sane.

One problem is that zero-extension of the 32bit register in 64bit architecture. If the instruction emission is skipped,
this won't be happen. Currently, we align our sub to add operation: we skip emission in this case.

  • offlineasm/arm64.rb:
  • offlineasm/x86.rb:
Location:
trunk/Source/JavaScriptCore/offlineasm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/offlineasm/arm64.rb

    r237627 r240241  
    461461       
    462462        if operands[0].immediate?
    463             if operands[0].value == 0 and flag !~ /s$/
    464                 unless operands[1] == operands[2]
     463            if operands[0].value == 0 and opcode !~ /s$/
     464                if operands[1] != operands[2]
    465465                    $asm.puts "mov #{arm64FlippedOperands(operands[1..2], kind)}"
    466466                end
     
    495495
    496496    $asm.puts "madd #{arm64TACOperands(operands, kind)}, #{arm64GPRName('xzr', kind)}"
     497end
     498
     499def emitARM64Sub(opcode, operands, kind)
     500    if operands.size == 3
     501        raise unless operands[0].register?
     502        raise unless operands[2].register?
     503
     504        if operands[1].immediate?
     505            if operands[1].value == 0 and opcode !~ /s$/
     506                if operands[0] != operands[2]
     507                    $asm.puts "mov #{arm64FlippedOperands([operands[0], operands[2]], kind)}"
     508                end
     509                return
     510            end
     511        end
     512    end
     513
     514    if operands.size == 2
     515        if operands[0].immediate? and operands[0].value == 0 and opcode !~ /s$/
     516            return
     517        end
     518    end
     519
     520    emitARM64TAC(opcode, operands, kind)
    497521end
    498522
     
    656680            emitARM64Mul('mul', operands, :quad)
    657681        when "subi"
    658             emitARM64TAC("sub", operands, :word)
     682            emitARM64Sub("sub", operands, :word)
    659683        when "subp"
    660             emitARM64TAC("sub", operands, :ptr)
     684            emitARM64Sub("sub", operands, :ptr)
    661685        when "subq"
    662             emitARM64TAC("sub", operands, :quad)
     686            emitARM64Sub("sub", operands, :quad)
    663687        when "subis"
    664             emitARM64TAC("subs", operands, :word)
     688            emitARM64Sub("subs", operands, :word)
    665689        when "negi"
    666690            $asm.puts "sub #{operands[0].arm64Operand(:word)}, wzr, #{operands[0].arm64Operand(:word)}"
  • trunk/Source/JavaScriptCore/offlineasm/x86.rb

    r237627 r240241  
    762762            raise unless operands[2].is_a? RegisterID
    763763            if operands[0].value == 0
    764                 unless operands[1] == operands[2]
     764                if operands[1] != operands[2]
    765765                    $asm.puts "mov#{x86Suffix(kind)} #{orderOperands(operands[1].x86Operand(kind), operands[2].x86Operand(kind))}"
    766766                end
     
    788788   
    789789    def handleX86Sub(kind)
    790         if operands.size == 3 and operands[1] == operands[2]
    791             $asm.puts "neg#{x86Suffix(kind)} #{operands[2].x86Operand(kind)}"
    792             $asm.puts "add#{x86Suffix(kind)} #{orderOperands(operands[0].x86Operand(kind), operands[2].x86Operand(kind))}"
    793         else
    794             handleX86Op("sub#{x86Suffix(kind)}", kind)
    795         end
     790        if operands.size == 3
     791            if Immediate.new(nil, 0) == operands[1]
     792                raise unless operands[0].is_a? RegisterID
     793                raise unless operands[2].is_a? RegisterID
     794                if operands[0] != operands[2]
     795                    $asm.puts "mov#{x86Suffix(kind)} #{orderOperands(operands[0].x86Operand(kind), operands[2].x86Operand(kind))}"
     796                end
     797                return
     798            end
     799            if operands[1] == operands[2]
     800                $asm.puts "neg#{x86Suffix(kind)} #{operands[2].x86Operand(kind)}"
     801                if Immediate.new(nil, 0) != operands[0]
     802                    $asm.puts "add#{x86Suffix(kind)} #{orderOperands(operands[0].x86Operand(kind), operands[2].x86Operand(kind))}"
     803                end
     804                return
     805            end
     806        end
     807
     808        if operands.size == 2
     809            if Immediate.new(nil, 0) == operands[0]
     810                return
     811            end
     812        end
     813
     814        handleX86Op("sub#{x86Suffix(kind)}", kind)
    796815    end
    797816   
Note: See TracChangeset for help on using the changeset viewer.