[PATCH] D128123: [SDAG] try to replace subtract-from-constant with xor

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 12 08:49:19 PDT 2022


foad added a comment.

In D128123#3645270 <https://reviews.llvm.org/D128123#3645270>, @spatel wrote:

>   +  // If there's no chance any bit will need to borrow from an adjacent bit:
>   +  // sub C, X --> xor X, C
>   +  // Avoid this fold if the sub has no-wrap flags because that could be an
>   +  // information-losing transform that we cannot recover from.
>   +  const APInt *Op0C;
>   +  if (!I.hasNoSignedWrap() && !I.hasNoUnsignedWrap() &&
>   +      match(Op0, m_APInt(Op0C)) &&
>   +      (~computeKnownBits(Op1, 0, &I).Zero).isSubsetOf(*Op0C))
>   +    return BinaryOperator::CreateXor(Op1, Op0);

If there's no chance any bit will need to borrow from an adjacent bit then there is no unsigned wrap by definition, so I'm not sure losing the nuw flag would actually lose any information.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128123



More information about the llvm-commits mailing list