Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/target/spirv/codegen_spirv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -676,13 +676,12 @@ void CodeGenSPIRV::VisitStmt_(const ForNode* op) {
spirv::Value init_value = MakeValue(op->min);
PrimExpr end = is_zero(op->min) ? op->extent : analyzer_->Simplify(op->min + op->extent);
spirv::Value end_value = MakeValue(end);
spirv::PhiValue loop_var = builder_->MakePhi(init_value.stype, 2);

// loop step
spirv::Value step;
if (op->HasTrivialStep()) {
step = op->loop_var.dtype().is_int() ? builder_->IntImm(loop_var.stype, 1)
: builder_->UIntImm(loop_var.stype, 1);
step = op->loop_var.dtype().is_int() ? builder_->IntImm(init_value.stype, 1)
: builder_->UIntImm(init_value.stype, 1);
} else {
step = MakeValue(tvm::cast(end->dtype, *op->step));
}
Expand All @@ -699,8 +698,9 @@ void CodeGenSPIRV::VisitStmt_(const ForNode* op) {
builder_->SetName(merge_label, "for_loop_merge");
builder_->MakeInst(spv::OpBranch, head_label);

// Loop head
// Loop head - Phi must be created AFTER StartLabel so it's in the head block
builder_->StartLabel(head_label);
spirv::PhiValue loop_var = builder_->MakePhi(init_value.stype, 2);
loop_var.SetIncoming(0, init_value, init_label);
spirv::Value loop_cond = builder_->LT(loop_var, end_value);
uint32_t control =
Expand Down
Loading