Skip to content

Commit 93cda6d

Browse files
[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 #114482
1 parent 5dc9c39 commit 93cda6d

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

llvm/lib/Target/SPIRV/SPIRVPreLegalizer.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,13 @@ static void buildOpBitcast(SPIRVGlobalRegistry *GR, MachineIRBuilder &MIB,
175175
MachineRegisterInfo *MRI = MIB.getMRI();
176176
if (!MRI->getRegClassOrNull(ResVReg))
177177
MRI->setRegClass(ResVReg, GR->getRegClass(ResType));
178-
MIB.buildInstr(SPIRV::OpBitcast)
179-
.addDef(ResVReg)
180-
.addUse(GR->getSPIRVTypeID(ResType))
181-
.addUse(OpReg);
178+
if (ResType == OpType)
179+
MIB.buildInstr(TargetOpcode::COPY).addDef(ResVReg).addUse(OpReg);
180+
else
181+
MIB.buildInstr(SPIRV::OpBitcast)
182+
.addDef(ResVReg)
183+
.addUse(GR->getSPIRVTypeID(ResType))
184+
.addUse(OpReg);
182185
}
183186

184187
// We do instruction selections early instead of calling MIB.buildBitcast()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; The goal of the test case is to ensure that no OpBitcast is generated for a bitcast between identical types.
2+
3+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
4+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}
5+
6+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
7+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
8+
9+
; CHECK: OpFunction
10+
; CHECK-NO: OpBitcast
11+
; CHECK: OpReturn
12+
13+
define void @foo() {
14+
entry:
15+
%r = bitcast i32 0 to i32
16+
ret void
17+
}

0 commit comments

Comments
 (0)