[all-commits] [llvm/llvm-project] 0cce78: [SPIR-V] Lower `select` instructions with aggregat...
Tim Besard via All-commits
all-commits at lists.llvm.org
Thu Jun 11 02:50:26 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 0cce78251f4c534b0d0a5ad55dd470e101ea9b94
https://github.com/llvm/llvm-project/commit/0cce78251f4c534b0d0a5ad55dd470e101ea9b94
Author: Tim Besard <tim.besard at gmail.com>
Date: 2026-06-11 (Thu, 11 Jun 2026)
Changed paths:
M llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
A llvm/test/CodeGen/SPIRV/select-aggregate.ll
A llvm/test/CodeGen/SPIRV/select-composite-constant.ll
Log Message:
-----------
[SPIR-V] Lower `select` instructions with aggregate operands (#201417)
Context: `SPIRVEmitIntrinsics` represents aggregate (array/struct) SSA
values as i32 value-ids, keeping the real type on the side for SPIR-V
emission. `preprocessCompositeConstants()` rewrites composite constant
operands into those value-ids.
A `select` takes its result type from its operands, so rewriting one arm
leaves the select with an aggregate result type but an i32 operand,
which is invalid. The exact failure mode depends: a composite-constant
arm tripped the verifier ("Select values must have same type as select
instruction"), while a non-constant arm (say a load) only became a
value-id later, in the visitor pass, at which point
`replaceMemInstrUses()` found a `select` among its users and hit an
unreachable.
I pushed two commits fixing this, one limited to my use case, another
more general:
1. Constant arms only. The common case is a select between two composite
constants, such as two complex literals. Once both arms are value-ids,
mutate the select to i32 and record its real type in `AggrConstTypes`;
the existing visitor turns its `extractvalue` users into `spv_extractv`.
2. An arm can also be a load or `insertvalue` result, which only becomes
a value-id later, in the visitor pass. By then the select has already
been mutated to i32, so its operand has to be reconciled when the arm is
lowered. This commit makes `select` behave like `PHINode` (which already
handles this): mutate every aggregate select to i32 up front, and handle
`SelectInst` in `replaceMemInstrUses()` so the operand and its
`extractvalue` users get fixed up as each arm is lowered. Nested
aggregate selects fall out of the same up-front mutation.
Developed with the help of Claude 4.8.
Closes https://github.com/llvm/llvm-project/issues/151344
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply at anthropic.com>
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list