Skip to content

Commit 9f2a068

Browse files
committed
[DAG] Add getValid*ShiftAmountConstant wrappers without DemandedElts
Simplify callers which don't have their own DemandedElts mask. Noticed while reviewing #88801
1 parent eaa2eac commit 9f2a068

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,18 +2146,32 @@ class SelectionDAG {
21462146
const APInt *getValidShiftAmountConstant(SDValue V,
21472147
const APInt &DemandedElts) const;
21482148

2149+
/// If a SHL/SRA/SRL node \p V has a constant or splat constant shift amount
2150+
/// that is less than the element bit-width of the shift node, return it.
2151+
const APInt *getValidShiftAmountConstant(SDValue V) const;
2152+
21492153
/// If a SHL/SRA/SRL node \p V has constant shift amounts that are all less
21502154
/// than the element bit-width of the shift node, return the minimum value.
21512155
const APInt *
21522156
getValidMinimumShiftAmountConstant(SDValue V,
21532157
const APInt &DemandedElts) const;
21542158

2159+
/// If a SHL/SRA/SRL node \p V has constant shift amounts that are all less
2160+
/// than the element bit-width of the shift node, return the minimum value.
2161+
const APInt *
2162+
getValidMinimumShiftAmountConstant(SDValue V) const;
2163+
21552164
/// If a SHL/SRA/SRL node \p V has constant shift amounts that are all less
21562165
/// than the element bit-width of the shift node, return the maximum value.
21572166
const APInt *
21582167
getValidMaximumShiftAmountConstant(SDValue V,
21592168
const APInt &DemandedElts) const;
21602169

2170+
/// If a SHL/SRA/SRL node \p V has constant shift amounts that are all less
2171+
/// than the element bit-width of the shift node, return the maximum value.
2172+
const APInt *
2173+
getValidMaximumShiftAmountConstant(SDValue V) const;
2174+
21612175
/// Match a binop + shuffle pyramid that represents a horizontal reduction
21622176
/// over the elements of a vector starting from the EXTRACT_VECTOR_ELT node /p
21632177
/// Extract. The reduction must use one of the opcodes listed in /p

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,6 +2993,14 @@ SelectionDAG::getValidShiftAmountConstant(SDValue V,
29932993
return nullptr;
29942994
}
29952995

2996+
const APInt *SelectionDAG::getValidShiftAmountConstant(SDValue V) const {
2997+
EVT VT = V.getValueType();
2998+
APInt DemandedElts = VT.isFixedLengthVector()
2999+
? APInt::getAllOnes(VT.getVectorNumElements())
3000+
: APInt(1, 1);
3001+
return getValidShiftAmountConstant(V, DemandedElts);
3002+
}
3003+
29963004
const APInt *SelectionDAG::getValidMinimumShiftAmountConstant(
29973005
SDValue V, const APInt &DemandedElts) const {
29983006
assert((V.getOpcode() == ISD::SHL || V.getOpcode() == ISD::SRL ||
@@ -3022,6 +3030,14 @@ const APInt *SelectionDAG::getValidMinimumShiftAmountConstant(
30223030
return MinShAmt;
30233031
}
30243032

3033+
const APInt *SelectionDAG::getValidMinimumShiftAmountConstant(SDValue V) const {
3034+
EVT VT = V.getValueType();
3035+
APInt DemandedElts = VT.isFixedLengthVector()
3036+
? APInt::getAllOnes(VT.getVectorNumElements())
3037+
: APInt(1, 1);
3038+
return getValidMinimumShiftAmountConstant(V, DemandedElts);
3039+
}
3040+
30253041
const APInt *SelectionDAG::getValidMaximumShiftAmountConstant(
30263042
SDValue V, const APInt &DemandedElts) const {
30273043
assert((V.getOpcode() == ISD::SHL || V.getOpcode() == ISD::SRL ||
@@ -3051,6 +3067,14 @@ const APInt *SelectionDAG::getValidMaximumShiftAmountConstant(
30513067
return MaxShAmt;
30523068
}
30533069

3070+
const APInt *SelectionDAG::getValidMaximumShiftAmountConstant(SDValue V) const {
3071+
EVT VT = V.getValueType();
3072+
APInt DemandedElts = VT.isFixedLengthVector()
3073+
? APInt::getAllOnes(VT.getVectorNumElements())
3074+
: APInt(1, 1);
3075+
return getValidMaximumShiftAmountConstant(V, DemandedElts);
3076+
}
3077+
30543078
/// Determine which bits of Op are known to be either zero or one and return
30553079
/// them in Known. For vectors, the known bits are those that are shared by
30563080
/// every vector element.

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20459,8 +20459,7 @@ static SDValue matchTruncateWithPACK(unsigned &PackOpcode, EVT DstVT,
2045920459
// the truncation then we can use PACKSS by converting the srl to a sra.
2046020460
// SimplifyDemandedBits often relaxes sra to srl so we need to reverse it.
2046120461
if (In.getOpcode() == ISD::SRL && In->hasOneUse())
20462-
if (const APInt *ShAmt = DAG.getValidShiftAmountConstant(
20463-
In, APInt::getAllOnes(SrcVT.getVectorNumElements()))) {
20462+
if (const APInt *ShAmt = DAG.getValidShiftAmountConstant(In)) {
2046420463
if (*ShAmt == MinSignBits) {
2046520464
PackOpcode = X86ISD::PACKSS;
2046620465
return DAG.getNode(ISD::SRA, DL, SrcVT, In->ops());

0 commit comments

Comments
 (0)