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

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 23 20:40:04 PDT 2021


craig.topper 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)>;
----------------
tlively wrote:
> kripken wrote:
> > 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)
> > 
> Is there a good way to check for boolean values from tablegen patterns?
You'd need to use a PatFrag to call computeKnownBits I think.


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