Skip to content

DARWIN/ARM64: Bad codegen for sign extend #39823

Closed

Description

julia> function f(n)
       (n_positive, neg) = Base.split_sign(n); ccall(:jl_breakpoint, Cvoid, ())
       Base.dec(n_positive, 1, neg)
       end

LLVM IR:

;  @ REPL[9]:2 within `f'
; ┌ @ intfuncs.jl:743 within `split_sign'
; │┌ @ int.jl:172 within `abs'
; ││┌ @ int.jl:132 within `flipsign'
     %7 = ashr i32 %0, 31
     %8 = add i32 %0, %7
     %9 = xor i32 %8, %7
; │└└
; │┌ @ promotion.jl:360 within `<'
; ││┌ @ promotion.jl:291 within `promote'
; │││┌ @ promotion.jl:268 within `_promote'
; ││││┌ @ number.jl:7 within `convert'
; │││││┌ @ boot.jl:757 within `Int64'
; ││││││┌ @ boot.jl:676 within `toInt64'
         %10 = sext i32 %0 to i64

Assembly:

; │┌ @ intfuncs.jl:743 within `split_sign'
; ││┌ @ int.jl:172 within `abs'
; │││┌ @ int.jl:132 within `flipsign'
	asr	w10, w9, #31
	add	w11, w9, w10
	eor	w0, w11, w10
; ││└└
; ││┌ @ promotion.jl:360 within `<'
; │││┌ @ promotion.jl:291 within `promote'
; ││││┌ @ promotion.jl:268 within `_promote'
; │││││┌ @ number.jl:7 within `convert'
; ││││││┌ @ boot.jl:757 within `Int64'
; │││││││┌ @ boot.jl:676 within `toInt64'
	mov	x8, x9
; │││└└└└└
; │││ @ promotion.jl:360 within `<' @ int.jl:83
	cmp	x8, #0                          ; =0
	cset	w10, lt

w9 is not sign extended in the x9 register

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    system:apple siliconAffects Apple Silicon only (Darwin/ARM64) - e.g. M1 and other M-series chipssystem:macAffects only macOS

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions