diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 3ec6b9b79507..b6d4050236b7 100644 --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -1908,11 +1908,6 @@ bool TargetLowering::SimplifyDemandedBits( SDValue Op1 = Op.getOperand(1); EVT ShiftVT = Op1.getValueType(); - // Try to match AVG patterns. - if (SDValue AVG = combineShiftToAVG(Op, TLO.DAG, *this, DemandedBits, - DemandedElts, Depth + 1)) - return TLO.CombineTo(Op, AVG); - KnownBits KnownSA = TLO.DAG.computeKnownBits(Op1, DemandedElts, Depth + 1); if (KnownSA.isConstant() && KnownSA.getConstant().ult(BitWidth)) { unsigned ShAmt = KnownSA.getConstant().getZExtValue(); @@ -1994,6 +1989,12 @@ bool TargetLowering::SimplifyDemandedBits( // shift amounts. Known = TLO.DAG.computeKnownBits(Op, DemandedElts, Depth); } + + // Try to match AVG patterns (after shift simplification). + if (SDValue AVG = combineShiftToAVG(Op, TLO.DAG, *this, DemandedBits, + DemandedElts, Depth + 1)) + return TLO.CombineTo(Op, AVG); + break; } case ISD::SRA: { @@ -2015,11 +2016,6 @@ bool TargetLowering::SimplifyDemandedBits( if (DemandedBits.isOne()) return TLO.CombineTo(Op, TLO.DAG.getNode(ISD::SRL, dl, VT, Op0, Op1)); - // Try to match AVG patterns. - if (SDValue AVG = combineShiftToAVG(Op, TLO.DAG, *this, DemandedBits, - DemandedElts, Depth + 1)) - return TLO.CombineTo(Op, AVG); - KnownBits KnownSA = TLO.DAG.computeKnownBits(Op1, DemandedElts, Depth + 1); if (KnownSA.isConstant() && KnownSA.getConstant().ult(BitWidth)) { unsigned ShAmt = KnownSA.getConstant().getZExtValue(); @@ -2106,6 +2102,12 @@ bool TargetLowering::SimplifyDemandedBits( } } } + + // Try to match AVG patterns (after shift simplification). + if (SDValue AVG = combineShiftToAVG(Op, TLO.DAG, *this, DemandedBits, + DemandedElts, Depth + 1)) + return TLO.CombineTo(Op, AVG); + break; } case ISD::FSHL: diff --git a/llvm/test/CodeGen/AArch64/arm64-vhadd.ll b/llvm/test/CodeGen/AArch64/arm64-vhadd.ll index e754f01daa2a..a8be8bbd193a 100644 --- a/llvm/test/CodeGen/AArch64/arm64-vhadd.ll +++ b/llvm/test/CodeGen/AArch64/arm64-vhadd.ll @@ -1379,7 +1379,7 @@ define <8 x i8> @sextmask2v8i8(<8 x i16> %src1, <8 x i8> %src2) { define <8 x i8> @sextmask3v8i8(<8 x i16> %src1, <8 x i8> %src2) { ; CHECK-LABEL: sextmask3v8i8: ; CHECK: // %bb.0: -; CHECK-NEXT: sshr.8h v0, v0, #7 +; CHECK-NEXT: ushr.8h v0, v0, #7 ; CHECK-NEXT: sshll.8h v1, v1, #0 ; CHECK-NEXT: shadd.8h v0, v0, v1 ; CHECK-NEXT: xtn.8b v0, v0