support select_spectre_guard and select on i128 conditions on all platforms. (#5460)
Fixes #5199.
Fixes #5200.
Fixes #5452.
Fixes #5453.
On riscv64, there is apparently an autoconversion from `ValueRegs` to
`Reg` that takes just the low register [0], and removing this conversion
causes 48 errors. As a result of this, `select` with an `i128` condition
was silently miscompiling, testing only the low 64 bits. We should
remove this autoconversion to ensure we aren't missing any other silent
truncations, but for now this PR just adds the explicit `I128` logic for
`select` / `select_spectre_guard`.
[0]
d9fdbfd50e/cranelift/codegen/src/isa/riscv64/inst.isle (L1762)
This commit is contained in:
@@ -1899,6 +1899,17 @@
|
||||
(rule (normalize_cmp_value $I64 r) r)
|
||||
(rule (normalize_cmp_value $I128 r) r)
|
||||
|
||||
;; Convert a truthy value, possibly of more than one register (an
|
||||
;; I128), to one register. If narrower than 64 bits, must have already
|
||||
;; been masked (e.g. by `normalize_cmp_value`).
|
||||
(decl truthy_to_reg (Type ValueRegs) Reg)
|
||||
(rule 1 (truthy_to_reg (fits_in_64 _) regs)
|
||||
(value_regs_get regs 0))
|
||||
(rule 0 (truthy_to_reg $I128 regs)
|
||||
(let ((lo Reg (value_regs_get regs 0))
|
||||
(hi Reg (value_regs_get regs 1)))
|
||||
(alu_rrr (AluOPRRR.Or) lo hi)))
|
||||
|
||||
;;;;;
|
||||
(rule
|
||||
(lower_branch (brz v @ (value_type ty) _ _) targets)
|
||||
|
||||
@@ -612,7 +612,7 @@
|
||||
;;;;; Rules for `select`;;;;;;;;;
|
||||
(rule
|
||||
(lower (has_type ty (select c @ (value_type cty) x y)))
|
||||
(gen_select ty (normalize_cmp_value cty c) x y))
|
||||
(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)))
|
||||
@@ -843,7 +843,7 @@
|
||||
|
||||
(rule -1
|
||||
(lower (has_type ty (select_spectre_guard c @ (value_type cty) x y)))
|
||||
(gen_select ty (normalize_cmp_value cty c) x y))
|
||||
(gen_select ty (truthy_to_reg cty (normalize_cmp_value cty c)) x y))
|
||||
|
||||
;;;;; Rules for `bmask`;;;;;;;;;
|
||||
(rule
|
||||
|
||||
Reference in New Issue
Block a user