[PATCH] D112085: [DAGCombiner] fold bit-hack form of usubsat

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 22 08:11:03 PDT 2021


spatel added inline comments.


================
Comment at: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:5653
+
+  // (i8 X ^ 128) & (i8 X s>> 7) --> usubsat X, 128
+  SDLoc DL(N);
----------------
RKSimon wrote:
> foad wrote:
> > What about the same thing with X +/- 128 instead of X ^ 128? Do they already get canonicalized to the XOR version?
> I think instcombine will have canonicalized them: https://alive2.llvm.org/ce/z/n2TfRo
Yes, instcombine will convert the math op to logic op. But this is an interesting question for codegen because one form may be better than the other depending on target.

For example on x86 we get these variants:
  leal	-2147483648(%rdi), %eax
vs.
  movl	%edi, %eax
  xorl	$-2147483648, %eax              ## imm = 0x80000000

...while on aarch64:
  mov	w8, #-2147483648
  add	w0, w0, w8
vs.
  eor	w0, w0, #0x80000000

Also, this patch is part of a chain that eventually leads back to a question about whether instcombine is canonicalizing or even can (in case of extra uses) canonicalize to a form that is consistent (we do form usubsat in IR sometimes, but we're missing patterns as shown in this patch).

So I think it's not a stretch to make the match more flexible in this fold...gives us some protection in case code outside of here decides to do things differently in the future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112085



More information about the llvm-commits mailing list