Skip to content

Commit fcee33b

Browse files
committed
[DAG] Pull out repeated isLittleEndian() calls. NFC.
1 parent 344eee6 commit fcee33b

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ SDValue TargetLowering::SimplifyMultipleUseDemandedBits(
645645
if (DemandedBits == 0 || DemandedElts == 0)
646646
return DAG.getUNDEF(Op.getValueType());
647647

648+
bool IsLE = DAG.getDataLayout().isLittleEndian();
648649
unsigned NumElts = DemandedElts.getBitWidth();
649650
unsigned BitWidth = DemandedBits.getBitWidth();
650651
KnownBits LHSKnown, RHSKnown;
@@ -664,8 +665,7 @@ SDValue TargetLowering::SimplifyMultipleUseDemandedBits(
664665
return DAG.getBitcast(DstVT, V);
665666

666667
// TODO - bigendian once we have test coverage.
667-
if (SrcVT.isVector() && (NumDstEltBits % NumSrcEltBits) == 0 &&
668-
DAG.getDataLayout().isLittleEndian()) {
668+
if (IsLE && SrcVT.isVector() && (NumDstEltBits % NumSrcEltBits) == 0) {
669669
unsigned Scale = NumDstEltBits / NumSrcEltBits;
670670
unsigned NumSrcElts = SrcVT.getVectorNumElements();
671671
APInt DemandedSrcBits = APInt::getZero(NumSrcEltBits);
@@ -687,8 +687,7 @@ SDValue TargetLowering::SimplifyMultipleUseDemandedBits(
687687
}
688688

689689
// TODO - bigendian once we have test coverage.
690-
if ((NumSrcEltBits % NumDstEltBits) == 0 &&
691-
DAG.getDataLayout().isLittleEndian()) {
690+
if (IsLE && (NumSrcEltBits % NumDstEltBits) == 0) {
692691
unsigned Scale = NumSrcEltBits / NumDstEltBits;
693692
unsigned NumSrcElts = SrcVT.isVector() ? SrcVT.getVectorNumElements() : 1;
694693
APInt DemandedSrcBits = APInt::getZero(NumSrcEltBits);
@@ -802,8 +801,8 @@ SDValue TargetLowering::SimplifyMultipleUseDemandedBits(
802801
SDValue Src = Op.getOperand(0);
803802
EVT SrcVT = Src.getValueType();
804803
EVT DstVT = Op.getValueType();
805-
if (DemandedElts == 1 && DstVT.getSizeInBits() == SrcVT.getSizeInBits() &&
806-
DAG.getDataLayout().isLittleEndian() &&
804+
if (IsLE && DemandedElts == 1 &&
805+
DstVT.getSizeInBits() == SrcVT.getSizeInBits() &&
807806
DemandedBits.getActiveBits() <= SrcVT.getScalarSizeInBits()) {
808807
return DAG.getBitcast(DstVT, Src);
809808
}
@@ -913,6 +912,7 @@ bool TargetLowering::SimplifyDemandedBits(
913912
if (Op.getValueType().isScalableVector())
914913
return false;
915914

915+
bool IsLE = TLO.DAG.getDataLayout().isLittleEndian();
916916
unsigned NumElts = OriginalDemandedElts.getBitWidth();
917917
assert((!Op.getValueType().isVector() ||
918918
NumElts == Op.getValueType().getVectorNumElements()) &&
@@ -1916,9 +1916,8 @@ bool TargetLowering::SimplifyDemandedBits(
19161916
if (DemandedBits.getActiveBits() <= InBits) {
19171917
// If we only need the non-extended bits of the bottom element
19181918
// then we can just bitcast to the result.
1919-
if (IsVecInReg && DemandedElts == 1 &&
1920-
VT.getSizeInBits() == SrcVT.getSizeInBits() &&
1921-
TLO.DAG.getDataLayout().isLittleEndian())
1919+
if (IsLE && IsVecInReg && DemandedElts == 1 &&
1920+
VT.getSizeInBits() == SrcVT.getSizeInBits())
19221921
return TLO.CombineTo(Op, TLO.DAG.getBitcast(VT, Src));
19231922

19241923
unsigned Opc =
@@ -1954,9 +1953,8 @@ bool TargetLowering::SimplifyDemandedBits(
19541953
if (DemandedBits.getActiveBits() <= InBits) {
19551954
// If we only need the non-extended bits of the bottom element
19561955
// then we can just bitcast to the result.
1957-
if (IsVecInReg && DemandedElts == 1 &&
1958-
VT.getSizeInBits() == SrcVT.getSizeInBits() &&
1959-
TLO.DAG.getDataLayout().isLittleEndian())
1956+
if (IsLE && IsVecInReg && DemandedElts == 1 &&
1957+
VT.getSizeInBits() == SrcVT.getSizeInBits())
19601958
return TLO.CombineTo(Op, TLO.DAG.getBitcast(VT, Src));
19611959

19621960
unsigned Opc =
@@ -2005,9 +2003,8 @@ bool TargetLowering::SimplifyDemandedBits(
20052003

20062004
// If we only need the bottom element then we can just bitcast.
20072005
// TODO: Handle ANY_EXTEND?
2008-
if (IsVecInReg && DemandedElts == 1 &&
2009-
VT.getSizeInBits() == SrcVT.getSizeInBits() &&
2010-
TLO.DAG.getDataLayout().isLittleEndian())
2006+
if (IsLE && IsVecInReg && DemandedElts == 1 &&
2007+
VT.getSizeInBits() == SrcVT.getSizeInBits())
20112008
return TLO.CombineTo(Op, TLO.DAG.getBitcast(VT, Src));
20122009

20132010
APInt InDemandedBits = DemandedBits.trunc(InBits);
@@ -2170,8 +2167,7 @@ bool TargetLowering::SimplifyDemandedBits(
21702167
// Bitcast from a vector using SimplifyDemanded Bits/VectorElts.
21712168
// Demand the elt/bit if any of the original elts/bits are demanded.
21722169
// TODO - bigendian once we have test coverage.
2173-
if (SrcVT.isVector() && (BitWidth % NumSrcEltBits) == 0 &&
2174-
TLO.DAG.getDataLayout().isLittleEndian()) {
2170+
if (IsLE && SrcVT.isVector() && (BitWidth % NumSrcEltBits) == 0) {
21752171
unsigned Scale = BitWidth / NumSrcEltBits;
21762172
unsigned NumSrcElts = SrcVT.getVectorNumElements();
21772173
APInt DemandedSrcBits = APInt::getZero(NumSrcEltBits);
@@ -2196,8 +2192,7 @@ bool TargetLowering::SimplifyDemandedBits(
21962192
if (SimplifyDemandedBits(Src, DemandedSrcBits, DemandedSrcElts,
21972193
KnownSrcBits, TLO, Depth + 1))
21982194
return true;
2199-
} else if ((NumSrcEltBits % BitWidth) == 0 &&
2200-
TLO.DAG.getDataLayout().isLittleEndian()) {
2195+
} else if (IsLE && (NumSrcEltBits % BitWidth) == 0) {
22012196
unsigned Scale = NumSrcEltBits / BitWidth;
22022197
unsigned NumSrcElts = SrcVT.isVector() ? SrcVT.getVectorNumElements() : 1;
22032198
APInt DemandedSrcBits = APInt::getZero(NumSrcEltBits);
@@ -2438,6 +2433,7 @@ bool TargetLowering::SimplifyDemandedVectorElts(
24382433

24392434
SDLoc DL(Op);
24402435
unsigned EltSizeInBits = VT.getScalarSizeInBits();
2436+
bool IsLE = TLO.DAG.getDataLayout().isLittleEndian();
24412437

24422438
// Helper for demanding the specified elements and all the bits of both binary
24432439
// operands.
@@ -2513,7 +2509,7 @@ bool TargetLowering::SimplifyDemandedVectorElts(
25132509
// Try calling SimplifyDemandedBits, converting demanded elts to the bits
25142510
// of the large element.
25152511
// TODO - bigendian once we have test coverage.
2516-
if (TLO.DAG.getDataLayout().isLittleEndian()) {
2512+
if (IsLE) {
25172513
unsigned SrcEltSizeInBits = SrcVT.getScalarSizeInBits();
25182514
APInt SrcDemandedBits = APInt::getZero(SrcEltSizeInBits);
25192515
for (unsigned i = 0; i != NumElts; ++i)
@@ -2826,9 +2822,8 @@ bool TargetLowering::SimplifyDemandedVectorElts(
28262822
KnownZero = SrcZero.zextOrTrunc(NumElts);
28272823
KnownUndef = SrcUndef.zextOrTrunc(NumElts);
28282824

2829-
if (Op.getOpcode() == ISD::ANY_EXTEND_VECTOR_INREG &&
2830-
Op.getValueSizeInBits() == Src.getValueSizeInBits() &&
2831-
DemandedSrcElts == 1 && TLO.DAG.getDataLayout().isLittleEndian()) {
2825+
if (IsLE && Op.getOpcode() == ISD::ANY_EXTEND_VECTOR_INREG &&
2826+
Op.getValueSizeInBits() == Src.getValueSizeInBits()) {
28322827
// aext - if we just need the bottom element then we can bitcast.
28332828
return TLO.CombineTo(Op, TLO.DAG.getBitcast(VT, Src));
28342829
}
@@ -2841,8 +2836,8 @@ bool TargetLowering::SimplifyDemandedVectorElts(
28412836

28422837
// zext - if we just need the bottom element then we can mask:
28432838
// zext(and(x,c)) -> and(x,c') iff the zext is the only user of the and.
2844-
if (DemandedSrcElts == 1 && TLO.DAG.getDataLayout().isLittleEndian() &&
2845-
Src.getOpcode() == ISD::AND && Op->isOnlyUserOf(Src.getNode()) &&
2839+
if (IsLE && DemandedSrcElts == 1 && Src.getOpcode() == ISD::AND &&
2840+
Op->isOnlyUserOf(Src.getNode()) &&
28462841
Op.getValueSizeInBits() == Src.getValueSizeInBits()) {
28472842
SDLoc DL(Op);
28482843
EVT SrcVT = Src.getValueType();

0 commit comments

Comments
 (0)