[SPIRV] Add PreLegalizer pattern matching for `step` GL extension
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
> Note: the `step` move deleted the SPIR-V intrinsic, so `Intrinsic::spv_step`, its `selectExtInst` lowering, and the SPIR-V `step.ll` test need to be restored first so the PreLegalizer combiner can emit the GL extension through the intrinsic.
Follow-up to #213098.
Following the `step` implementation move, SPIR-V now lowers `step` as a generic `fcmp`+`select` instead of the GL extension:
```asm
step(y, x) ->
cmpResult = fcmp olt x, y
select(cmpResult, 0.0, 1.0)
```
We can pattern match this in `SPIRVCombine.td` and `SPIRVCombinerHelper.cpp` to
```llvm
select(
fcmp(olt,
x,
y),
0.0,
1.0)
```
which would allow us to change `select(fcmp(olt, x, y), 0.0, 1.0)` back into `step(y, x)` so that SPIR-V emits the GL extension again.
Contributor guide
Research direction
Start by reviewing the deleted SPIR-V intrinsic, its selectExtInst lowering, and the SPIR-V step.ll test, which must be restored first. Then read SPIRVCombine.td and SPIRVCombinerHelper.cpp to trace the existing PreLegalizer patterns. Done means the fcmp/select form is recognized as step and the SPIR-V step test verifies emission through the GL extension.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 62/100