[llvm] 93cda6d - [SPIR-V] No OpBitcast is generated for a bitcast between identical types (#114877)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 5 02:26:02 PST 2024
Author: Vyacheslav Levytskyy
Date: 2024-11-05T11:25:58+01:00
New Revision: 93cda6d6a75e98d5516fbf12ce984604be834f01
URL: https://github.com/llvm/llvm-project/commit/93cda6d6a75e98d5516fbf12ce984604be834f01
DIFF: https://github.com/llvm/llvm-project/commit/93cda6d6a75e98d5516fbf12ce984604be834f01.diff
LOG: [SPIR-V] No OpBitcast is generated for a bitcast between identical types (#114877)
The goal of the PR is to ensure that no OpBitcast is generated for a
bitcast between identical types.
This PR resolves https://github.com/llvm/llvm-project/issues/114482
Added:
llvm/test/CodeGen/SPIRV/no-opbitcast-between-identical-types.ll
Modified:
llvm/lib/Target/SPIRV/SPIRVPreLegalizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/SPIRV/SPIRVPreLegalizer.cpp b/llvm/lib/Target/SPIRV/SPIRVPreLegalizer.cpp
index 790d86f191fd86..d5299043d9ef2f 100644
--- a/llvm/lib/Target/SPIRV/SPIRVPreLegalizer.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVPreLegalizer.cpp
@@ -175,10 +175,13 @@ static void buildOpBitcast(SPIRVGlobalRegistry *GR, MachineIRBuilder &MIB,
MachineRegisterInfo *MRI = MIB.getMRI();
if (!MRI->getRegClassOrNull(ResVReg))
MRI->setRegClass(ResVReg, GR->getRegClass(ResType));
- MIB.buildInstr(SPIRV::OpBitcast)
- .addDef(ResVReg)
- .addUse(GR->getSPIRVTypeID(ResType))
- .addUse(OpReg);
+ if (ResType == OpType)
+ MIB.buildInstr(TargetOpcode::COPY).addDef(ResVReg).addUse(OpReg);
+ else
+ MIB.buildInstr(SPIRV::OpBitcast)
+ .addDef(ResVReg)
+ .addUse(GR->getSPIRVTypeID(ResType))
+ .addUse(OpReg);
}
// We do instruction selections early instead of calling MIB.buildBitcast()
diff --git a/llvm/test/CodeGen/SPIRV/no-opbitcast-between-identical-types.ll b/llvm/test/CodeGen/SPIRV/no-opbitcast-between-identical-types.ll
new file mode 100644
index 00000000000000..9b19a32d38f751
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/no-opbitcast-between-identical-types.ll
@@ -0,0 +1,17 @@
+; The goal of the test case is to ensure that no OpBitcast is generated for a bitcast between identical types.
+
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; CHECK: OpFunction
+; CHECK-NO: OpBitcast
+; CHECK: OpReturn
+
+define void @foo() {
+entry:
+ %r = bitcast i32 0 to i32
+ ret void
+}
More information about the llvm-commits
mailing list