Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cranelift/codegen/src/opts/selects.isle
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
;; `select`/`bitselect`-related rewrites

;; remove select when both choices are the same
(rule (simplify (select ty _ x x)) x)
(rule (simplify (bitselect ty _ x x)) x)

;; Transform select-of-icmp into {u,s}{min,max} instructions where possible.
(rule (simplify (select ty (sgt _ x y) x y)) (smax ty x y))
(rule (simplify (select ty (sge _ x y) x y)) (smax ty x y))
Expand Down
14 changes: 14 additions & 0 deletions cranelift/filetests/filetests/egraph/select.clif
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ target aarch64
target s390x
target riscv64

function %select_self(i8, i32) -> i32 {
block0(v0: i8, v1: i32):
v2 = select v0, v1, v1
return v2
; check: return v1
}

function %bitselect_self(i32, i32) -> i32 {
block0(v0: i32, v1: i32):
v2 = bitselect v0, v1, v1
return v2
; check: return v1
}

function %select_sgt_to_smax(i32, i32) -> i32 {
block0(v0: i32, v1: i32):
v2 = icmp sgt v0, v1
Expand Down