Skip to content

Commit 927ed63

Browse files
modify how we lower the builtin
1 parent 845c0e8 commit 927ed63

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVInstPrinter.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,15 @@ void SPIRVInstPrinter::printInst(const MCInst *MI, uint64_t Address,
284284
}
285285
break;
286286
}
287+
case SPIRV::OpPredicatedLoadINTEL: {
288+
const unsigned NumOps = MI->getNumOperands();
289+
if (NumOps > NumFixedOps) {
290+
OS << ' ';
291+
printSymbolicOperand<OperandCategory::MemoryOperandOperand>(
292+
MI, FirstVariableIndex, OS);
293+
break;
294+
}
295+
}
287296
default:
288297
printRemainingVariableOps(MI, NumFixedOps, OS);
289298
break;

llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,24 +1131,6 @@ static bool buildPipeInst(const SPIRV::IncomingCall *Call, unsigned Opcode,
11311131
}
11321132
}
11331133

1134-
// Helper function for building Intel's predicated load/store instructions.
1135-
static bool buildPredicatedLoadStoreInst(const SPIRV::IncomingCall *Call,
1136-
unsigned Opcode,
1137-
MachineIRBuilder &MIRBuilder,
1138-
SPIRVGlobalRegistry *GR) {
1139-
// Generate SPIRV instruction accordingly.
1140-
if (Call->isSpirvOp())
1141-
return buildOpFromWrapper(MIRBuilder, Opcode, Call, Register(0));
1142-
1143-
auto MIB = MIRBuilder.buildInstr(Opcode)
1144-
.addDef(Call->ReturnRegister)
1145-
.addUse(GR->getSPIRVTypeID(Call->ReturnType));
1146-
for (unsigned i = 0; i < Call->Arguments.size(); ++i)
1147-
MIB.addUse(Call->Arguments[i]);
1148-
1149-
return true;
1150-
}
1151-
11521134
static unsigned getNumComponentsForDim(SPIRV::Dim::Dim dim) {
11531135
switch (dim) {
11541136
case SPIRV::Dim::DIM_1D:
@@ -2444,7 +2426,19 @@ static bool generatePredicatedLoadStoreInst(const SPIRV::IncomingCall *Call,
24442426
unsigned Opcode =
24452427
SPIRV::lookupNativeBuiltin(Builtin->Name, Builtin->Set)->Opcode;
24462428

2447-
return buildPredicatedLoadStoreInst(Call, Opcode, MIRBuilder, GR);
2429+
bool IsSet = Opcode != SPIRV::OpPredicatedStoreINTEL;
2430+
unsigned ArgSz = Call->Arguments.size();
2431+
unsigned LiteralIdx = 0;
2432+
if(ArgSz > 3) {
2433+
LiteralIdx = 3;
2434+
}
2435+
SmallVector<uint32_t, 1> ImmArgs;
2436+
MachineRegisterInfo *MRI = MIRBuilder.getMRI();
2437+
if (LiteralIdx > 0)
2438+
ImmArgs.push_back(getConstFromIntrinsic(Call->Arguments[LiteralIdx], MRI));
2439+
Register TypeReg = GR->getSPIRVTypeID(Call->ReturnType);
2440+
return buildOpFromWrapper(MIRBuilder, Opcode, Call,
2441+
IsSet ? TypeReg : Register(0), ImmArgs);
24482442
}
24492443

24502444
static bool buildNDRange(const SPIRV::IncomingCall *Call,

llvm/lib/Target/SPIRV/SPIRVInstrInfo.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ def OpSubgroup2DBlockStoreINTEL: Op<6235, (outs), (ins ID:$element_size, ID:$blo
989989
"OpSubgroup2DBlockStoreINTEL $element_size $block_width $block_height $block_count $src_ptr $dst_base_ptr $memory_width $memory_height $memory_pitch $coord">;
990990

991991
// SPV_INTEL_predicated_io
992-
def OpPredicatedLoadINTEL: Op<6528, (outs ID:$res), (ins ID:$ptr, ID:$predicate, ID:$default_value),
993-
"$res = OpPredicatedLoadINTEL $ptr $predicate $default_value">;
994-
def OpPredicatedStoreINTEL: Op<6529, (outs), (ins ID:$ptr, ID:$object, ID:$predicate),
992+
def OpPredicatedLoadINTEL: Op<6528, (outs ID:$res), (ins TYPE:$resType, ID:$ptr, ID:$predicate, ID:$default_value, variable_ops),
993+
"$res = OpPredicatedLoadINTEL $resType $ptr $predicate $default_value">;
994+
def OpPredicatedStoreINTEL: Op<6529, (outs), (ins ID:$ptr, ID:$object, ID:$predicate, variable_ops),
995995
"OpPredicatedStoreINTEL $ptr $object $predicate">;

llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_predicated_io/predicated_io_generic.ll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
; CHECK-DAG: Extension "SPV_INTEL_predicated_io"
1010

1111
; CHECK-DAG: %[[Int32Ty:[0-9]+]] = OpTypeInt 32 0
12-
; CHECK-DAG: %[[Const0:[0-9]+]] = OpConstant %[[Int32Ty]] 0
1312
; CHECK-DAG: %[[VoidTy:[0-9]+]] = OpTypeVoid
1413
; CHECK-DAG: %[[IntPtrTy:[0-9]+]] = OpTypePointer CrossWorkgroup %[[Int32Ty]]
1514
; CHECK-DAG: %[[BoolTy:[0-9]+]] = OpTypeBool
@@ -18,10 +17,10 @@
1817
; CHECK: %[[DefaultVal:]] = FunctionParameter %[[Int32Ty]]
1918
; CHECK: %[[StoreObj:]] = FunctionParameter %[[Int32Ty]]
2019
; CHECK: %[[Predicate:]] = FunctionParameter %[[BoolTy]]
21-
; CHECK: PredicatedLoadINTEL %[[Int32Ty]] %[[Result1:]] %[[LoadPtr]] %[[Predicate]] %[[DefaultVal]]
22-
; CHECK: PredicatedLoadINTEL %[[Int32Ty]] %[[Result2:]] %[[LoadPtr]] %[[Predicate]] %[[DefaultVal]] %[[Const0]]
20+
; CHECK: PredicatedLoadINTEL %[[Int32Ty]] %[[LoadPtr]] %[[Predicate]] %[[DefaultVal]]
21+
; CHECK: PredicatedLoadINTEL %[[Int32Ty]] %[[LoadPtr]] %[[Predicate]] %[[DefaultVal]] 0
2322
; CHECK: PredicatedStoreINTEL %[[StorePtr]] %[[StoreObj]] %[[Predicate]]
24-
; CHECK: PredicatedStoreINTEL %[[StorePtr]] %[[StoreObj]] %[[Predicate]] %[[Const0]]
23+
; CHECK: PredicatedStoreINTEL %[[StorePtr]] %[[StoreObj]] %[[Predicate]] 0
2524

2625
define spir_func void @foo(ptr addrspace(1) %load_pointer, ptr addrspace(1) %store_pointer, i32 %default_value, i32 %store_object, i1 zeroext %predicate) {
2726
entry:
@@ -35,4 +34,4 @@ entry:
3534
declare spir_func i32 @_Z27__spirv_PredicatedLoadINTELPU3AS1Kibi(ptr addrspace(1), i1, i32)
3635
declare spir_func i32 @_Z27__spirv_PredicatedLoadINTELPU3AS1Kibii(ptr addrspace(1), i1, i32, i32)
3736
declare spir_func void @_Z28__spirv_PredicatedStoreINTELPU3AS1Kiib(ptr addrspace(1), i32, i1)
38-
declare spir_func void @_Z28__spirv_PredicatedStoreINTELPU3AS1Kiibi(ptr addrspace(1), i32, i1, i32)
37+
declare spir_func void @_Z28__spirv_PredicatedStoreINTELPU3AS1Kiibi(ptr addrspace(1), i32, i1, i32)

0 commit comments

Comments
 (0)