From cf0ffe2435656dcf7c089f81ccd4e85ae99aa1db Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Sat, 14 May 2022 17:12:09 +0200 Subject: [PATCH] Only fold Type.op_Equality calls before morphing args Otherwise we may discard setup nodes. Fix #68513 --- src/coreclr/jit/gentree.cpp | 5 +++++ src/coreclr/jit/morph.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index d9234846e2269b..4c2b02f2484f85 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -12400,6 +12400,11 @@ GenTree* Compiler::gtFoldExpr(GenTree* tree) GenTree* Compiler::gtFoldExprCall(GenTreeCall* call) { + // This may discard the call and will thus discard arg setup nodes that may + // have arbitrary side effects, so we only support this being called before + // args have been morphed. + assert(!call->gtArgs.AreArgsComplete()); + // Can only fold calls to special intrinsics. if ((call->gtCallMoreFlags & GTF_CALL_M_SPECIAL_INTRINSIC) == 0) { diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 9ad29739647939..9bca4e85b8a18e 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -8321,7 +8321,7 @@ GenTree* Compiler::fgMorphCall(GenTreeCall* call) // Morph Type.op_Equality, Type.op_Inequality, and Enum.HasFlag // // We need to do these before the arguments are morphed - if ((call->gtCallMoreFlags & GTF_CALL_M_SPECIAL_INTRINSIC)) + if (!call->gtArgs.AreArgsComplete() && (call->gtCallMoreFlags & GTF_CALL_M_SPECIAL_INTRINSIC)) { // See if this is foldable GenTree* optTree = gtFoldExprCall(call);