[llvm] [RISCV][GISel] Lower G_SADDE (PR #156865)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 10 10:02:06 PDT 2025


================
@@ -9298,6 +9300,28 @@ LegalizerHelper::lowerSADDO_SSUBO(MachineInstr &MI) {
   return Legalized;
 }
 
+LegalizerHelper::LegalizeResult LegalizerHelper::lowerSADDE(MachineInstr &MI) {
+  auto [Res, OvOut, LHS, RHS, CarryIn] = MI.getFirst5Regs();
+  const LLT Ty = MRI.getType(Res);
+
+  // sum = LHS + RHS + zext(CarryIn)
+  auto Tmp = MIRBuilder.buildAdd(Ty, LHS, RHS);
+  auto CarryZ = MIRBuilder.buildZExt(Ty, CarryIn);
+  auto Sum = MIRBuilder.buildAdd(Ty, Tmp, CarryZ);
+  MIRBuilder.buildCopy(Res, Sum);
----------------
topperc wrote:

Or maybe we can't. Looks like G_UADDO uses a copy but G_SSUBO doesn't. The difference is that G_UADDO needs to use the result to calculate the carry, but G_SSUBO doesn't.

https://github.com/llvm/llvm-project/pull/156865


More information about the llvm-commits mailing list