Skip to content
10 changes: 7 additions & 3 deletions llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,9 +743,13 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
if (!CArg)
break;

int CArg4BitAsInt = CArg->getValue().trunc(4).getSExtValue();
float ResVal = 0.0625 * CArg4BitAsInt;
Constant *Res = ConstantFP::get(II.getType(), ResVal);
// Tabulated 0.0625 * (sext (CArg & 0xf)).
constexpr size_t ResValsSize = 16;
const float ResVals[ResValsSize] = {
0.0, 0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375,
-0.5, -0.4375, -0.375, -0.3125, -0.25, -0.1875, -0.125, -0.0625};
Constant *Res =
ConstantFP::get(Ty, ResVals[CArg->getZExtValue() % ResValsSize]);
return IC.replaceInstUsesWith(II, Res);
}
case Intrinsic::amdgcn_ubfe:
Expand Down
Loading