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)
327 lines
11 KiB
Plaintext
327 lines
11 KiB
Plaintext
test interpret
|
|
test run
|
|
set enable_llvm_abi_extensions=true
|
|
target aarch64
|
|
target s390x
|
|
target x86_64
|
|
|
|
function %select_spectre_guard_i8_eq(i8, i8, i8) -> i8 {
|
|
block0(v0: i8, v1: i8, v2: i8):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp eq v0, v3
|
|
v5 = select_spectre_guard.i8 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i8_eq(0, 32, 255) == 255
|
|
; run: %select_spectre_guard_i8_eq(255, 32, -1) == -1
|
|
; run: %select_spectre_guard_i8_eq(42, 32, 255) == 32
|
|
|
|
function %select_spectre_guard_i16_eq(i8, i16, i16) -> i16 {
|
|
block0(v0: i8, v1: i16, v2: i16):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp eq v0, v3
|
|
v5 = select_spectre_guard.i16 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i16_eq(0, 32, 65535) == 65535
|
|
; run: %select_spectre_guard_i16_eq(255, 32, -1) == -1
|
|
; run: %select_spectre_guard_i16_eq(42, 32, 65535) == 32
|
|
|
|
function %select_spectre_guard_i32_eq(i8, i32, i32) -> i32 {
|
|
block0(v0: i8, v1: i32, v2: i32):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp eq v0, v3
|
|
v5 = select_spectre_guard.i32 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i32_eq(0, 32, 4294967295) == 4294967295
|
|
; run: %select_spectre_guard_i32_eq(255, 32, -1) == -1
|
|
; run: %select_spectre_guard_i32_eq(42, 32, 4294967295) == 32
|
|
|
|
function %select_spectre_guard_i64_eq(i8, i64, i64) -> i64 {
|
|
block0(v0: i8, v1: i64, v2: i64):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp eq v0, v3
|
|
v5 = select_spectre_guard.i64 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i64_eq(0, 32, 18446744073709551615) == 18446744073709551615
|
|
; run: %select_spectre_guard_i64_eq(255, 32, -1) == -1
|
|
; run: %select_spectre_guard_i64_eq(42, 32, 18446744073709551615) == 32
|
|
|
|
function %select_spectre_guard_i128_eq(i8, i128, i128) -> i128 {
|
|
block0(v0: i8, v1: i128, v2: i128):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp eq v0, v3
|
|
v5 = select_spectre_guard.i128 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i128_eq(0, 32, 19000000000000000000) == 19000000000000000000
|
|
; run: %select_spectre_guard_i128_eq(255, 32, -1) == -1
|
|
; run: %select_spectre_guard_i128_eq(42, 32, 19000000000000000000) == 32
|
|
|
|
function %select_spectre_guard_i8_ult(i8, i8, i8) -> i8 {
|
|
block0(v0: i8, v1: i8, v2: i8):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp ult v0, v3
|
|
v5 = select_spectre_guard.i8 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i8_ult(0, 32, 255) == 32
|
|
; run: %select_spectre_guard_i8_ult(255, 32, -1) == -1
|
|
; run: %select_spectre_guard_i8_ult(42, 32, 255) == 255
|
|
|
|
function %select_spectre_guard_i16_ult(i8, i16, i16) -> i16 {
|
|
block0(v0: i8, v1: i16, v2: i16):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp ult v0, v3
|
|
v5 = select_spectre_guard.i16 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i16_ult(0, 32, 65535) == 32
|
|
; run: %select_spectre_guard_i16_ult(255, 32, -1) == -1
|
|
; run: %select_spectre_guard_i16_ult(42, 32, 65535) == 65535
|
|
|
|
function %select_spectre_guard_i32_ult(i8, i32, i32) -> i32 {
|
|
block0(v0: i8, v1: i32, v2: i32):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp ult v0, v3
|
|
v5 = select_spectre_guard.i32 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i32_ult(0, 32, 4294967295) == 32
|
|
; run: %select_spectre_guard_i32_ult(255, 32, -1) == -1
|
|
; run: %select_spectre_guard_i32_ult(42, 32, 4294967295) == 4294967295
|
|
|
|
function %select_spectre_guard_i64_ult(i8, i64, i64) -> i64 {
|
|
block0(v0: i8, v1: i64, v2: i64):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp ult v0, v3
|
|
v5 = select_spectre_guard.i64 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i64_ult(0, 32, 18446744073709551615) == 32
|
|
; run: %select_spectre_guard_i64_ult(255, 32, -1) == -1
|
|
; run: %select_spectre_guard_i64_ult(42, 32, 18446744073709551615) == 18446744073709551615
|
|
|
|
function %select_spectre_guard_i128_ult(i8, i128, i128) -> i128 {
|
|
block0(v0: i8, v1: i128, v2: i128):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp ult v0, v3
|
|
v5 = select_spectre_guard.i128 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i128_ult(0, 32, 19000000000000000000) == 32
|
|
; run: %select_spectre_guard_i128_ult(255, 32, -1) == -1
|
|
; run: %select_spectre_guard_i128_ult(42, 32, 19000000000000000000) == 19000000000000000000
|
|
|
|
function %select_spectre_guard_i8_ule(i8, i8, i8) -> i8 {
|
|
block0(v0: i8, v1: i8, v2: i8):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp ule v0, v3
|
|
v5 = select_spectre_guard.i8 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i8_ule(0, 32, 255) == 32
|
|
; run: %select_spectre_guard_i8_ule(255, 32, -1) == -1
|
|
; run: %select_spectre_guard_i8_ule(42, 32, 255) == 32
|
|
|
|
function %select_spectre_guard_i16_ule(i8, i16, i16) -> i16 {
|
|
block0(v0: i8, v1: i16, v2: i16):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp ule v0, v3
|
|
v5 = select_spectre_guard.i16 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i16_ule(0, 32, 65535) == 32
|
|
; run: %select_spectre_guard_i16_ule(255, 32, -1) == -1
|
|
; run: %select_spectre_guard_i16_ule(42, 32, 65535) == 32
|
|
|
|
function %select_spectre_guard_i32_ule(i8, i32, i32) -> i32 {
|
|
block0(v0: i8, v1: i32, v2: i32):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp ule v0, v3
|
|
v5 = select_spectre_guard.i32 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i32_ule(0, 32, 4294967295) == 32
|
|
; run: %select_spectre_guard_i32_ule(255, 32, -1) == -1
|
|
; run: %select_spectre_guard_i32_ule(42, 32, 4294967295) == 32
|
|
|
|
function %select_spectre_guard_i64_ule(i8, i64, i64) -> i64 {
|
|
block0(v0: i8, v1: i64, v2: i64):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp ule v0, v3
|
|
v5 = select_spectre_guard.i64 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i64_ule(0, 32, 18446744073709551615) == 32
|
|
; run: %select_spectre_guard_i64_ule(255, 32, -1) == -1
|
|
; run: %select_spectre_guard_i64_ule(42, 32, 18446744073709551615) == 32
|
|
|
|
function %select_spectre_guard_i128_ule(i8, i128, i128) -> i128 {
|
|
block0(v0: i8, v1: i128, v2: i128):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp ule v0, v3
|
|
v5 = select_spectre_guard.i128 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i128_ule(0, 32, 19000000000000000000) == 32
|
|
; run: %select_spectre_guard_i128_ule(255, 32, -1) == -1
|
|
; run: %select_spectre_guard_i128_ule(42, 32, 19000000000000000000) == 32
|
|
|
|
function %select_spectre_guard_i8_slt(i8, i8, i8) -> i8 {
|
|
block0(v0: i8, v1: i8, v2: i8):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp slt v0, v3
|
|
v5 = select_spectre_guard.i8 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i8_slt(0, 32, 255) == 32
|
|
; run: %select_spectre_guard_i8_slt(-128, 32, -1) == 32
|
|
; run: %select_spectre_guard_i8_slt(42, 32, 255) == 255
|
|
|
|
function %select_spectre_guard_i16_slt(i8, i16, i16) -> i16 {
|
|
block0(v0: i8, v1: i16, v2: i16):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp slt v0, v3
|
|
v5 = select_spectre_guard.i16 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i16_slt(0, 32, 65535) == 32
|
|
; run: %select_spectre_guard_i16_slt(-128, 32, -1) == 32
|
|
; run: %select_spectre_guard_i16_slt(42, 32, 65535) == 65535
|
|
|
|
function %select_spectre_guard_i32_slt(i8, i32, i32) -> i32 {
|
|
block0(v0: i8, v1: i32, v2: i32):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp slt v0, v3
|
|
v5 = select_spectre_guard.i32 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i32_slt(0, 32, 4294967295) == 32
|
|
; run: %select_spectre_guard_i32_slt(-128, 32, -1) == 32
|
|
; run: %select_spectre_guard_i32_slt(42, 32, 4294967295) == 4294967295
|
|
|
|
function %select_spectre_guard_i64_slt(i8, i64, i64) -> i64 {
|
|
block0(v0: i8, v1: i64, v2: i64):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp slt v0, v3
|
|
v5 = select_spectre_guard.i64 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i64_slt(0, 32, 18446744073709551615) == 32
|
|
; run: %select_spectre_guard_i64_slt(-128, 32, -1) == 32
|
|
; run: %select_spectre_guard_i64_slt(42, 32, 18446744073709551615) == 18446744073709551615
|
|
|
|
function %select_spectre_guard_i128_slt(i8, i128, i128) -> i128 {
|
|
block0(v0: i8, v1: i128, v2: i128):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp slt v0, v3
|
|
v5 = select_spectre_guard.i128 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i128_slt(0, 32, 19000000000000000000) == 32
|
|
; run: %select_spectre_guard_i128_slt(-128, 32, -1) == 32
|
|
; run: %select_spectre_guard_i128_slt(42, 32, 19000000000000000000) == 19000000000000000000
|
|
|
|
function %select_spectre_guard_i8_sle(i8, i8, i8) -> i8 {
|
|
block0(v0: i8, v1: i8, v2: i8):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp sle v0, v3
|
|
v5 = select_spectre_guard.i8 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i8_sle(0, 32, 127) == 32
|
|
; run: %select_spectre_guard_i8_sle(-128, 32, -1) == 32
|
|
; run: %select_spectre_guard_i8_sle(127, 32, -1) == -1
|
|
; run: %select_spectre_guard_i8_sle(127, 32, 127) == 127
|
|
; run: %select_spectre_guard_i8_sle(42, 32, 127) == 32
|
|
|
|
function %select_spectre_guard_i16_sle(i8, i16, i16) -> i16 {
|
|
block0(v0: i8, v1: i16, v2: i16):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp sle v0, v3
|
|
v5 = select_spectre_guard.i16 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i16_sle(0, 32, 65535) == 32
|
|
; run: %select_spectre_guard_i16_sle(-128, 32, -1) == 32
|
|
; run: %select_spectre_guard_i16_sle(127, 32, -1) == -1
|
|
; run: %select_spectre_guard_i16_sle(127, 32, 65535) == 65535
|
|
; run: %select_spectre_guard_i16_sle(42, 32, 65535) == 32
|
|
|
|
function %select_spectre_guard_i32_sle(i8, i32, i32) -> i32 {
|
|
block0(v0: i8, v1: i32, v2: i32):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp sle v0, v3
|
|
v5 = select_spectre_guard.i32 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i32_sle(0, 32, 4294967295) == 32
|
|
; run: %select_spectre_guard_i32_sle(-128, 32, -1) == 32
|
|
; run: %select_spectre_guard_i32_sle(127, 32, -1) == -1
|
|
; run: %select_spectre_guard_i32_sle(127, 32, 4294967295) == 4294967295
|
|
; run: %select_spectre_guard_i32_sle(42, 32, 4294967295) == 32
|
|
|
|
function %select_spectre_guard_i64_sle(i8, i64, i64) -> i64 {
|
|
block0(v0: i8, v1: i64, v2: i64):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp sle v0, v3
|
|
v5 = select_spectre_guard.i64 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i64_sle(0, 32, 18446744073709551615) == 32
|
|
; run: %select_spectre_guard_i64_sle(-128, 32, -1) == 32
|
|
; run: %select_spectre_guard_i64_sle(127, 32, -1) == -1
|
|
; run: %select_spectre_guard_i64_sle(127, 32, 18446744073709551615) == 18446744073709551615
|
|
; run: %select_spectre_guard_i64_sle(42, 32, 18446744073709551615) == 32
|
|
|
|
function %select_spectre_guard_i128_sle(i8, i128, i128) -> i128 {
|
|
block0(v0: i8, v1: i128, v2: i128):
|
|
v3 = iconst.i8 42
|
|
v4 = icmp sle v0, v3
|
|
v5 = select_spectre_guard.i128 v4, v1, v2
|
|
return v5
|
|
}
|
|
|
|
; run: %select_spectre_guard_i128_sle(0, 32, 19000000000000000000) == 32
|
|
; run: %select_spectre_guard_i128_sle(-128, 32, -1) == 32
|
|
; run: %select_spectre_guard_i128_sle(127, 32, -1) == -1
|
|
; run: %select_spectre_guard_i128_sle(127, 32, 19000000000000000000) == 19000000000000000000
|
|
; run: %select_spectre_guard_i128_sle(42, 32, 19000000000000000000) == 32
|
|
|
|
function %select_spectre_guard_i128_cond(i128, i128, i128) -> i128 {
|
|
block0(v0: i128, v1: i128, v2: i128):
|
|
v3 = select_spectre_guard.i128 v0, v1, v2
|
|
return v3
|
|
}
|
|
; run: %select_spectre_guard_i128_cond(1, 2, 3) == 2
|
|
; run: %select_spectre_guard_i128_cond(0, 2, 3) == 3
|
|
; run: %select_spectre_guard_i128_cond(18446744073709551616, 2, 3) == 2
|
|
; run: %select_spectre_guard_i128_cond(18446744073709551616, 18446744073709551616, 3) == 18446744073709551616
|