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:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.