[llvm] [SPIR-V] Fix crash on switch with odd-width condition type (PR #208026)
Arseniy Obolenskiy via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 8 01:38:37 PDT 2026
================
@@ -64,9 +64,14 @@ class SPIRVTargetLowering : public TargetLowering {
// the standard.
void finalizeLowering(MachineFunction &MF) const override;
+ // Return a width no larger than the condition so CodeGenPrepare never widens
+ // it. Odd-width integers are extended EVTs, so getSimpleVT would fail, so
+ // falling back to i1.
MVT getPreferredSwitchConditionType(LLVMContext &Context,
EVT ConditionVT) const override {
- return ConditionVT.getSimpleVT();
+ if (ConditionVT.isSimple())
+ return ConditionVT.getSimpleVT();
+ return MVT::i1;
----------------
aobolensk wrote:
> Why don't we always return `MVT::i1` then, since this would have made the cut for every case? Are there any regressions if we do that?
That will work, no regressions expected in this case. Shall we proceed with i1?
> What happens if we have the arbitrary precision integers extension?
They are orthogonal. This fix does not depend on that. i1 is applicable in any case
> What happens if there is an use of the condition by another instruction? Does the switch's condition type interfere on this case?
That will be ok. Added the corresponding test
https://github.com/llvm/llvm-project/pull/208026
More information about the llvm-commits
mailing list