Skip to content

Commit b45aef2

Browse files
fix test cases
1 parent 3edba95 commit b45aef2

File tree

5 files changed

+40
-36
lines changed

5 files changed

+40
-36
lines changed

llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,20 +1815,23 @@ static bool generateImageSizeQueryInst(const SPIRV::IncomingCall *Call,
18151815
// Query result may either be a vector or a scalar. If return type is not a
18161816
// vector, expect only a single size component. Otherwise get the number of
18171817
// expected components.
1818-
SPIRVType *RetTy = Call->ReturnType;
1819-
unsigned NumExpectedRetComponents = RetTy->getOpcode() == SPIRV::OpTypeVector
1820-
? RetTy->getOperand(2).getImm()
1821-
: 1;
1818+
unsigned NumExpectedRetComponents =
1819+
Call->ReturnType->getOpcode() == SPIRV::OpTypeVector
1820+
? Call->ReturnType->getOperand(2).getImm()
1821+
: 1;
18221822
// Get the actual number of query result/size components.
18231823
SPIRVType *ImgType = GR->getSPIRVTypeForVReg(Call->Arguments[0]);
18241824
unsigned NumActualRetComponents = getNumSizeComponents(ImgType);
18251825
Register QueryResult = Call->ReturnRegister;
18261826
SPIRVType *QueryResultType = Call->ReturnType;
18271827
if (NumExpectedRetComponents != NumActualRetComponents) {
1828+
unsigned Bitwidth = Call->ReturnType->getOpcode() == SPIRV::OpTypeInt
1829+
? Call->ReturnType->getOperand(1).getImm()
1830+
: 32;
18281831
QueryResult = MIRBuilder.getMRI()->createGenericVirtualRegister(
1829-
LLT::fixed_vector(NumActualRetComponents, 32));
1832+
LLT::fixed_vector(NumActualRetComponents, Bitwidth));
18301833
MIRBuilder.getMRI()->setRegClass(QueryResult, &SPIRV::vIDRegClass);
1831-
SPIRVType *IntTy = GR->getOrCreateSPIRVIntegerType(32, MIRBuilder);
1834+
SPIRVType *IntTy = GR->getOrCreateSPIRVIntegerType(Bitwidth, MIRBuilder);
18321835
QueryResultType = GR->getOrCreateSPIRVVectorType(
18331836
IntTy, NumActualRetComponents, MIRBuilder, true);
18341837
GR->assignSPIRVTypeToVReg(QueryResultType, QueryResult, MIRBuilder.getMF());

llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -645,18 +645,20 @@ SPIRVGlobalRegistry::buildConstantSampler(Register ResReg, unsigned AddrMode,
645645
ResReg.isValid()
646646
? ResReg
647647
: MIRBuilder.getMRI()->createVirtualRegister(&SPIRV::iIDRegClass);
648-
const MachineInstr *NewMI =
649-
createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
650-
return MIRBuilder.buildInstr(SPIRV::OpConstantSampler)
651-
.addDef(Sampler)
652-
.addUse(getSPIRVTypeID(getOrCreateOpTypeSampler(MIRBuilder)))
653-
.addImm(AddrMode)
654-
.addImm(Param)
655-
.addImm(FilerMode);
656-
});
657-
// TODO: this is a constant and it needs a usual control flow of add()/find()
658-
// as other constants
659-
return NewMI->getOperand(0).getReg();
648+
SPIRVType *TypeSampler = getOrCreateOpTypeSampler(MIRBuilder);
649+
Register TypeSamplerReg = getSPIRVTypeID(TypeSampler);
650+
// We cannot use createOpType() logic here, because of the
651+
// GlobalISel/IRTranslator.cpp check for a tail call that expects that
652+
// MIRBuilder.getInsertPt() has a previous instruction. If this constant is
653+
// inserted as a result of "__translate_sampler_initializer()" this would
654+
// break this IRTranslator assumption.
655+
MIRBuilder.buildInstr(SPIRV::OpConstantSampler)
656+
.addDef(Sampler)
657+
.addUse(TypeSamplerReg)
658+
.addImm(AddrMode)
659+
.addImm(Param)
660+
.addImm(FilerMode);
661+
return Sampler;
660662
}
661663

