Skip to content

Commit

Permalink
JIT: Optimize *x = dblCns to *x = intCns (#52298)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed May 18, 2021
1 parent 65afa4e commit 79f9415
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/coreclr/jit/lowerxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,38 @@ void Lowering::LowerStoreIndir(GenTreeIndir* node)
return;
}
}
else if (node->AsStoreInd()->Data()->OperIs(GT_CNS_DBL))
{
// Optimize *x = DCON to *x = ICON which is slightly faster on xarch
GenTree* data = node->AsStoreInd()->Data();
double dblCns = data->AsDblCon()->gtDconVal;
ssize_t intCns = 0;
var_types type = TYP_UNKNOWN;

if (node->TypeIs(TYP_FLOAT))
{
float fltCns = static_cast<float>(dblCns); // should be a safe round-trip
intCns = static_cast<ssize_t>(*reinterpret_cast<UINT32*>(&fltCns));
type = TYP_UINT;
}
#ifdef TARGET_AMD64
else
{
assert(node->TypeIs(TYP_DOUBLE));
intCns = static_cast<ssize_t>(*reinterpret_cast<UINT64*>(&dblCns));
type = TYP_ULONG;
}
#endif

if (type != TYP_UNKNOWN)
{
data->SetContained();
data->ChangeOperConst(GT_CNS_INT);
data->AsIntCon()->SetIconValue(intCns);
data->ChangeType(type);
node->ChangeType(type);
}
}
ContainCheckStoreIndir(node);
}

Expand Down

0 comments on commit 79f9415

Please sign in to comment.