For the following code, the generated adc and add instructions can be combined into a single adc instruction.
Compiler explorer: https://godbolt.org/z/95v4x53Ef
define i32 @test(i32 %0, i32 %1, i32 %2) {
%4 = icmp ult i32 %0, %1
%5 = zext i1 %4 to i32
%6 = add i32 %2, 42
%7 = add i32 %6, %5
%8 = icmp slt i32 %7, 0
%9 = select i1 %8, i32 %1, i32 %0
ret i32 %9
}
Output:
test:
mov eax, edi
cmp edi, esi
adc edx, 0
add edx, 42
cmovs eax, esi
ret
Expected:
test:
mov eax, edi
cmp edi, esi
adc edx, 42
cmovs eax, esi
ret