Skip to content

Commit ca63860

Browse files
[SPIR-V] Don't change switch condition type in CodeGen opts (#94959)
This change makes sure the preferred switch condition int type size remains the same throughout CodeGen optimizations. The change fixes running several OpenCL applications with -O2 or higher opt levels, and fixes Basic/stream/stream_max_stmt_exceed.cpp DPC++ E2E test with -O2.
1 parent 9b4f8ac commit ca63860

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

llvm/lib/Target/SPIRV/SPIRVISelLowering.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ class SPIRVTargetLowering : public TargetLowering {
6868
// extra instructions required to preserve validity of SPIR-V code imposed by
6969
// the standard.
7070
void finalizeLowering(MachineFunction &MF) const override;
71+
72+
MVT getPreferredSwitchConditionType(LLVMContext &Context,
73+
EVT ConditionVT) const override {
74+
return ConditionVT.getSimpleVT();
75+
}
7176
};
7277
} // namespace llvm
7378

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: llc -O2 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O2 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
; CHECK: %[[#INT16:]] = OpTypeInt 16 0
5+
; CHECK: %[[#PARAM:]] = OpFunctionParameter %[[#INT16]]
6+
; CHECK: OpSwitch %[[#PARAM]] %[[#]] 1 %[[#]] 2 %[[#]]
7+
8+
define i32 @test_switch(i16 %cond) {
9+
entry:
10+
switch i16 %cond, label %default [ i16 1, label %case_one
11+
i16 2, label %case_two ]
12+
case_one:
13+
ret i32 1
14+
case_two:
15+
ret i32 2
16+
default:
17+
ret i32 3
18+
}

0 commit comments

Comments
 (0)