662664
Register SPIRVGlobalRegistry::buildGlobalVariable(

llvm/lib/Target/SPIRV/SPIRVPreLegalizer.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ static void insertBitcasts(MachineFunction &MF, SPIRVGlobalRegistry *GR,
268268
ToErase.push_back(AssignMI);
269269
MRI->replaceRegWith(Def, Source);
270270
} else {
271-
GR->assignSPIRVTypeToVReg(AssignedPtrType, Def, MF);
271+
if (!GR->getSPIRVTypeForVReg(Def, &MF))
272+
GR->assignSPIRVTypeToVReg(AssignedPtrType, Def, MF);
272273
MIB.buildBitcast(Def, Source);
273274
}
274275
}
@@ -442,13 +443,11 @@ void insertAssignInstr(Register Reg, Type *Ty, SPIRVType *SpvType,
442443

443444
if (!isTypeFoldingSupported(Def->getOpcode())) {
444445
// No need to generate SPIRV::ASSIGN_TYPE pseudo-instruction
445-
if (!GR->getSPIRVTypeForVReg(Reg, &MRI.getMF())) {
446-
if (!MRI.getRegClassOrNull(Reg))
447-
MRI.setRegClass(Reg, GR->getRegClass(SpvType));
448-
if (!MRI.getType(Reg).isValid())
449-
MRI.setType(Reg, GR->getRegType(SpvType));
450-
GR->assignSPIRVTypeToVReg(SpvType, Reg, MIB.getMF());
451-
}
446+
if (!MRI.getRegClassOrNull(Reg))
447+
MRI.setRegClass(Reg, GR->getRegClass(SpvType));
448+
if (!MRI.getType(Reg).isValid())
449+
MRI.setType(Reg, GR->getRegType(SpvType));
450+
GR->assignSPIRVTypeToVReg(SpvType, Reg, MIB.getMF());
452451
return;
453452
}
454453

llvm/test/CodeGen/SPIRV/keep-tracked-const.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
44
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
55

6-
; CHECK-SPIRV-DAG: %[[#Int:]] = OpTypeInt 32 0
6+
; CHECK-SPIRV-DAG: %[[#Int:]] = OpTypeInt 8 0
77
; CHECK-SPIRV-DAG: %[[#C0:]] = OpConstantNull %[[#Int]]
88
; CHECK-SPIRV-DAG: %[[#C1:]] = OpConstant %[[#Int]] 1{{$}}
99

llvm/test/CodeGen/SPIRV/transcoding/OpenCL/barrier.ll

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
;; barrier(flags);
2626
;; }
2727

28-
; CHECK-SPIRV: OpName %[[#TEST_CONST_FLAGS:]] "test_barrier_const_flags"
29-
; CHECK-SPIRV: %[[#UINT:]] = OpTypeInt 32 0
28+
; CHECK-SPIRV-DAG: OpName %[[#TEST_CONST_FLAGS:]] "test_barrier_const_flags"
29+
; CHECK-SPIRV-DAG: %[[#UINT:]] = OpTypeInt 32 0
3030

3131
;; In SPIR-V, barrier is represented as OpControlBarrier [3] and OpenCL
3232
;; cl_mem_fence_flags are represented as part of Memory Semantics [2], which
@@ -35,19 +35,19 @@
3535
;; bit more information than original source
3636

3737
;; 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory
38-
; CHECK-SPIRV: %[[#LOCAL:]] = OpConstant %[[#UINT]] 272
38+
; CHECK-SPIRV-DAG: %[[#LOCAL:]] = OpConstant %[[#UINT]] 272{{$}}
3939
;; 0x2 Workgroup
40-
; CHECK-SPIRV: %[[#WG:]] = OpConstant %[[#UINT]] 2
40+
; CHECK-SPIRV-DAG: %[[#WG:]] = OpConstant %[[#UINT]] 2{{$}}
4141
;; 0x10 SequentiallyConsistent + 0x200 CrossWorkgroupMemory
42-
; CHECK-SPIRV-DAG: %[[#GLOBAL:]] = OpConstant %[[#UINT]] 528
42+
; CHECK-SPIRV-DAG: %[[#GLOBAL:]] = OpConstant %[[#UINT]] 528{{$}}
4343
;; 0x10 SequentiallyConsistent + 0x800 ImageMemory
44-
; CHECK-SPIRV-DAG: %[[#IMAGE:]] = OpConstant %[[#UINT]] 2064
44+
; CHECK-SPIRV-DAG: %[[#IMAGE:]] = OpConstant %[[#UINT]] 2064{{$}}
4545
;; 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory + 0x200 CrossWorkgroupMemory
46-
; CHECK-SPIRV-DAG: %[[#LOCAL_GLOBAL:]] = OpConstant %[[#UINT]] 784
46+
; CHECK-SPIRV-DAG: %[[#LOCAL_GLOBAL:]] = OpConstant %[[#UINT]] 784{{$}}
4747
;; 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory + 0x800 ImageMemory
48-
; CHECK-SPIRV-DAG: %[[#LOCAL_IMAGE:]] = OpConstant %[[#UINT]] 2320
48+
; CHECK-SPIRV-DAG: %[[#LOCAL_IMAGE:]] = OpConstant %[[#UINT]] 2320{{$}}
4949
;; 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory + 0x200 CrossWorkgroupMemory + 0x800 ImageMemory
50-
; CHECK-SPIRV-DAG: %[[#LOCAL_GLOBAL_IMAGE:]] = OpConstant %[[#UINT]] 2832
50+
; CHECK-SPIRV-DAG: %[[#LOCAL_GLOBAL_IMAGE:]] = OpConstant %[[#UINT]] 2832{{$}}
5151

5252
; CHECK-SPIRV: %[[#TEST_CONST_FLAGS]] = OpFunction %[[#]]
5353
; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#LOCAL]]

0 commit comments

Comments
 (0)