@@ -10905,9 +10905,12 @@ SDValue DAGCombiner::foldABSToABD(SDNode *N) {
10905
10905
Op1 = AbsOp1.getOperand(1);
10906
10906
10907
10907
unsigned Opc0 = Op0.getOpcode();
10908
+
10908
10909
// Check if the operands of the sub are (zero|sign)-extended.
10910
+ // TODO: Should we use ValueTracking instead?
10909
10911
if (Opc0 != Op1.getOpcode() ||
10910
- (Opc0 != ISD::ZERO_EXTEND && Opc0 != ISD::SIGN_EXTEND)) {
10912
+ (Opc0 != ISD::ZERO_EXTEND && Opc0 != ISD::SIGN_EXTEND &&
10913
+ Opc0 != ISD::SIGN_EXTEND_INREG)) {
10911
10914
// fold (abs (sub nsw x, y)) -> abds(x, y)
10912
10915
if (AbsOp1->getFlags().hasNoSignedWrap() && hasOperation(ISD::ABDS, VT) &&
10913
10916
TLI.preferABDSToABSWithNSW(VT)) {
@@ -10917,9 +10920,15 @@ SDValue DAGCombiner::foldABSToABD(SDNode *N) {
10917
10920
return SDValue();
10918
10921
}
10919
10922
10920
- EVT VT0 = Op0.getOperand(0).getValueType();
10921
- EVT VT1 = Op1.getOperand(0).getValueType();
10922
- unsigned ABDOpcode = (Opc0 == ISD::SIGN_EXTEND) ? ISD::ABDS : ISD::ABDU;
10923
+ EVT VT0, VT1;
10924
+ if (Opc0 == ISD::SIGN_EXTEND_INREG) {
10925
+ VT0 = cast<VTSDNode>(Op0.getOperand(1))->getVT();
10926
+ VT1 = cast<VTSDNode>(Op1.getOperand(1))->getVT();
10927
+ } else {
10928
+ VT0 = Op0.getOperand(0).getValueType();
10929
+ VT1 = Op1.getOperand(0).getValueType();
10930
+ }
10931
+ unsigned ABDOpcode = (Opc0 == ISD::ZERO_EXTEND) ? ISD::ABDU : ISD::ABDS;
10923
10932
10924
10933
// fold abs(sext(x) - sext(y)) -> zext(abds(x, y))
10925
10934
// fold abs(zext(x) - zext(y)) -> zext(abdu(x, y))
0 commit comments