Skip to content

Commit 5ef3399

Browse files
Addressign pr comments
1 parent ad355a3 commit 5ef3399

File tree

5 files changed

+24
-28
lines changed

5 files changed

+24
-28
lines changed

llvm/include/llvm/IR/IntrinsicsSPIRV.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let TargetPrefix = "spv" in {
3333
def int_spv_ptrcast : Intrinsic<[llvm_any_ty], [llvm_any_ty, llvm_metadata_ty, llvm_i32_ty], [ImmArg<ArgIndex<2>>]>;
3434
def int_spv_switch : Intrinsic<[], [llvm_any_ty, llvm_vararg_ty]>;
3535
def int_spv_loop_merge : Intrinsic<[], [llvm_vararg_ty]>;
36-
def int_spv_selection_merge : Intrinsic<[], [llvm_vararg_ty]>;
36+
def int_spv_selection_merge : Intrinsic<[], [llvm_any_ty, llvm_i32_ty], [ImmArg<ArgIndex<1>>]>;
3737
def int_spv_cmpxchg : Intrinsic<[llvm_i32_ty], [llvm_any_ty, llvm_vararg_ty]>;
3838
def int_spv_unreachable : Intrinsic<[], []>;
3939
def int_spv_alloca : Intrinsic<[llvm_any_ty], []>;

llvm/lib/IR/Verifier.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7339,6 +7339,7 @@ struct VerifierLegacyPass : public FunctionPass {
73397339

73407340
bool runOnFunction(Function &F) override {
73417341
if (!V->verify(F) && FatalErrors) {
7342+
auto x = V->verify(F);
73427343
errs() << "in function " << F.getName() << '\n';
73437344
report_fatal_error("Broken function found, compilation aborted!");
73447345
}

llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,12 @@ static void translateBranchMetadata(Module &M) {
306306
auto *HlslControlFlowMD =
307307
BBTerminatorInst->getMetadata("hlsl.controlflow.hint");
308308

309-
if (!HlslControlFlowMD || HlslControlFlowMD->getNumOperands() < 2)
309+
if (!HlslControlFlowMD)
310310
continue;
311311

312+
assert(HlslControlFlowMD->getNumOperands() == 2 &&
313+
"invalid operands for hlsl.controlflow.hint");
314+
312315
MDBuilder MDHelper(M.getContext());
313316
auto *Op1 =
314317
mdconst::extract<ConstantInt>(HlslControlFlowMD->getOperand(1));

llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2810,28 +2810,14 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg,
28102810
}
28112811
case Intrinsic::spv_selection_merge: {
28122812

2813-
auto SelectionControl = SPIRV::SelectionControl::None;
2814-
auto LastOp = I.getOperand(I.getNumExplicitOperands() - 1);
2815-
2816-
assert((LastOp.isMBB() || LastOp.isMetadata()) &&
2817-
"Invalid type for last Machine Operand");
2818-
2819-
if (LastOp.isMetadata()) {
2820-
const MDNode *MDOp = LastOp.getMetadata();
2821-
if (MDOp->getNumOperands() == 2) {
2822-
if (ConstantInt *BranchHint =
2823-
mdconst::extract<ConstantInt>(MDOp->getOperand(1))) {
2824-
if (BranchHint->equalsInt(2))
2825-
SelectionControl = SPIRV::SelectionControl::Flatten;
2826-
else if (BranchHint->equalsInt(1))
2827-
SelectionControl = SPIRV::SelectionControl::DontFlatten;
2828-
else
2829-
llvm_unreachable("Invalid value for SelectionControl");
2830-
} else {
2831-
llvm_unreachable("Invalid value for SelectionControl");
2832-
}
2833-
}
2834-
}
2813+
int64_t SelectionControl = SPIRV::SelectionControl::None;
2814+
auto LastOp = I.getOperand(I.getNumOperands() - 1);
2815+
2816+
auto BranchHint = LastOp.getImm();
2817+
if (BranchHint == 2)
2818+
SelectionControl = SPIRV::SelectionControl::Flatten;
2819+
else if (BranchHint == 1)
2820+
SelectionControl = SPIRV::SelectionControl::DontFlatten;
28352821

28362822
auto MIB =
28372823
BuildMI(BB, I, I.getDebugLoc(), TII.get(SPIRV::OpSelectionMerge));

llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,15 +1207,21 @@ class SPIRVStructurizer : public FunctionPass {
12071207
Instruction *BBTerminatorInst = Builder->GetInsertBlock()->getTerminator();
12081208

12091209
MDNode *MDNode = BBTerminatorInst->getMetadata("hlsl.controlflow.hint");
1210-
if (MDNode)
1210+
1211+
ConstantInt *BranchHint = llvm::ConstantInt::get(Builder->getInt32Ty(), 0);
1212+
1213+
if (MDNode) {
12111214
assert(MDNode->getNumOperands() == 2 &&
12121215
"invalid metadata hlsl.controlflow.hint");
1216+
BranchHint = mdconst::extract<ConstantInt>(MDNode->getOperand(1));
12131217

1214-
Value *MDNodeValue = MetadataAsValue::get(Builder->getContext(), MDNode);
1218+
assert(BranchHint && "invalid metadata value for hlsl.controlflow.hint");
1219+
}
12151220

1216-
llvm::SmallVector<llvm::Value *, 2> Args = {MergeAddress, MDNodeValue};
1221+
llvm::SmallVector<llvm::Value *, 2> Args = {MergeAddress, BranchHint};
12171222

1218-
Builder->CreateIntrinsic(Intrinsic::spv_selection_merge, {}, {Args});
1223+
Builder->CreateIntrinsic(Intrinsic::spv_selection_merge,
1224+
{MergeAddress->getType()}, {Args});
12191225
}
12201226
};
12211227
} // namespace llvm

0 commit comments

Comments
 (0)