Skip to content

Commit de41396

Browse files
committed
[DAG] foldABSToABD - add support for abs(sub(sign_extend_inreg(),sign_extend_inreg())) patterns
Partial fix for ABDS regressions on D152928
1 parent 9180b9f commit de41396

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10905,9 +10905,12 @@ SDValue DAGCombiner::foldABSToABD(SDNode *N) {
1090510905
Op1 = AbsOp1.getOperand(1);
1090610906

1090710907
unsigned Opc0 = Op0.getOpcode();
10908+
1090810909
// Check if the operands of the sub are (zero|sign)-extended.
10910+
// TODO: Should we use ValueTracking instead?
1090910911
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)) {
1091110914
// fold (abs (sub nsw x, y)) -> abds(x, y)
1091210915
if (AbsOp1->getFlags().hasNoSignedWrap() && hasOperation(ISD::ABDS, VT) &&
1091310916
TLI.preferABDSToABSWithNSW(VT)) {
@@ -10917,9 +10920,15 @@ SDValue DAGCombiner::foldABSToABD(SDNode *N) {
1091710920
return SDValue();
1091810921
}
1091910922

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;
1092310932

1092410933
// fold abs(sext(x) - sext(y)) -> zext(abds(x, y))
1092510934
// fold abs(zext(x) - zext(y)) -> zext(abdu(x, y))

llvm/test/CodeGen/Thumb2/mve-vabdus.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ define arm_aapcs_vfpcc <4 x i8> @vabd_v4s8(<4 x i8> %src1, <4 x i8> %src2) {
4040
; CHECK-NEXT: vmovlb.s8 q0, q0
4141
; CHECK-NEXT: vmovlb.s16 q1, q1
4242
; CHECK-NEXT: vmovlb.s16 q0, q0
43-
; CHECK-NEXT: vsub.i32 q0, q0, q1
44-
; CHECK-NEXT: vabs.s32 q0, q0
43+
; CHECK-NEXT: vabd.s32 q0, q0, q1
4544
; CHECK-NEXT: bx lr
4645
%sextsrc1 = sext <4 x i8> %src1 to <4 x i16>
4746
%sextsrc2 = sext <4 x i8> %src2 to <4 x i16>

0 commit comments

Comments
 (0)