[llvm] ca63860 - [SPIR-V] Don't change switch condition type in CodeGen opts (#94959)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 11 11:09:24 PDT 2024
Author: Michal Paszkowski
Date: 2024-06-11T11:09:21-07:00
New Revision: ca6386073308d3c41647d8fc3e2cf72a77d46c76
URL: https://github.com/llvm/llvm-project/commit/ca6386073308d3c41647d8fc3e2cf72a77d46c76
DIFF: https://github.com/llvm/llvm-project/commit/ca6386073308d3c41647d8fc3e2cf72a77d46c76.diff
LOG: [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.
Added:
llvm/test/CodeGen/SPIRV/optimizations/switch-condition-type.ll
Modified:
llvm/lib/Target/SPIRV/SPIRVISelLowering.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/SPIRV/SPIRVISelLowering.h b/llvm/lib/Target/SPIRV/SPIRVISelLowering.h
index 6fc200abf4627..77356b7512a73 100644
--- a/llvm/lib/Target/SPIRV/SPIRVISelLowering.h
+++ b/llvm/lib/Target/SPIRV/SPIRVISelLowering.h
@@ -68,6 +68,11 @@ class SPIRVTargetLowering : public TargetLowering {
// extra instructions required to preserve validity of SPIR-V code imposed by
// the standard.
void finalizeLowering(MachineFunction &MF) const override;
+
+ MVT getPreferredSwitchConditionType(LLVMContext &Context,
+ EVT ConditionVT) const override {
+ return ConditionVT.getSimpleVT();
+ }
};
} // namespace llvm
diff --git a/llvm/test/CodeGen/SPIRV/optimizations/switch-condition-type.ll b/llvm/test/CodeGen/SPIRV/optimizations/switch-condition-type.ll
new file mode 100644
index 0000000000000..054520d2021b9
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/optimizations/switch-condition-type.ll
@@ -0,0 +1,18 @@
+; RUN: llc -O2 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O2 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; CHECK: %[[#INT16:]] = OpTypeInt 16 0
+; CHECK: %[[#PARAM:]] = OpFunctionParameter %[[#INT16]]
+; CHECK: OpSwitch %[[#PARAM]] %[[#]] 1 %[[#]] 2 %[[#]]
+
+define i32 @test_switch(i16 %cond) {
+entry:
+ switch i16 %cond, label %default [ i16 1, label %case_one
+ i16 2, label %case_two ]
+case_one:
+ ret i32 1
+case_two:
+ ret i32 2
+default:
+ ret i32 3
+}
More information about the llvm-commits
mailing list