--- /dev/null
+// PR middle-end/79173
+// { dg-do compile { target c++11 } }
+// { dg-options "-O2 -fno-stack-protector -masm=att" }
+// { dg-final { scan-assembler-times "addq\t%r\[^\n\r]*, \\\(%rdi\\\)" 1 { target lp64 } } }
+// { dg-final { scan-assembler-times "adcq\t%r\[^\n\r]*, 8\\\(%rdi\\\)" 1 { target lp64 } } }
+// { dg-final { scan-assembler-times "adcq\t%r\[^\n\r]*, 16\\\(%rdi\\\)" 1 { target lp64 } } }
+// { dg-final { scan-assembler-times "adcq\t%r\[^\n\r]*, 24\\\(%rdi\\\)" 1 { target lp64 } } }
+// { dg-final { scan-assembler-times "addl\t%e\[^\n\r]*, \\\(%e\[^\n\r]*\\\)" 1 { target ia32 } } }
+// { dg-final { scan-assembler-times "adcl\t%e\[^\n\r]*, 4\\\(%e\[^\n\r]*\\\)" 1 { target ia32 } } }
+// { dg-final { scan-assembler-times "adcl\t%e\[^\n\r]*, 8\\\(%e\[^\n\r]*\\\)" 1 { target ia32 } } }
+// { dg-final { scan-assembler-times "adcl\t%e\[^\n\r]*, 12\\\(%e\[^\n\r]*\\\)" 1 { target ia32 } } }
+
+template <typename T>
+inline constexpr T
+uaddc (T x, T y, T carry_in, T &carry_out) noexcept
+{
+ [[gnu::assume (carry_in <= 1)]];
+ x += y;
+ carry_out = x < y;
+ x += carry_in;
+ carry_out += x < carry_in;
+ return x;
+}
+
+void
+foo (unsigned long *p, unsigned long *q)
+{
+ unsigned long c;
+ p[0] = uaddc (p[0], q[0], 0UL, c);
+ p[1] = uaddc (p[1], q[1], c, c);
+ p[2] = uaddc (p[2], q[2], c, c);
+ p[3] = uaddc (p[3], q[3], c, c);
+}
if (!types_compatible_p (type, TREE_TYPE (arg1)))
return false;
int kind[2] = { 0, 0 };
+ tree arg_im[2] = { NULL_TREE, NULL_TREE };
/* At least one of arg2 and arg3 should have type compatible
with arg1/rhs[0], and the other one should have value in [0, 1]
range. If both are in [0, 1] range and type compatible with
g = uaddc_ne0 (g);
if (!uaddc_is_cplxpart (g, IMAGPART_EXPR))
continue;
+ arg_im[i] = gimple_assign_lhs (g);
g = SSA_NAME_DEF_STMT (TREE_OPERAND (gimple_assign_rhs1 (g), 0));
if (!is_gimple_call (g) || !gimple_call_internal_p (g))
continue;
{
std::swap (arg2, arg3);
std::swap (kind[0], kind[1]);
+ std::swap (arg_im[0], arg_im[1]);
}
if ((kind[0] & 1) == 0 || (kind[1] & 6) == 0)
return false;
/* Build .UADDC/.USUBC call which will be placed before the stmt. */
gimple_stmt_iterator gsi2 = gsi_for_stmt (ovf2);
gimple *g;
+ if ((kind[1] & 4) != 0 && types_compatible_p (type, TREE_TYPE (arg_im[1])))
+ arg3 = arg_im[1];
if ((kind[1] & 1) == 0)
{
if (TREE_CODE (arg3) == INTEGER_CST)