ISLE: rewrite and/or of icmp (#6095)
* ISLE: rewrite `and`/`or` of `icmp` * Add `make-icmp-tests.sh` script * Remove unused changes
This commit is contained in:
@@ -479,6 +479,56 @@
|
||||
(iconst _ (u64_from_imm64 0))))
|
||||
(iconst ty (imm64 1)))
|
||||
|
||||
(decl pure decompose_intcc (IntCC) u64)
|
||||
(rule (decompose_intcc (IntCC.Equal)) 1)
|
||||
(rule (decompose_intcc (IntCC.UnsignedLessThan)) 2)
|
||||
(rule (decompose_intcc (IntCC.SignedLessThan)) 2)
|
||||
(rule (decompose_intcc (IntCC.UnsignedLessThanOrEqual)) 3)
|
||||
(rule (decompose_intcc (IntCC.SignedLessThanOrEqual)) 3)
|
||||
(rule (decompose_intcc (IntCC.UnsignedGreaterThan)) 4)
|
||||
(rule (decompose_intcc (IntCC.SignedGreaterThan)) 4)
|
||||
(rule (decompose_intcc (IntCC.UnsignedGreaterThanOrEqual)) 5)
|
||||
(rule (decompose_intcc (IntCC.SignedGreaterThanOrEqual)) 5)
|
||||
(rule (decompose_intcc (IntCC.NotEqual)) 6)
|
||||
|
||||
(decl compose_icmp (Type u64 bool Value Value) Value)
|
||||
(rule (compose_icmp ty 0 _ _ _) (subsume (iconst ty (imm64 0))))
|
||||
(rule (compose_icmp ty 1 _ x y) (icmp ty (IntCC.Equal) x y))
|
||||
(rule (compose_icmp ty 2 $false x y) (icmp ty (IntCC.UnsignedLessThan) x y))
|
||||
(rule (compose_icmp ty 2 $true x y) (icmp ty (IntCC.SignedLessThan) x y))
|
||||
(rule (compose_icmp ty 3 $false x y) (icmp ty (IntCC.UnsignedLessThanOrEqual) x y))
|
||||
(rule (compose_icmp ty 3 $true x y) (icmp ty (IntCC.SignedLessThanOrEqual) x y))
|
||||
(rule (compose_icmp ty 4 $false x y) (icmp ty (IntCC.UnsignedGreaterThan) x y))
|
||||
(rule (compose_icmp ty 4 $true x y) (icmp ty (IntCC.SignedGreaterThan) x y))
|
||||
(rule (compose_icmp ty 5 $false x y) (icmp ty (IntCC.UnsignedGreaterThanOrEqual) x y))
|
||||
(rule (compose_icmp ty 5 $true x y) (icmp ty (IntCC.SignedGreaterThanOrEqual) x y))
|
||||
(rule (compose_icmp ty 6 _ x y) (icmp ty (IntCC.NotEqual) x y))
|
||||
(rule (compose_icmp ty 7 _ _ _) (subsume (iconst ty (imm64 1))))
|
||||
|
||||
(decl pure intcc_class (IntCC) u64)
|
||||
(rule (intcc_class (IntCC.UnsignedLessThan)) 1)
|
||||
(rule (intcc_class (IntCC.UnsignedLessThanOrEqual)) 1)
|
||||
(rule (intcc_class (IntCC.UnsignedGreaterThan)) 1)
|
||||
(rule (intcc_class (IntCC.UnsignedGreaterThanOrEqual)) 1)
|
||||
(rule (intcc_class (IntCC.SignedLessThan)) 2)
|
||||
(rule (intcc_class (IntCC.SignedLessThanOrEqual)) 2)
|
||||
(rule (intcc_class (IntCC.SignedGreaterThan)) 2)
|
||||
(rule (intcc_class (IntCC.SignedGreaterThanOrEqual)) 2)
|
||||
(rule (intcc_class (IntCC.Equal)) 3)
|
||||
(rule (intcc_class (IntCC.NotEqual)) 3)
|
||||
|
||||
(decl pure partial intcc_comparable (IntCC IntCC) bool)
|
||||
(rule (intcc_comparable x y)
|
||||
(if-let (u64_nonzero class) (u64_and (intcc_class x) (intcc_class y)))
|
||||
(u64_eq 2 class))
|
||||
|
||||
(rule (simplify (band ty (icmp ty cc1 x y) (icmp ty cc2 x y)))
|
||||
(if-let signed (intcc_comparable cc1 cc2))
|
||||
(compose_icmp ty (u64_and (decompose_intcc cc1) (decompose_intcc cc2)) signed x y))
|
||||
|
||||
(rule (simplify (bor ty (icmp ty cc1 x y) (icmp ty cc2 x y)))
|
||||
(if-let signed (intcc_comparable cc1 cc2))
|
||||
(compose_icmp ty (u64_or (decompose_intcc cc1) (decompose_intcc cc2)) signed x y))
|
||||
|
||||
;; 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))
|
||||
|
||||
3010
cranelift/filetests/filetests/egraph/icmp.clif
Normal file
3010
cranelift/filetests/filetests/egraph/icmp.clif
Normal file
File diff suppressed because it is too large
Load Diff
38
cranelift/filetests/filetests/egraph/make-icmp-tests.sh
Executable file
38
cranelift/filetests/filetests/egraph/make-icmp-tests.sh
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
cd $(dirname "$0")
|
||||
out=icmp.clif
|
||||
CCS="eq ne ult ule ugt uge slt sle sgt sge"
|
||||
|
||||
function main {
|
||||
cat << EOF > $out
|
||||
test optimize precise-output
|
||||
set opt_level=speed
|
||||
set use_egraphs=true
|
||||
target x86_64
|
||||
|
||||
;; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
;; !!! GENERATED BY 'make-icmp-tests.sh' DO NOT EDIT !!!
|
||||
;; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
;; run with the 'CRANELIFT_TEST_BLESS=1' env var set to update this file
|
||||
|
||||
EOF
|
||||
for op in "and" "or"; do
|
||||
for cc1 in $CCS; do
|
||||
for cc2 in $CCS; do
|
||||
cat << EOF >> $out
|
||||
function %icmp_${op}_${cc1}_${cc2}(i32, i32) -> i8 {
|
||||
block0(v0: i32, v1: i32):
|
||||
v2 = icmp ${cc1} v0, v1
|
||||
v3 = icmp ${cc2} v0, v1
|
||||
v4 = b${op} v2, v3
|
||||
return v4
|
||||
}
|
||||
EOF
|
||||
done
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
main
|
||||
Reference in New Issue
Block a user