[PATCH] D99171: [WebAssembly] Fold xor by inverting branch target

Alon Zakai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 23 19:57:16 PDT 2021


kripken added inline comments.


================
Comment at: llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td:33
           (BR_UNLESS bb_op:$dst, I32:$cond)>;
+def : Pat<(brcond (i32 (xor I32:$cond, (i32 1))), bb:$dst),
+          (BR_UNLESS bb_op:$dst, I32:$cond)>;
----------------
samparker wrote:
> Ah, I've remembered that I thought I should check that the incoming I32 is indeed a boolean value.
Yes, this seems like a valid pattern for any boolean value, not just one flowing into a br? That is,

bool(x) ^ 1   =>   !bool(x)

or in wasm

(i32.xor X (i32.const 1))   =>   (i32.eqz X)



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99171/new/

https://reviews.llvm.org/D99171



More information about the llvm-commits mailing list