Please use GitHub pull requests for new 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,239 Lines • ▼ Show 20 Lines | SDValue AMDGPUTargetLowering::performTruncateCombine( | ||||
if (VT.getScalarSizeInBits() < 32) { | 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(); | |||||
if ((Known.isConstant() && Known.getConstant().ule(Size)) || | // - For left shifts, do the transform as long as the shift | ||||
(Known.countMaxActiveBits() <= Log2_32(Size))) { | // amount is still legal for i32, so when ShiftAmt < 32 (<= 31) | ||||
// - 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) ? 31 : (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.getMaxValue().ule(MaxCstSize)) { | |||||
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