Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove fgMorphCastedBitwiseOp #86491

Merged
merged 1 commit into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5997,7 +5997,6 @@ class Compiler
GenTree* fgMorphConst(GenTree* tree);

GenTreeOp* fgMorphCommutative(GenTreeOp* tree);
GenTree* fgMorphCastedBitwiseOp(GenTreeOp* tree);

GenTree* fgMorphReduceAddOps(GenTree* tree);

Expand Down
78 changes: 0 additions & 78 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8347,75 +8347,6 @@ GenTreeOp* Compiler::fgMorphCommutative(GenTreeOp* tree)
return op1->AsOp();
}

//------------------------------------------------------------------------------
// fgMorphCastedBitwiseOp : Try to simplify "(T)x op (T)y" to "(T)(x op y)".
//
// Arguments:
// tree - node to fold
//
// Return Value:
// A folded GenTree* instance, or nullptr if it couldn't be folded
GenTree* Compiler::fgMorphCastedBitwiseOp(GenTreeOp* tree)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but is this something we can handle in lowering instead where we can make the decision to keep or bypass the cast based on whether the operands are coming from memory?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, let's see if perf triage will find any regressions (hoping to see improvements instead)

{
// This transform does not preserve VNs and deletes a node.
assert(fgGlobalMorph);
assert(varTypeIsIntegralOrI(tree));
assert(tree->OperIs(GT_OR, GT_AND, GT_XOR));

GenTree* op1 = tree->gtGetOp1();
GenTree* op2 = tree->gtGetOp2();
genTreeOps oper = tree->OperGet();

// see whether both ops are casts, with matching to and from types.
if (op1->OperIs(GT_CAST) && op2->OperIs(GT_CAST))
{
// bail if either operand is a checked cast
if (op1->gtOverflow() || op2->gtOverflow())
{
return nullptr;
}

var_types fromType = op1->AsCast()->CastOp()->TypeGet();
var_types toType = op1->AsCast()->CastToType();
bool isUnsigned = op1->IsUnsigned();

if (varTypeIsFloating(fromType) || (op2->CastFromType() != fromType) || (op2->CastToType() != toType) ||
(op2->IsUnsigned() != isUnsigned))
{
return nullptr;
}

/*
// Reuse gentree nodes:
//
// tree op1
// / \ |
// op1 op2 ==> tree
// | | / \.
// x y x y
//
// (op2 becomes garbage)
*/

tree->gtOp1 = op1->AsCast()->CastOp();
tree->gtOp2 = op2->AsCast()->CastOp();
tree->gtType = genActualType(fromType);

op1->gtType = genActualType(toType);
op1->AsCast()->gtOp1 = tree;
op1->AsCast()->CastToType() = toType;
op1->SetAllEffectsFlags(tree);
// no need to update isUnsigned

DEBUG_DESTROY_NODE(op2);
INDEBUG(op1->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED);

return op1;
}

return nullptr;
}

//------------------------------------------------------------------------
// fgMorphSmpOp: morph a GTK_SMPOP tree
//
Expand Down Expand Up @@ -10862,15 +10793,6 @@ GenTree* Compiler::fgOptimizeCommutativeArithmetic(GenTreeOp* tree)
}
}

if (fgGlobalMorph && tree->OperIs(GT_AND, GT_OR, GT_XOR))
{
GenTree* castTree = fgMorphCastedBitwiseOp(tree->AsOp());
if (castTree != nullptr)
{
return castTree;
}
}

if (varTypeIsIntegralOrI(tree))
{
genTreeOps oldTreeOper = tree->OperGet();
Expand Down