[llvm] de41396 - [DAG] foldABSToABD - add support for abs(sub(sign_extend_inreg(),sign_extend_inreg())) patterns
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 15 07:49:52 PST 2023
Author: Simon Pilgrim
Date: 2023-11-15T15:49:30Z
New Revision: de4139689519572b789b345ef1030d0f5aa5ac38
URL: https://github.com/llvm/llvm-project/commit/de4139689519572b789b345ef1030d0f5aa5ac38
DIFF: https://github.com/llvm/llvm-project/commit/de4139689519572b789b345ef1030d0f5aa5ac38.diff
LOG: [DAG] foldABSToABD - add support for abs(sub(sign_extend_inreg(),sign_extend_inreg())) patterns
Partial fix for ABDS regressions on D152928
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/Thumb2/mve-vabdus.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index b32e630e8e48584..c2d5b40ee72510c 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -10905,9 +10905,12 @@ SDValue DAGCombiner::foldABSToABD(SDNode *N) {
Op1 = AbsOp1.getOperand(1);
unsigned Opc0 = Op0.getOpcode();
+
// Check if the operands of the sub are (zero|sign)-extended.
+ // TODO: Should we use ValueTracking instead?
if (Opc0 != Op1.getOpcode() ||
- (Opc0 != ISD::ZERO_EXTEND && Opc0 != ISD::SIGN_EXTEND)) {
+ (Opc0 != ISD::ZERO_EXTEND && Opc0 != ISD::SIGN_EXTEND &&
+ Opc0 != ISD::SIGN_EXTEND_INREG)) {
// fold (abs (sub nsw x, y)) -> abds(x, y)
if (AbsOp1->getFlags().hasNoSignedWrap() && hasOperation(ISD::ABDS, VT) &&
TLI.preferABDSToABSWithNSW(VT)) {
@@ -10917,9 +10920,15 @@ SDValue DAGCombiner::foldABSToABD(SDNode *N) {
return SDValue();
}
- EVT VT0 = Op0.getOperand(0).getValueType();
- EVT VT1 = Op1.getOperand(0).getValueType();
- unsigned ABDOpcode = (Opc0 == ISD::SIGN_EXTEND) ? ISD::ABDS : ISD::ABDU;
+ EVT VT0, VT1;
+ if (Opc0 == ISD::SIGN_EXTEND_INREG) {
+ VT0 = cast<VTSDNode>(Op0.getOperand(1))->getVT();
+ VT1 = cast<VTSDNode>(Op1.getOperand(1))->getVT();
+ } else {
+ VT0 = Op0.getOperand(0).getValueType();
+ VT1 = Op1.getOperand(0).getValueType();
+ }
+ unsigned ABDOpcode = (Opc0 == ISD::ZERO_EXTEND) ? ISD::ABDU : ISD::ABDS;
// fold abs(sext(x) - sext(y)) -> zext(abds(x, y))
// fold abs(zext(x) - zext(y)) -> zext(abdu(x, y))
diff --git a/llvm/test/CodeGen/Thumb2/mve-vabdus.ll b/llvm/test/CodeGen/Thumb2/mve-vabdus.ll
index 654f7a3cb248a65..cfbecd14604a212 100644
--- a/llvm/test/CodeGen/Thumb2/mve-vabdus.ll
+++ b/llvm/test/CodeGen/Thumb2/mve-vabdus.ll
@@ -40,8 +40,7 @@ define arm_aapcs_vfpcc <4 x i8> @vabd_v4s8(<4 x i8> %src1, <4 x i8> %src2) {
; CHECK-NEXT: vmovlb.s8 q0, q0
; CHECK-NEXT: vmovlb.s16 q1, q1
; CHECK-NEXT: vmovlb.s16 q0, q0
-; CHECK-NEXT: vsub.i32 q0, q0, q1
-; CHECK-NEXT: vabs.s32 q0, q0
+; CHECK-NEXT: vabd.s32 q0, q0, q1
; CHECK-NEXT: bx lr
%sextsrc1 = sext <4 x i8> %src1 to <4 x i16>
%sextsrc2 = sext <4 x i8> %src2 to <4 x i16>
More information about the llvm-commits
mailing list