Skip to content

Commit

Permalink
Fix uextend on x64 for non-i32-source cases. (bytecodealliance#3906)
Browse files Browse the repository at this point in the history
In bytecodealliance#3849, I moved uextend over to ISLE in the x64 backend. Unfortunately, the lowering patterns had a bug in the i32-to-i64 special case (when we know the generating instruction zeroes the upper 32 bits): it wasn't actually special casing for an i32 source! This meant that e.g. zero extends of the results of i8 adds did not work properly.

This PR fixes the bug and updates the runtest for extends significantly to cover the narrow-value cases.

No security impact to Wasm as Wasm does not use narrow integer types.

Thanks @bjorn3 for reporting!
  • Loading branch information
cfallin committed Mar 9, 2022
1 parent 9137b4a commit a371355
Show file tree
Hide file tree
Showing 4 changed files with 310 additions and 114 deletions.
20 changes: 10 additions & 10 deletions cranelift/codegen/src/isa/x64/lower.isle
Original file line number Diff line number Diff line change
Expand Up @@ -1894,34 +1894,34 @@
;; keep these here than write an external extractor containing bits of
;; the instruction pattern.s)
(rule (lower (has_type $I64
(uextend src @ (iadd _ _))))
(uextend src @ (has_type $I32 (iadd _ _)))))
src)
(rule (lower (has_type $I64
(uextend src @ (iadd_ifcout _ _))))
(uextend src @ (has_type $I32 (iadd_ifcout _ _)))))
src)
(rule (lower (has_type $I64
(uextend src @ (isub _ _))))
(uextend src @ (has_type $I32 (isub _ _)))))
src)
(rule (lower (has_type $I64
(uextend src @ (imul _ _))))
(uextend src @ (has_type $I32 (imul _ _)))))
src)
(rule (lower (has_type $I64
(uextend src @ (band _ _))))
(uextend src @ (has_type $I32 (band _ _)))))
src)
(rule (lower (has_type $I64
(uextend src @ (bor _ _))))
(uextend src @ (has_type $I32 (bor _ _)))))
src)
(rule (lower (has_type $I64
(uextend src @ (bxor _ _))))
(uextend src @ (has_type $I32 (bxor _ _)))))
src)
(rule (lower (has_type $I64
(uextend src @ (ishl _ _))))
(uextend src @ (has_type $I32 (ishl _ _)))))
src)
(rule (lower (has_type $I64
(uextend src @ (ushr _ _))))
(uextend src @ (has_type $I32 (ushr _ _)))))
src)
(rule (lower (has_type $I64
(uextend src @ (uload32 _ _ _))))
(uextend src @ (has_type $I32 (uload32 _ _ _)))))
src)

;; Rules for `sextend` / `bextend` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
src/clif.isle 9ea75a6f790b5c03
src/prelude.isle b2bc986bcbbbb77
src/isa/x64/inst.isle 40f495d3ca5ae547
src/isa/x64/lower.isle faa2a07bba48a813
src/isa/x64/lower.isle c049f7d36db0e0fb
186 changes: 96 additions & 90 deletions cranelift/codegen/src/isa/x64/lower/isle/generated_code.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a371355

Please sign in to comment.