KhronosGroup / KhronosGroup/SPIRV-Tools

spirv-opt should be able to optimise two consecutive 'OpVectorTimesScalar's into an 'OpFMul' and a single 'OpVectorTimesScalar'

Open
#4,076 0 comments 0 reactions 0 assignees View on GitHub
component:optimization
Dominant language
C++
Stars
1.4k
Forks
709
Avg merge
1d 22h
Merged PRs (30d)
28

Description

At the moment, `vec4 * float * float` in glsl compiled via `glslc` becomes:

```spir-v
%12 = OpLoad %v4float %a
%15 = OpLoad %float %b
%16 = OpVectorTimesScalar %v4float %12 %15
%18 = OpLoad %float %c
%19 = OpVectorTimesScalar %v4float %16 %18
```
While `vec4 * (float * float)` becomes:
```
%12 = OpLoad %v4float %a
%15 = OpLoad %float %b
%17 = OpLoad %float %c
%18 = OpFMul %float %15 %17
%19 = OpVectorTimesScalar %v4float %12 %18
```
I'd like `spirv-opt` to be able to do this optimisation for me. Has this been discussed before? Are there any problems with accuracy that could arise from this?

Contributor guide

Open the contributing guide

Research direction

Start with the issue's SPIR-V examples and the spirv-opt entry point, then review how existing optimization passes handle consecutive OpVectorTimesScalar instructions. Determine whether combining the scalar operands preserves the required accuracy, and define completion as a pass that produces the requested OpFMul plus single OpVectorTimesScalar form with coverage for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.