spirv: consider bitsize when handling OpSwitch cases
When walking over all the cases in a OpSwitch, take in account the bitsize of the literals to avoid getting wrong cases. Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
This commit is contained in:
@@ -513,13 +513,14 @@ vtn_cfg_walk_blocks(struct vtn_builder *b, struct list_head *cf_list,
|
|||||||
"Selector of OpSelect must have a type of OpTypeInt");
|
"Selector of OpSelect must have a type of OpTypeInt");
|
||||||
|
|
||||||
bool is_default = true;
|
bool is_default = true;
|
||||||
|
const uint bitsize = nir_alu_type_get_type_size(cond_type);
|
||||||
for (const uint32_t *w = block->branch + 2; w < branch_end;) {
|
for (const uint32_t *w = block->branch + 2; w < branch_end;) {
|
||||||
uint64_t literal = 0;
|
uint64_t literal = 0;
|
||||||
if (!is_default) {
|
if (!is_default) {
|
||||||
if (nir_alu_type_get_type_size(cond_type) <= 32) {
|
if (bitsize <= 32) {
|
||||||
literal = *(w++);
|
literal = *(w++);
|
||||||
} else {
|
} else {
|
||||||
assert(nir_alu_type_get_type_size(cond_type) == 64);
|
assert(bitsize == 64);
|
||||||
literal = vtn_u64_literal(w);
|
literal = vtn_u64_literal(w);
|
||||||
w += 2;
|
w += 2;
|
||||||
}
|
}
|
||||||
@@ -544,7 +545,7 @@ vtn_cfg_walk_blocks(struct vtn_builder *b, struct list_head *cf_list,
|
|||||||
/* Finally, we walk over all of the cases one more time and put
|
/* Finally, we walk over all of the cases one more time and put
|
||||||
* them in fall-through order.
|
* them in fall-through order.
|
||||||
*/
|
*/
|
||||||
for (const uint32_t *w = block->branch + 2; w < branch_end; w += 2) {
|
for (const uint32_t *w = block->branch + 2; w < branch_end;) {
|
||||||
struct vtn_block *case_block =
|
struct vtn_block *case_block =
|
||||||
vtn_value(b, *w, vtn_value_type_block)->block;
|
vtn_value(b, *w, vtn_value_type_block)->block;
|
||||||
|
|
||||||
@@ -554,6 +555,13 @@ vtn_cfg_walk_blocks(struct vtn_builder *b, struct list_head *cf_list,
|
|||||||
vtn_assert(case_block->switch_case);
|
vtn_assert(case_block->switch_case);
|
||||||
|
|
||||||
vtn_order_case(swtch, case_block->switch_case);
|
vtn_order_case(swtch, case_block->switch_case);
|
||||||
|
|
||||||
|
if (bitsize <= 32) {
|
||||||
|
w += 2;
|
||||||
|
} else {
|
||||||
|
assert(bitsize == 64);
|
||||||
|
w += 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum vtn_branch_type branch_type =
|
enum vtn_branch_type branch_type =
|
||||||
|
|||||||
Reference in New Issue
Block a user