Cranelift: Correctly wrap shifts in constant propagation (#5695)

Fixes #5690
Fixes #5696

Co-authored-by: Jamey Sharp <jsharp@fastly.com>
This commit is contained in:
Nick Fitzgerald
2023-02-02 16:12:57 -08:00
committed by GitHub
parent fd67ccf9cd
commit 72c8513411
10 changed files with 176 additions and 35 deletions

View File

@@ -87,6 +87,17 @@ block0(v0: i64):
; return v5
}
function %signed_shift_right_shift_left_i8_mask_rhs(i8) -> i8 {
block0(v0: i8):
v1 = iconst.i8 0xf5
v2 = sshr v0, v1
v3 = ishl v2, v1
return v3
; check: v4 = iconst.i8 224
; check: v5 = band v0, v4
; return v5
}
function %or_and_y_with_not_y_i8(i8, i8) -> i8 {
block0(v0: i8, v1: i8):
v2 = band v0, v1

View File

@@ -34,6 +34,28 @@ block0:
; check: v3 = iconst.i8 4
; check: return v3
function %ishl_i8_i16() -> i8 {
block0:
v0 = iconst.i8 1
v1 = iconst.i16 0xf2
v2 = ishl v0, v1
return v2
}
; check: v3 = iconst.i8 4
; check: return v3
function %ishl_i16_i8() -> i16 {
block0:
v0 = iconst.i16 1
v1 = iconst.i8 0xf2
v2 = ishl v0, v1
return v2
}
; check: v3 = iconst.i16 4
; check: return v3
function %ushr() -> i8 {
block0:
v0 = iconst.i8 -1
@@ -45,6 +67,28 @@ block0:
; check: v3 = iconst.i8 63
; check: return v3
function %ushr_i8_i16() -> i8 {
block0:
v0 = iconst.i8 -1
v1 = iconst.i16 0xf2
v2 = ushr v0, v1
return v2
}
; check: v3 = iconst.i8 63
; check: return v3
function %ushr_i16_i8() -> i16 {
block0:
v0 = iconst.i16 -1
v1 = iconst.i8 0xf2
v2 = ushr v0, v1
return v2
}
; check: v3 = iconst.i16 0x3fff
; check: return v3
function %sshr() -> i8 {
block0:
v0 = iconst.i8 0xf0
@@ -53,7 +97,29 @@ block0:
return v2
}
; check: v3 = iconst.i8 -4
; check: v3 = iconst.i8 252
; check: return v3
function %sshr_i8_i16() -> i8 {
block0:
v0 = iconst.i8 0xf0
v1 = iconst.i16 0xf2
v2 = sshr v0, v1
return v2
}
; check: v3 = iconst.i8 252
; check: return v3
function %sshr_i16_i8() -> i16 {
block0:
v0 = iconst.i16 0xfff0
v1 = iconst.i8 0xf2
v2 = sshr v0, v1
return v2
}
; check: v3 = iconst.i16 0xfffc
; check: return v3
function %icmp_eq_i32() -> i8 {

View File

@@ -0,0 +1,29 @@
test interpret
test run
set opt_level=speed
set enable_simd=true
set enable_safepoints=true
set unwind_info=false
set preserve_frame_pointers=true
set machine_code_cfg_info=true
set enable_table_access_spectre_mitigation=false
target aarch64
target x86_64
function %u1() -> i64 sext, f64, i8, i8 sext, i8 sext system_v {
block0:
v0 = f64const 0x1.8373638ff3738p-124
v1 = iconst.i8 53
v2 = iconst.i64 0x4445_00ff_ffff_ffff
v3 = iconst.i8 0
v4 = iconst.i16 0
v5 = iconst.i32 0
v6 = iconst.i64 0
v7 = uextend.i128 v6
v8 = ishl v2, v2
v9 = rotr v1, v1
nop
return v8, v0, v9, v9, v9
}
; run: %u1() == [-9223372036854775808, 0x1.8373638ff3738p-124, -87, -87, -87]

View File

@@ -0,0 +1,20 @@
;;! target = "x86_64"
;;! optimize = true
;;! settings = ["opt_level=speed"]
(module
(func (;0;) (param i64) (result i64)
i64.const 32
i64.const -19
i64.shr_u
;; call 0
)
)
;; function u0:0(i64, i64 vmctx) -> i64 fast {
;; block0(v0: i64, v1: i64):
;; @001e jump block1
;;
;; block1:
;; v6 = iconst.i64 0
;; @001e return v6 ; v6 = 0
;; }

View File

@@ -24,6 +24,7 @@ pub fn run(path: &Path, wat: &str) -> Result<()> {
let config: TestConfig =
toml::from_str(&config_text).context("failed to parse the test configuration")?;
log::debug!("Wasm test config = {config:#?}");
config
.validate()