Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
Show First 20 Lines • Show All 3,240 Lines • ▼ Show 20 Lines | if (VT.getScalarSizeInBits() < 32) { | ||||
EVT SrcVT = Src.getValueType(); | EVT SrcVT = Src.getValueType(); | ||||
if (SrcVT.getScalarSizeInBits() > 32 && | if (SrcVT.getScalarSizeInBits() > 32 && | ||||
(Src.getOpcode() == ISD::SRL || | (Src.getOpcode() == ISD::SRL || | ||||
Src.getOpcode() == ISD::SRA || | Src.getOpcode() == ISD::SRA || | ||||
Src.getOpcode() == ISD::SHL)) { | Src.getOpcode() == ISD::SHL)) { | ||||
SDValue Amt = Src.getOperand(1); | SDValue Amt = Src.getOperand(1); | ||||
KnownBits Known = DAG.computeKnownBits(Amt); | KnownBits Known = DAG.computeKnownBits(Amt); | ||||
unsigned Size = VT.getScalarSizeInBits(); | unsigned Size = VT.getScalarSizeInBits(); | ||||
if ((Known.isConstant() && Known.getConstant().ule(Size)) || | |||||
// When the shift amount is known: | |||||
// - For left shifts, do the transform if ShiftAmt <= Size | |||||
// - For right shift, do it if ShiftAmt <= (32 - Size) to avoid | |||||
// losing information stored in the high bits when truncating. | |||||
const unsigned MaxCstSize = (Src.getOpcode() == ISD::SHL) | |||||
? Size | |||||
: (32 - VT.getScalarSizeInBits()); | |||||
foad: For left shifts you can do it so long as the new shift amount is still valid, so ShiftAmt < 32… | |||||
if ((Known.isConstant() && Known.getConstant().ule(MaxCstSize)) || | |||||
(Known.countMaxActiveBits() <= Log2_32(Size))) { | (Known.countMaxActiveBits() <= Log2_32(Size))) { | ||||
foadUnsubmitted The whole if condition can be replaced with: Known.getMaxValue().ule(MaxCstSize) foad: The whole `if` condition can be replaced with: `Known.getMaxValue().ule(MaxCstSize)` | |||||
EVT MidVT = VT.isVector() ? | EVT MidVT = VT.isVector() ? | ||||
EVT::getVectorVT(*DAG.getContext(), MVT::i32, | EVT::getVectorVT(*DAG.getContext(), MVT::i32, | ||||
VT.getVectorNumElements()) : MVT::i32; | VT.getVectorNumElements()) : MVT::i32; | ||||
EVT NewShiftVT = getShiftAmountTy(MidVT, DAG.getDataLayout()); | EVT NewShiftVT = getShiftAmountTy(MidVT, DAG.getDataLayout()); | ||||
SDValue Trunc = DAG.getNode(ISD::TRUNCATE, SL, MidVT, | SDValue Trunc = DAG.getNode(ISD::TRUNCATE, SL, MidVT, | ||||
Src.getOperand(0)); | Src.getOperand(0)); | ||||
DCI.AddToWorklist(Trunc.getNode()); | DCI.AddToWorklist(Trunc.getNode()); | ||||
▲ Show 20 Lines • Show All 1,578 Lines • Show Last 20 Lines |
For left shifts you can do it so long as the new shift amount is still valid, so ShiftAmt < 32 (aka <= 31).
So this can be: ... ? 31 : 32 - Size