Skip to content

Commit 136b312

Browse files
Slightly more aggressive ASG reversal (#65920)
Allows us to reverse "ASG(IND(const), ...)".
1 parent 5d2da71 commit 136b312

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/coreclr/jit/gentree.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4276,28 +4276,24 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree)
42764276
case GT_IND:
42774277
case GT_BLK:
42784278
case GT_OBJ:
4279-
4280-
// In an indirection, the destination address is evaluated prior to the source.
4281-
// If we have any side effects on the target indirection,
4282-
// we have to evaluate op1 first.
4283-
// However, if the LHS is a lclVar address, SSA relies on using evaluation order for its
4284-
// renaming, and therefore the RHS must be evaluated first.
4285-
// If we have an assignment involving a lclVar address, the LHS may be marked as having
4286-
// side-effects.
4287-
// However the side-effects won't require that we evaluate the LHS address first:
4288-
// - The GTF_GLOB_REF might have been conservatively set on a FIELD of a local.
4289-
// - The local might be address-exposed, but that side-effect happens at the actual assignment (not
4290-
// when its address is "evaluated") so it doesn't change the side effect to "evaluate" the address
4291-
// after the RHS (note that in this case it won't be renamed by SSA anyway, but the reordering is
4292-
// safe).
4279+
{
4280+
// In an ASG(IND(addr), ...), the "IND" is a pure syntactical element,
4281+
// the actual indirection will only be realized at the point of the ASG
4282+
// itself. As such, we can disard any side effects "induced" by it in
4283+
// this logic.
4284+
//
4285+
// Note that for local "addr"s, liveness depends on seeing the defs and
4286+
// uses in correct order, and so we MUST reverse the ASG in that case.
42934287
//
4294-
if (op1Val->AsIndir()->Addr()->IsLocalAddrExpr())
4288+
GenTree* op1Addr = op1->AsIndir()->Addr();
4289+
4290+
if (op1Addr->IsLocalAddrExpr() || op1Addr->IsInvariant())
42954291
{
42964292
bReverseInAssignment = true;
42974293
tree->gtFlags |= GTF_REVERSE_OPS;
42984294
break;
42994295
}
4300-
if (op1Val->AsIndir()->Addr()->gtFlags & GTF_ALL_EFFECT)
4296+
if (op1Addr->gtFlags & GTF_ALL_EFFECT)
43014297
{
43024298
break;
43034299
}
@@ -4314,7 +4310,7 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree)
43144310
{
43154311
break;
43164312
}
4317-
4313+
}
43184314
// fall through and set GTF_REVERSE_OPS
43194315
FALLTHROUGH;
43204316

0 commit comments

Comments
 (0)