Skip to content

Commit bbc4c2e

Browse files
committed
[DAG] SimplifyDemandedBits - ensure we have simplified the shift operands before folding to AVG
Pulled out of #92096 - ensure we have completed a topological simplification of the SRA/SRL shift operands before we try to combine to a AVG node, as its difficult to later simplify through AVG nodes.
1 parent 8619054 commit bbc4c2e

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,11 +1908,6 @@ bool TargetLowering::SimplifyDemandedBits(
19081908
SDValue Op1 = Op.getOperand(1);
19091909
EVT ShiftVT = Op1.getValueType();
19101910

1911-
// Try to match AVG patterns.
1912-
if (SDValue AVG = combineShiftToAVG(Op, TLO.DAG, *this, DemandedBits,
1913-
DemandedElts, Depth + 1))
1914-
return TLO.CombineTo(Op, AVG);
1915-
19161911
KnownBits KnownSA = TLO.DAG.computeKnownBits(Op1, DemandedElts, Depth + 1);
19171912
if (KnownSA.isConstant() && KnownSA.getConstant().ult(BitWidth)) {
19181913
unsigned ShAmt = KnownSA.getConstant().getZExtValue();
@@ -1994,6 +1989,12 @@ bool TargetLowering::SimplifyDemandedBits(
19941989
// shift amounts.
19951990
Known = TLO.DAG.computeKnownBits(Op, DemandedElts, Depth);
19961991
}
1992+
1993+
// Try to match AVG patterns (after shift simplification).
1994+
if (SDValue AVG = combineShiftToAVG(Op, TLO.DAG, *this, DemandedBits,
1995+
DemandedElts, Depth + 1))
1996+
return TLO.CombineTo(Op, AVG);
1997+
19971998
break;
19981999
}
19992000
case ISD::SRA: {
@@ -2015,11 +2016,6 @@ bool TargetLowering::SimplifyDemandedBits(
20152016
if (DemandedBits.isOne())
20162017
return TLO.CombineTo(Op, TLO.DAG.getNode(ISD::SRL, dl, VT, Op0, Op1));
20172018

2018-
// Try to match AVG patterns.
2019-
if (SDValue AVG = combineShiftToAVG(Op, TLO.DAG, *this, DemandedBits,
2020-
DemandedElts, Depth + 1))
2021-
return TLO.CombineTo(Op, AVG);
2022-
20232019
KnownBits KnownSA = TLO.DAG.computeKnownBits(Op1, DemandedElts, Depth + 1);
20242020
if (KnownSA.isConstant() && KnownSA.getConstant().ult(BitWidth)) {
20252021
unsigned ShAmt = KnownSA.getConstant().getZExtValue();
@@ -2106,6 +2102,12 @@ bool TargetLowering::SimplifyDemandedBits(
21062102
}
21072103
}
21082104
}
2105+
2106+
// Try to match AVG patterns (after shift simplification).
2107+
if (SDValue AVG = combineShiftToAVG(Op, TLO.DAG, *this, DemandedBits,
2108+
DemandedElts, Depth + 1))
2109+
return TLO.CombineTo(Op, AVG);
2110+
21092111
break;
21102112
}
21112113
case ISD::FSHL:

llvm/test/CodeGen/AArch64/arm64-vhadd.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ define <8 x i8> @sextmask2v8i8(<8 x i16> %src1, <8 x i8> %src2) {
13791379
define <8 x i8> @sextmask3v8i8(<8 x i16> %src1, <8 x i8> %src2) {
13801380
; CHECK-LABEL: sextmask3v8i8:
13811381
; CHECK: // %bb.0:
1382-
; CHECK-NEXT: sshr.8h v0, v0, #7
1382+
; CHECK-NEXT: ushr.8h v0, v0, #7
13831383
; CHECK-NEXT: sshll.8h v1, v1, #0
13841384
; CHECK-NEXT: shadd.8h v0, v0, v1
13851385
; CHECK-NEXT: xtn.8b v0, v0

0 commit comments

Comments
 (0)