[PATCH] D125130: [CodeGen] Clarify the semantics of ADDCARRY/SUBCARRY

Kazu Hirata via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat May 7 13:15:54 PDT 2022


kazu updated this revision to Diff 427892.
kazu added a comment.

Included a comparison to [US]{ADD,SUB}O.

Split the description to several paragraphs, separating the definition
proper and supplemental information.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125130

Files:
  llvm/include/llvm/CodeGen/ISDOpcodes.h


Index: llvm/include/llvm/CodeGen/ISDOpcodes.h
===================================================================
--- llvm/include/llvm/CodeGen/ISDOpcodes.h
+++ llvm/include/llvm/CodeGen/ISDOpcodes.h
@@ -281,12 +281,25 @@
 
   /// Carry-using nodes for multiple precision addition and subtraction.
   /// These nodes take three operands: The first two are the normal lhs and
-  /// rhs to the add or sub, and the third is a boolean indicating if there
-  /// is an incoming carry. These nodes produce two results: the normal
-  /// result of the add or sub, and the output carry so they can be chained
-  /// together. The use of this opcode is preferable to adde/sube if the
-  /// target supports it, as the carry is a regular value rather than a
-  /// glue, which allows further optimisation.
+  /// rhs to the add or sub, and the third is a boolean value that is 1 if and
+  /// only if there is an incoming carry/borrow. These nodes produce two
+  /// results: the normal result of the add or sub, and a boolean value that is
+  /// 1 if and only if there is an outgoing carry/borrow.
+  ///
+  /// Care must be taken if these opcodes are lowered to hardware instructions
+  /// that use the inverse logic -- 0 if and only if there is an
+  /// incoming/outgoing carry/borrow.  In such cases, you must preserve the
+  /// semantcis of these opcodes by inverting the incoming carry/borrow, feeding
+  /// it to the sub/add hardware instruction, and then inverting the outgoing
+  /// carry/borrow.
+  ///
+  /// The use of these opcodes is preferable to adde/sube if the target supports
+  /// it, as the carry is a regular value rather than a glue, which allows
+  /// further optimisation.
+  ///
+  /// These opcodes are different from [US]{ADD,SUB}O in that ADDCARRY/SUBCARRY
+  /// consume and produce a carry/borrow, whereas [US]{ADD,SUB}O produce an
+  /// overflow.
   ADDCARRY,
   SUBCARRY,
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125130.427892.patch
Type: text/x-patch
Size: 1907 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220507/4f214493/attachment.bin>


More information about the llvm-commits mailing list