Skip to content

power_by_squaring is not inlined for x^2 #60639

@eschnett

Description

@eschnett

I am using Julia 1.12.4. It seems that @fastmath breaks efficient integer powers for Float32.

Simple code:

f(x) = @fastmath x^2

This is good (Float64):

julia> @code_llvm debuginfo=:none f(1.0)
; Function Signature: f(Float64)
define double @julia_f_3688(double %"x::Float64") #0 {
top:
  %0 = fmul double %"x::Float64", %"x::Float64"
  ret double %0
}

This is bad (Float32):

julia> @code_llvm debuginfo=:none f(1.0f0)
; Function Signature: f(Float32)
define float @julia_f_3715(float %"x::Float32") #0 {
top:
  %0 = fpext float %"x::Float32" to double
  %1 = call double @"j_#power_by_squaring#401_3717"(double %0, i64 signext 2)
  %2 = fptrunc double %1 to float
  ret float %2
}

Not only is power_by_squaring not inlined, it even converts to and from Float64!

See also #59804. I assume this fixed things for Float64 but not for Float32.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions