From 5b69930e03dc67b65777ba3f98f088ec0fca7d81 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sat, 5 May 2018 11:01:49 -0500 Subject: [PATCH] Legalize bnot using xor with -1. --- cranelift/filetests/isa/riscv/expand-i32.cton | 3 ++- lib/codegen/meta/base/legalize.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cranelift/filetests/isa/riscv/expand-i32.cton b/cranelift/filetests/isa/riscv/expand-i32.cton index 890352e72f..30048622ca 100644 --- a/cranelift/filetests/isa/riscv/expand-i32.cton +++ b/cranelift/filetests/isa/riscv/expand-i32.cton @@ -32,7 +32,8 @@ ebb0(v0: i32): function %bitclear(i32, i32) -> i32 { ebb0(v0: i32, v1: i32): v2 = band_not v0, v1 - ; check: bnot + ; check: iconst.i32 -1 + ; check: bxor ; check: band return v2 } diff --git a/lib/codegen/meta/base/legalize.py b/lib/codegen/meta/base/legalize.py index 95a58987d3..0a7e8ea7b3 100644 --- a/lib/codegen/meta/base/legalize.py +++ b/lib/codegen/meta/base/legalize.py @@ -252,6 +252,14 @@ for inst_not, inst in [ a << inst(x, a1) )) +# Expand bnot using xor. +expand.legalize( + a << bnot(x), + Rtl( + y << iconst(imm64(-1)), + a << bxor(x, y) + )) + # Floating-point sign manipulations. for ty, minus_zero in [ (types.f32, f32const(ieee32.bits(0x80000000))),