[PATCH] D62266: [DAGCombine][X86][AArch64][ARM] (C - x) + y -> (y - x) + C fold

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 24 07:44:38 PDT 2019


lebedev.ri added a comment.

In D62266#1514711 <https://reviews.llvm.org/D62266#1514711>, @efriedma wrote:

> > Are you saying that the following transform should be performed: (sub Carry, X) -> (addcarry (sub 0, X), 0, !Carry)?
>
> The correct transform is `(sub Carry, X) -> (add Carry, (sub 0, X)) -> (addcarry (sub 0, X), 0, Carry)`, no "!".


Oh right, i think i may have mistyped here. D62392 <https://reviews.llvm.org/D62392>

> Sorry, I wasn't really clear; the carry bit doesn't need to be inverted in target-independent code.  It's just that on ARM, "subs"/"sbcs" produce a carry bit which has the opposite meaning of the "overflow" bit from usubo, and "sbc(s)" consumes a carry bit that's inverted from the carry bit operand of subcarry. If the result of a usubo is consumed by a subcarry, the two inversions cancel; otherwise, we need to transfer the the carry bit to a GPR, invert it, then transfer it back to the flags register.  (Maybe this could be optimized a bit in certain cases, but it doesn't really optimize in general.)

Thanks! That helps improves half of the cases (although still regressed as compared to LHS of this diff).


Repository:
  rL LLVM

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

https://reviews.llvm.org/D62266





More information about the llvm-commits mailing list