Skip to content

Commit de7beb0

Browse files
committed
[DAG] ExpandShiftWithKnownAmountBit - reduce number of repeated getOpcode / getOperand calls. NFC.
1 parent 0aacd44 commit de7beb0

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -2897,6 +2897,8 @@ void DAGTypeLegalizer::ExpandShiftByConstant(SDNode *N, const APInt &Amt,
28972897
/// shift amount.
28982898
bool DAGTypeLegalizer::
28992899
ExpandShiftWithKnownAmountBit(SDNode *N, SDValue &Lo, SDValue &Hi) {
2900+
unsigned Opc = N->getOpcode();
2901+
SDValue In = N->getOperand(0);
29002902
SDValue Amt = N->getOperand(1);
29012903
EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
29022904
EVT ShTy = Amt.getValueType();
@@ -2907,15 +2909,15 @@ ExpandShiftWithKnownAmountBit(SDNode *N, SDValue &Lo, SDValue &Hi) {
29072909
SDLoc dl(N);
29082910

29092911
APInt HighBitMask = APInt::getHighBitsSet(ShBits, ShBits - Log2_32(NVTBits));
2910-
KnownBits Known = DAG.computeKnownBits(N->getOperand(1));
2912+
KnownBits Known = DAG.computeKnownBits(Amt);
29112913

29122914
// If we don't know anything about the high bits, exit.
2913-
if (((Known.Zero|Known.One) & HighBitMask) == 0)
2915+
if (((Known.Zero | Known.One) & HighBitMask) == 0)
29142916
return false;
29152917

29162918
// Get the incoming operand to be shifted.
29172919
SDValue InL, InH;
2918-
GetExpandedInteger(N->getOperand(0), InL, InH);
2920+
GetExpandedInteger(In, InL, InH);
29192921

29202922
// If we know that any of the high bits of the shift amount are one, then we
29212923
// can do this as a couple of simple shifts.
@@ -2924,7 +2926,7 @@ ExpandShiftWithKnownAmountBit(SDNode *N, SDValue &Lo, SDValue &Hi) {
29242926
Amt = DAG.getNode(ISD::AND, dl, ShTy, Amt,
29252927
DAG.getConstant(~HighBitMask, dl, ShTy));
29262928

2927-
switch (N->getOpcode()) {
2929+
switch (Opc) {
29282930
default: llvm_unreachable("Unknown shift");
29292931
case ISD::SHL:
29302932
Lo = DAG.getConstant(0, dl, NVT); // Low part is zero.
@@ -2952,15 +2954,15 @@ ExpandShiftWithKnownAmountBit(SDNode *N, SDValue &Lo, SDValue &Hi) {
29522954
DAG.getConstant(NVTBits - 1, dl, ShTy));
29532955

29542956
unsigned Op1, Op2;
2955-
switch (N->getOpcode()) {
2957+
switch (Opc) {
29562958
default: llvm_unreachable("Unknown shift");
29572959
case ISD::SHL: Op1 = ISD::SHL; Op2 = ISD::SRL; break;
29582960
case ISD::SRL:
29592961
case ISD::SRA: Op1 = ISD::SRL; Op2 = ISD::SHL; break;
29602962
}
29612963

29622964
// When shifting right the arithmetic for Lo and Hi is swapped.
2963-
if (N->getOpcode() != ISD::SHL)
2965+
if (Opc != ISD::SHL)
29642966
std::swap(InL, InH);
29652967

29662968
// Use a little trick to get the bits that move from Lo to Hi. First
@@ -2969,10 +2971,10 @@ ExpandShiftWithKnownAmountBit(SDNode *N, SDValue &Lo, SDValue &Hi) {
29692971
// Then compute the remaining shift with amount-1.
29702972
SDValue Sh2 = DAG.getNode(Op2, dl, NVT, Sh1, Amt2);
29712973

2972-
Lo = DAG.getNode(N->getOpcode(), dl, NVT, InL, Amt);
2974+
Lo = DAG.getNode(Opc, dl, NVT, InL, Amt);
29732975
Hi = DAG.getNode(ISD::OR, dl, NVT, DAG.getNode(Op1, dl, NVT, InH, Amt),Sh2);
29742976

2975-
if (N->getOpcode() != ISD::SHL)
2977+
if (Opc != ISD::SHL)
29762978
std::swap(Hi, Lo);
29772979
return true;
29782980
}

0 commit comments

Comments
 (0)