[PATCH] D32756: [DAGCombine] Refactor common addcarry pattern.

Amaury SECHET via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 5 06:38:28 PDT 2017


deadalnix added inline comments.


================
Comment at: lib/CodeGen/SelectionDAG/DAGCombiner.cpp:2169
+  // With Y = (uaddo A, B)
+  if (N1.getOpcode() == ISD::ADDCARRY &&
+      isNullConstant(N1.getOperand(0)) &&
----------------
RKSimon wrote:
> This comment really isn't any use to explain what is happening here - it needs a much better explanation.
> 
> AFAICT you are saying that if (A+B) overflows then the carry can only occur in the second operand, else if (A+B) doesn't overflow it might occur in the third (carry) operand after the additional add? Can carries ever occur in both? e.g. Is addcarry/uaddo supposed to accept for i1/i2 types?
That is the idea. If A + B overflows, then Y + [0 or 1] cannot overflow. As a result, you can combine the two carries into one by doing A + B + [0 or 1]. This holds true even for types like i1, however, addcarry are generated by the legalization code, so you shouldn't get i1 in there anyway.

This transform a diamond pattern into the carry chain into a linear carry chain, and then other existing optimizations can kick in.


https://reviews.llvm.org/D32756





More information about the llvm-commits mailing list