riscv64: Add masking for small types when lowering select (#5504)

When lowering `select+icmp` we have an optimization that allows us to
avoid materializing the icmp result.

We were accidentally not masking the high bits for i8 and i16 in this case.

Issue #5498 reported this as an illegal instruction but what was happening
there was that the invalid select caused a division by zero.
This commit is contained in:
Afonso Bordado
2023-01-03 19:59:14 +00:00
committed by GitHub
parent f911855612
commit 7e94704264
3 changed files with 30 additions and 6 deletions

View File

@@ -615,8 +615,10 @@
(gen_select ty (truthy_to_reg cty (normalize_cmp_value cty c)) x y))
(rule 1
(lower (has_type ty (select (icmp cc a b) x y)))
(gen_select_reg cc a b x y))
(lower (has_type ty (select (icmp cc a b @ (value_type in_ty)) x y)))
(let ((a Reg (normalize_cmp_value in_ty a))
(b Reg (normalize_cmp_value in_ty b)))
(gen_select_reg cc a b x y)))
;;;;; Rules for `bitselect`;;;;;;;;;