Skip to content

Compile constant SIMD initialiser to a constant vector expression  #18147

Closed
@huonw

Description

@huonw

Currently

#![crate_type = "lib"]

pub fn foo(x: f64, y:f64) -> std::simd::f64x2 {
    std::simd::f64x2(0.0, 1.0)
}

becomes, with no optimisations,

; Function Attrs: uwtable
define <2 x double> @_ZN3foo20h36a71d373a6347d3daaE(double, double) unnamed_addr #0 {
entry-block:
  %sret_slot = alloca <2 x double>
  %x = alloca double
  %y = alloca double
  store double %0, double* %x
  store double %1, double* %y
  %2 = getelementptr inbounds <2 x double>* %sret_slot, i32 0, i32 0
  store double 0.000000e+00, double* %2
  %3 = getelementptr inbounds <2 x double>* %sret_slot, i32 0, i32 1
  store double 1.000000e+00, double* %3
  %4 = load <2 x double>* %sret_slot
  ret <2 x double> %4
}

After optimisations it becomes

; Function Attrs: nounwind readnone uwtable
define <2 x double> @_ZN3foo20h36a71d373a6347d3daaE(double, double) unnamed_addr #0 {
entry-block:
  ret <2 x double> <double 0.000000e+00, double 1.000000e+00>
}

We could detect constants in a SIMD initialiser and compile to this directly, making our no-opt code faster, and saving the optimiser work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-SIMDArea: SIMD (Single Instruction Multiple Data)A-codegenArea: Code generationC-enhancementCategory: An issue proposing an enhancement or a PR with one.I-compiletimeIssue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions