Skip to content

Conversation

@michalpaszkowski
Copy link
Member

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.

This change makes sure the preferresd 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.
@llvmbot
Copy link
Member

llvmbot commented Jun 10, 2024

@llvm/pr-subscribers-backend-spir-v

Author: Michal Paszkowski (michalpaszkowski)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/94959.diff

2 Files Affected:

  • (modified) llvm/lib/Target/SPIRV/SPIRVISelLowering.h (+5)
  • (added) llvm/test/CodeGen/SPIRV/optimizations/switch-condition-type.ll (+18)
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 +} 
@michalpaszkowski michalpaszkowski merged commit ca63860 into llvm:main Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants