Skip to content

Commit bb597e2

Browse files
[JIT] [Issue: 61620] Optimizing ARM64 for *x = dblCns; (#61847)
* [Issue: 61620] Optimizing ARM64 for *x = 0; * Update src/coreclr/jit/lower.cpp Co-authored-by: SingleAccretion <[email protected]> * Fixed bug with * x = dConst if dConst is not 0 * remove extra printf * Replacing IsFPZero with IsCnsNonZeroFltOrDbl for STOREIND Minor edits with conditional compilation in lower.cpp * fixed ARM codegen for STOREIND * Update src/coreclr/jit/lower.cpp Co-authored-by: SingleAccretion <[email protected]> * Update src/coreclr/jit/lower.cpp Co-authored-by: SingleAccretion <[email protected]> * fix formatting Co-authored-by: SingleAccretion <[email protected]>
1 parent 5ff8070 commit bb597e2

File tree

2 files changed

+46
-31
lines changed

2 files changed

+46
-31
lines changed

src/coreclr/jit/lower.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6783,6 +6783,51 @@ void Lowering::LowerStoreIndirCommon(GenTreeStoreInd* ind)
67836783
TryCreateAddrMode(ind->Addr(), true, ind->TypeGet());
67846784
if (!comp->codeGen->gcInfo.gcIsWriteBarrierStoreIndNode(ind))
67856785
{
6786+
if (varTypeIsFloating(ind) && ind->Data()->IsCnsFltOrDbl())
6787+
{
6788+
// Optimize *x = DCON to *x = ICON which can be slightly faster and/or smaller.
6789+
GenTree* data = ind->Data();
6790+
double dblCns = data->AsDblCon()->gtDconVal;
6791+
ssize_t intCns = 0;
6792+
var_types type = TYP_UNKNOWN;
6793+
// XARCH: we can always contain the immediates.
6794+
// ARM64: zero can always be contained, other cases will use immediates from the data
6795+
// section and it is not a clear win to switch them to inline integers.
6796+
// ARM: FP constants are assembled from integral ones, so it is always profitable
6797+
// to directly use the integers as it avoids the int -> float conversion.
6798+
CLANG_FORMAT_COMMENT_ANCHOR;
6799+
6800+
#if defined(TARGET_XARCH) || defined(TARGET_ARM)
6801+
bool shouldSwitchToInteger = true;
6802+
#else // TARGET_ARM64
6803+
bool shouldSwitchToInteger = !data->IsCnsNonZeroFltOrDbl();
6804+
#endif
6805+
6806+
if (shouldSwitchToInteger)
6807+
{
6808+
if (ind->TypeIs(TYP_FLOAT))
6809+
{
6810+
float fltCns = static_cast<float>(dblCns); // should be a safe round-trip
6811+
intCns = static_cast<ssize_t>(*reinterpret_cast<INT32*>(&fltCns));
6812+
type = TYP_INT;
6813+
}
6814+
#ifdef TARGET_64BIT
6815+
else
6816+
{
6817+
assert(ind->TypeIs(TYP_DOUBLE));
6818+
intCns = static_cast<ssize_t>(*reinterpret_cast<INT64*>(&dblCns));
6819+
type = TYP_LONG;
6820+
}
6821+
#endif
6822+
}
6823+
6824+
if (type != TYP_UNKNOWN)
6825+
{
6826+
data->BashToConst(intCns, type);
6827+
ind->ChangeType(type);
6828+
}
6829+
}
6830+
67866831
LowerStoreIndir(ind);
67876832
}
67886833
}
@@ -6852,7 +6897,7 @@ void Lowering::TransformUnusedIndirection(GenTreeIndir* ind, Compiler* comp, Bas
68526897
#ifdef TARGET_ARM64
68536898
bool useNullCheck = true;
68546899
#elif TARGET_ARM
6855-
bool useNullCheck = false;
6900+
bool useNullCheck = false;
68566901
#else // TARGET_XARCH
68576902
bool useNullCheck = !ind->Addr()->isContained();
68586903
#endif // !TARGET_XARCH

src/coreclr/jit/lowerxarch.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -129,36 +129,6 @@ void Lowering::LowerStoreIndir(GenTreeStoreInd* node)
129129
return;
130130
}
131131
}
132-
else if (node->Data()->IsCnsFltOrDbl())
133-
{
134-
// Optimize *x = DCON to *x = ICON which is slightly faster on xarch
135-
GenTree* data = node->Data();
136-
double dblCns = data->AsDblCon()->gtDconVal;
137-
ssize_t intCns = 0;
138-
var_types type = TYP_UNKNOWN;
139-
140-
if (node->TypeIs(TYP_FLOAT))
141-
{
142-
float fltCns = static_cast<float>(dblCns); // should be a safe round-trip
143-
intCns = static_cast<ssize_t>(*reinterpret_cast<INT32*>(&fltCns));
144-
type = TYP_INT;
145-
}
146-
#ifdef TARGET_AMD64
147-
else
148-
{
149-
assert(node->TypeIs(TYP_DOUBLE));
150-
intCns = static_cast<ssize_t>(*reinterpret_cast<INT64*>(&dblCns));
151-
type = TYP_LONG;
152-
}
153-
#endif
154-
155-
if (type != TYP_UNKNOWN)
156-
{
157-
data->SetContained();
158-
data->BashToConst(intCns, type);
159-
node->ChangeType(type);
160-
}
161-
}
162132

163133
// Optimization: do not unnecessarily zero-extend the result of setcc.
164134
if (varTypeIsByte(node) && (node->Data()->OperIsCompare() || node->Data()->OperIs(GT_SETCC)))

0 commit comments

Comments
 (0)