SDValue RHS = N->getOperand(1);
SDValue CarryIn = N->getOperand(2);
+ // Canonicalize constant to RHS.
+ if (isa<ConstantSDNode>(LHS) && !isa<ConstantSDNode>(RHS))
+ return DAG.getNode(X86ISD::ADC, SDLoc(N), N->getVTList(), RHS, LHS,
+ CarryIn);
+
// If the LHS and RHS of the ADC node are zero, then it can't overflow and
// the result is either zero or one (depending on the input carry bit).
// Strength reduce this down to a "set on carry" aka SETCC_CARRY&1.
}
}
+ // Fold ADD(ADC(Y,0,W),X) -> ADC(X,Y,W)
+ if (Op0.getOpcode() == X86ISD::ADC && Op0->hasOneUse() &&
+ X86::isZeroNode(Op0.getOperand(1))) {
+ assert(!Op0->hasAnyUseOfValue(1) && "Overflow bit in use");
+ return DAG.getNode(X86ISD::ADC, SDLoc(Op0), Op0->getVTList(), Op1,
+ Op0.getOperand(0), Op0.getOperand(2));
+ }
+
return combineAddOrSubToADCOrSBB(N, DAG);
}
ret <4 x i32> %r
}
-; FIXME: Fold to adc $32, %edi
define i32 @combine_add_adc_constant(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: combine_add_adc_constant:
; CHECK: # %bb.0:
-; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
+; CHECK-NEXT: movl %edi, %eax
; CHECK-NEXT: btl $7, %edx
-; CHECK-NEXT: adcl $0, %edi
-; CHECK-NEXT: leal 32(%rdi), %eax
+; CHECK-NEXT: adcl $32, %eax
; CHECK-NEXT: retq
%and = lshr i32 %z, 7
%bit = and i32 %and, 1