[llvm] [SPIR-V] Fix crash on switch with odd-width condition type (PR #208026)
Juan Manuel Martinez CaamaƱo via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 8 00:57:19 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;
----------------
jmmartinez wrote:
Few questions.
* 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?
* What happens if we have the arbitrary precision integers extension?
* What happens if there is an use of the condition by another instruction? Does the switch's condition type interfere on this case?
https://github.com/llvm/llvm-project/pull/208026
More information about the llvm-commits
mailing list