From 8383e4b6bd14329cab97314cd5275f62235ee7f0 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Wed, 14 Dec 2022 11:50:42 -0800 Subject: [PATCH] egraph opt rules: do `(icmp cc x x) == {0,1}` only for integer types. (#5438) We could do these for vectors too, in theory, but for now let's fix the bug by applying the equivalence only for integer types. Fixes #5437. --- cranelift/codegen/src/opts/algebraic.isle | 20 ++++----- .../filetests/egraph/issue-5437.clif | 41 +++++++++++++++++++ 2 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 cranelift/filetests/filetests/egraph/issue-5437.clif diff --git a/cranelift/codegen/src/opts/algebraic.isle b/cranelift/codegen/src/opts/algebraic.isle index d407474131..9262b1b657 100644 --- a/cranelift/codegen/src/opts/algebraic.isle +++ b/cranelift/codegen/src/opts/algebraic.isle @@ -211,32 +211,32 @@ ;; `x == x` is always true for integers; `x != x` is false. Strict ;; inequalities are false, and loose inequalities are true. (rule (simplify - (icmp ty (IntCC.Equal) x x)) + (icmp (ty_int ty) (IntCC.Equal) x x)) (iconst ty (imm64 1))) (rule (simplify - (icmp ty (IntCC.NotEqual) x x)) + (icmp (ty_int ty) (IntCC.NotEqual) x x)) (iconst ty (imm64 0))) (rule (simplify - (icmp ty (IntCC.UnsignedGreaterThan) x x)) + (icmp (ty_int ty) (IntCC.UnsignedGreaterThan) x x)) (iconst ty (imm64 0))) (rule (simplify - (icmp ty (IntCC.UnsignedGreaterThanOrEqual) x x)) + (icmp (ty_int ty) (IntCC.UnsignedGreaterThanOrEqual) x x)) (iconst ty (imm64 1))) (rule (simplify - (icmp ty (IntCC.SignedGreaterThan) x x)) + (icmp (ty_int ty) (IntCC.SignedGreaterThan) x x)) (iconst ty (imm64 0))) (rule (simplify - (icmp ty (IntCC.SignedGreaterThanOrEqual) x x)) + (icmp (ty_int ty) (IntCC.SignedGreaterThanOrEqual) x x)) (iconst ty (imm64 1))) (rule (simplify - (icmp ty (IntCC.UnsignedLessThan) x x)) + (icmp (ty_int ty) (IntCC.UnsignedLessThan) x x)) (iconst ty (imm64 0))) (rule (simplify - (icmp ty (IntCC.UnsignedLessThanOrEqual) x x)) + (icmp (ty_int ty) (IntCC.UnsignedLessThanOrEqual) x x)) (iconst ty (imm64 1))) (rule (simplify - (icmp ty (IntCC.SignedLessThan) x x)) + (icmp (ty_int ty) (IntCC.SignedLessThan) x x)) (iconst ty (imm64 0))) (rule (simplify - (icmp ty (IntCC.SignedLessThanOrEqual) x x)) + (icmp (ty_int ty) (IntCC.SignedLessThanOrEqual) x x)) (iconst ty (imm64 1))) diff --git a/cranelift/filetests/filetests/egraph/issue-5437.clif b/cranelift/filetests/filetests/egraph/issue-5437.clif new file mode 100644 index 0000000000..b8eb3c938b --- /dev/null +++ b/cranelift/filetests/filetests/egraph/issue-5437.clif @@ -0,0 +1,41 @@ +test compile +set use_egraphs=true +target x86_64 +target aarch64 +target s390x + +function u0:0(i64 vmctx, i64) fast { + gv0 = vmctx + gv1 = load.i64 notrap aligned readonly gv0+8 + gv2 = load.i64 notrap aligned gv1 + sig0 = (i64 vmctx, i64) fast + fn0 = colocated u0:2 sig0 + jt0 = jump_table [block1] + stack_limit = gv2 + + block0(v0: i64, v1: i64): +@0019 v2 = vconst.i8x16 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] +@001b v3 = iconst.i32 0 +@001d brz v3, block2 ; v3 = 0 +@001d jump block3 + + block3: +@001f trap unreachable + + block2: +@0025 v4 = bitcast.i16x8 little v2 ; v2 = const0 +@0025 v5 = bitcast.i16x8 little v2 ; v2 = const0 +@0025 v6 = icmp ult v4, v5 +@0027 v7 = bitcast.i32x4 little v6 +@0027 v8 = vhigh_bits.i32 v7 +@002a v9 = iconst.i32 0 +@002c brnz v9, block1 ; v9 = 0 +@002c jump block4 + + block4: +@002e call fn0(v0, v0) +@0030 br_table v8, block1, jt0 + + block1: +@0036 return +}