Skip to content

Commit

Permalink
Merge branch 'main' into upstream-08-28
Browse files Browse the repository at this point in the history
	modified:   cranelift/filetests/filetests/isa/aarch64/user_stack_maps.`lif
  • Loading branch information
avanhatt committed Aug 30, 2024
2 parents 63c82cc + 098430f commit 2fd06af
Show file tree
Hide file tree
Showing 135 changed files with 11,785 additions and 4,474 deletions.
39 changes: 21 additions & 18 deletions Cargo.lock

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

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ wasmtime-cranelift = { workspace = true, optional = true }
wasmtime-environ = { workspace = true }
wasmtime-explorer = { workspace = true, optional = true }
wasmtime-wast = { workspace = true, optional = true }
wasi-common = { workspace = true, default-features = true, features = ["exit"], optional = true }
wasi-common = { workspace = true, default-features = true, features = ["exit", "tokio"], optional = true }
wasmtime-wasi = { workspace = true, default-features = true, optional = true }
wasmtime-wasi-nn = { workspace = true, optional = true }
wasmtime-wasi-runtime-config = { workspace = true, optional = true }
Expand Down Expand Up @@ -111,7 +111,7 @@ test-programs-artifacts = { workspace = true }
bytesize = "1.3.0"
wit-component = { workspace = true }
cranelift-filetests = { workspace = true }
cranelift-codegen = { workspace = true }
cranelift-codegen = { workspace = true, features = ["disas", "trace-log", "timing"] }
cranelift-reader = { workspace = true }
toml = { workspace = true }
similar = { workspace = true }
Expand Down Expand Up @@ -248,7 +248,7 @@ byte-array-literals = { path = "crates/wasi-preview1-component-adapter/byte-arra

# Bytecode Alliance maintained dependencies:
# ---------------------------
regalloc2 = "0.9.3"
regalloc2 = "0.9.4"

# cap-std family:
target-lexicon = "0.12.16"
Expand Down Expand Up @@ -390,6 +390,7 @@ default = [
# cost, so allow disabling this through disabling of our own `default`
# feature.
"clap/default",
"clap/wrap_help",
]

# ========================================
Expand Down Expand Up @@ -441,7 +442,7 @@ explore = ["dep:wasmtime-explorer", "dep:tempfile"]
wast = ["dep:wasmtime-wast"]
config = ["cache"]
compile = ["cranelift"]
run = ["dep:wasmtime-wasi", "wasmtime/runtime", "dep:listenfd", "dep:wasi-common"]
run = ["dep:wasmtime-wasi", "wasmtime/runtime", "dep:listenfd", "dep:wasi-common", "dep:tokio"]

[[test]]
name = "host_segfault"
Expand Down
2 changes: 1 addition & 1 deletion cranelift/codegen/src/machinst/vcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ impl<I: VCodeInst> RegallocFunction for VCode<I> {

fn block_insns(&self, block: BlockIndex) -> InstRange {
let range = self.block_ranges.get(block.index());
InstRange::forward(InsnIndex::new(range.start), InsnIndex::new(range.end))
InstRange::new(InsnIndex::new(range.start), InsnIndex::new(range.end))
}

fn block_succs(&self, block: BlockIndex) -> &[BlockIndex] {
Expand Down
47 changes: 45 additions & 2 deletions cranelift/codegen/src/opts/icmp.isle
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

;; Optimize icmp-of-icmp.
;; ne(icmp(ty, cc, x, y), 0) == icmp(ty, cc, x, y)
;; e.g. neq(ugt(x, y), 0) == ugt(x, y)
;; e.g. neq(ugt(x, y), 0) == ugt(x, y)
(rule (simplify (ne ty
(uextend_maybe _ inner @ (icmp ty _ _ _))
(iconst_u _ 0)))
(subsume inner))

;; eq(icmp(ty, cc, x, y), 0) == icmp(ty, cc_complement, x, y)
;; e.g. eq(ugt(x, y), 0) == ule(x, y)
;; e.g. eq(ugt(x, y), 0) == ule(x, y)
(rule (simplify (eq ty
(uextend_maybe _ (icmp ty cc x y))
(iconst_u _ 0)))
Expand Down Expand Up @@ -213,3 +213,46 @@
(rule (intcc_class (IntCC.SignedGreaterThanOrEqual)) 2)
(rule (intcc_class (IntCC.Equal)) 3)
(rule (intcc_class (IntCC.NotEqual)) 3)

;; Pattern-match what LLVM emits today for 128-bit comparisons into actual
;; 128-bit comparisons. Platforms like x64 and aarch64 have more optimal
;; lowerings for 128-bit arithmetic than the default structure.
(rule (simplify (select ty (eq _ a_hi @ (value_type $I64) b_hi @ (value_type $I64))
(uge ty a_lo @ (value_type $I64) b_lo @ (value_type $I64))
(uge ty a_hi b_hi)))
(uge ty (iconcat $I64 a_lo a_hi) (iconcat $I64 b_lo b_hi)))

(rule (simplify (select ty (eq _ a_hi @ (value_type $I64) b_hi @ (value_type $I64))
(uge ty a_lo @ (value_type $I64) b_lo @ (value_type $I64))
(sge ty a_hi b_hi)))
(sge ty (iconcat $I64 a_lo a_hi) (iconcat $I64 b_lo b_hi)))

(rule (simplify (select ty (eq _ a_hi @ (value_type $I64) b_hi @ (value_type $I64))
(ugt ty a_lo @ (value_type $I64) b_lo @ (value_type $I64))
(ugt ty a_hi b_hi)))
(ugt ty (iconcat $I64 a_lo a_hi) (iconcat $I64 b_lo b_hi)))

(rule (simplify (select ty (eq _ a_hi @ (value_type $I64) b_hi @ (value_type $I64))
(ugt ty a_lo @ (value_type $I64) b_lo @ (value_type $I64))
(sgt ty a_hi b_hi)))
(sgt ty (iconcat $I64 a_lo a_hi) (iconcat $I64 b_lo b_hi)))

(rule (simplify (select ty (eq _ a_hi @ (value_type $I64) b_hi @ (value_type $I64))
(ule ty a_lo @ (value_type $I64) b_lo @ (value_type $I64))
(ule ty a_hi b_hi)))
(ule ty (iconcat $I64 a_lo a_hi) (iconcat $I64 b_lo b_hi)))

(rule (simplify (select ty (eq _ a_hi @ (value_type $I64) b_hi @ (value_type $I64))
(ule ty a_lo @ (value_type $I64) b_lo @ (value_type $I64))
(sle ty a_hi b_hi)))
(sle ty (iconcat $I64 a_lo a_hi) (iconcat $I64 b_lo b_hi)))

(rule (simplify (select ty (eq _ a_hi @ (value_type $I64) b_hi @ (value_type $I64))
(ult ty a_lo @ (value_type $I64) b_lo @ (value_type $I64))
(ult ty a_hi b_hi)))
(ult ty (iconcat $I64 a_lo a_hi) (iconcat $I64 b_lo b_hi)))

(rule (simplify (select ty (eq _ a_hi @ (value_type $I64) b_hi @ (value_type $I64))
(ult ty a_lo @ (value_type $I64) b_lo @ (value_type $I64))
(slt ty a_hi b_hi)))
(slt ty (iconcat $I64 a_lo a_hi) (iconcat $I64 b_lo b_hi)))
11 changes: 11 additions & 0 deletions cranelift/codegen/src/opts/selects.isle
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,14 @@
(rule (simplify (bor (ty_vec128 ty) (band ty (bnot ty c) y) (band ty x c))) (bitselect ty c x y))
(rule (simplify (bor (ty_vec128 ty) (band ty y (bnot ty c)) (band ty c x))) (bitselect ty c x y))
(rule (simplify (bor (ty_vec128 ty) (band ty y (bnot ty c)) (band ty x c))) (bitselect ty c x y))

;; Lift an extend operation outside of a `select` if the extend is happening
;; on both the consequent and the alternative.
(rule (simplify (select ty cond
(uextend ty a @ (value_type small))
(uextend ty b @ (value_type small))))
(uextend ty (select small cond a b)))
(rule (simplify (select ty cond
(sextend ty a @ (value_type small))
(sextend ty b @ (value_type small))))
(sextend ty (select small cond a b)))
22 changes: 22 additions & 0 deletions cranelift/filetests/filetests/egraph/select.clif
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,25 @@ block0(v0: i32, v1: i32):
; check: v6 = icmp sgt v0, v1
; check: v8 = bmask.i64 v6
; check: return v8

function %lift_uextend_out_of_select(i8, i32, i32) -> i64 {
block0(v0: i8, v1: i32, v2: i32):
v3 = uextend.i64 v1
v4 = uextend.i64 v2
v5 = select v0, v3, v4
return v5
}
; check: v6 = select v0, v1, v2
; check: v7 = uextend.i64 v6
; check: return v7

function %lift_sextend_out_of_select(i8, i32, i32) -> i64 {
block0(v0: i8, v1: i32, v2: i32):
v3 = sextend.i64 v1
v4 = sextend.i64 v2
v5 = select v0, v3, v4
return v5
}
; check: v6 = select v0, v1, v2
; check: v7 = sextend.i64 v6
; check: return v7
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ block0(v0: i64):
; stp fp, lr, [sp, #-16]!
; mov fp, sp
; block0:
; mov x0, x2
; load_ext_name x3, TestCase(%g)+0
; mov x0, x2
; blr x3
; mov x2, x0
; ldp fp, lr, [sp], #16
Expand All @@ -76,11 +76,11 @@ block0(v0: i64):
; stp x29, x30, [sp, #-0x10]!
; mov x29, sp
; block1: ; offset 0xc
; mov x0, x2
; ldr x3, #0x18
; b #0x20
; ldr x3, #0x14
; b #0x1c
; .byte 0x00, 0x00, 0x00, 0x00 ; reloc_external Abs8 %g 0
; .byte 0x00, 0x00, 0x00, 0x00
; mov x0, x2
; blr x3
; mov x2, x0
; ldp x29, x30, [sp], #0x10
Expand Down
8 changes: 4 additions & 4 deletions cranelift/filetests/filetests/isa/aarch64/call-pauth.clif
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ block0(v0: i64):
; stp fp, lr, [sp, #-16]!
; mov fp, sp
; block0:
; mov x0, x2
; load_ext_name x3, TestCase(%g)+0
; mov x0, x2
; blr x3
; mov x2, x0
; ldp fp, lr, [sp], #16
Expand All @@ -77,11 +77,11 @@ block0(v0: i64):
; stp x29, x30, [sp, #-0x10]!
; mov x29, sp
; block1: ; offset 0xc
; mov x0, x2
; ldr x3, #0x18
; b #0x20
; ldr x3, #0x14
; b #0x1c
; .byte 0x00, 0x00, 0x00, 0x00 ; reloc_external Abs8 %g 0
; .byte 0x00, 0x00, 0x00, 0x00
; mov x0, x2
; blr x3
; mov x2, x0
; ldp x29, x30, [sp], #0x10
Expand Down
Loading

0 comments on commit 2fd06af

Please sign in to comment.