Skip to content

Conversation

@briansull
Copy link
Contributor

This change has zero code diffs in the framework libraries

  • Mark nodes that use the division by constant optimization with GTF_DIV_BY_CNS_OPT
  • Don't perform const prop on expressions marked with GTF_DONT_CSE, as this would undo a constant CSE
  • Fix for bug in AssertionProp where we assign the wrong value number when folding a conditional
  • When dumping the BasicBlocks print hascall when the block is marked with BBF_HAS_CALL
  • Call CheckDivideByConstOptimized when early prop inserts a constant node
  • added methods: UsesDivideByConstOptimized, CheckDivideByConstOptimized and MarkDivideByConstant
  • Propagate any side effect flags in the gtCallAddr field of an indirect call node
  • Call CheckDivideByConstOptimized when morphing a divide or remainder nodes
  • Don't allow changing a floating point GT_DIV into a GT_MUL in fgMorph after the global morph phase
  • In loop hoisting, set BBF_HAS_CALL if we hoist a tree that contains a call
  • When hoisting something that requires a physical register, clear that requirement in the hoisted copy

… diffs in the framework libraries)

Mark nodes that use the division by constant optimization with GTF_DIV_BY_CNS_OPT
Don't perform const prop on expressions marked with GTF_DONT_CSE, as this would undo a constant CSE
Fix for bug in AssertionProp where we assign the wrong value number when folding a conditional
When dumping the BasicBlocks print hascall when the block is marked with BBF_HAS_CALL
Call CheckDivideByConstOptimized when early prop inserts a constant node
added methods: UsesDivideByConstOptimized, CheckDivideByConstOptimized and MarkDivideByConstant
Propagate any side effect flags in the gtCallAddr field of an indirect call node
Call CheckDivideByConstOptimized when morphing a divide or remainder nodes
Don't allow changing a floating point GT_DIV into a GT_MUL in fgMorph after the global morph phase
In loop hoisting, set BBF_HAS_CALL if we hoist a tree that contains a call
When hoisting something that requires a physical register, clear that requirement in the hoisted copy
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 9, 2020
@briansull
Copy link
Contributor Author

@sandreenko PTAL
@dotnet/jit-contrib

Copy link
Contributor

@sandreenko sandreenko left a comment

Choose a reason for hiding this comment

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

LGTM, 2 questions and a few nits.

Thank you for extracting this.

//------------------------------------------------------------------------
// CheckDivideByConstOptimized:
// Checks if we will can use the division by constant optimization
// on this node
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: formatting.

Copy link
Contributor

Choose a reason for hiding this comment

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

//      on this node
//      and if so sets the flag GTF_DIV_BY_CNS_OPT and

it looks like an unintentional new line.

GenTree* divisor = gtGetOp2()->gtEffectiveVal(/*commaOnly*/ true);
if (divisor->OperIs(GT_CNS_INT))
{
divisor->gtFlags |= GTF_DONT_CSE;
Copy link
Contributor

Choose a reason for hiding this comment

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

you have answered earlier why we check GTF_DONT_CSE in optVNConstantPropOnJTrue and as I understood the idea was to replace constant values with CSE lclVars, is my understanding correct?
If so why do we forbid replacing these const with a CSE lclVar here?

Copy link
Contributor Author

@briansull briansull Jul 9, 2020

Choose a reason for hiding this comment

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

Because changing the CNS_INT to a CSE LclVar will cause lower to fail to use the multiplication by reciprocal optimization.
Thus we would generate a slow divide instruction instead of the faster multiply or shift sequence.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I think I understand now.

From these two comments:

Doing a constant prop here would replace the CSE LclVar with the original constant.
Essentially undoing the CSE of the constant.

Because changing the CNS_INT to a CSE LclVar will cause lower to fail to use the multiplication by reciprocal optimization.

In general we want to set DONT_CSE on constants under DIV/MOD so they are not replaced with a CSE LCL_VAR. Other constants (that are not under 'DIV/MOD) are not marked as DONT_CSEso they could be replaced and, once they are replaced, we mark it withDONT_CSE` because it is their final state. Is it correct?

}
else
{
printf(" -0x%llx", -dspIconVal);
Copy link
Contributor

Choose a reason for hiding this comment

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

Starting from VS2013 we have support for "%zd" (and other runtime parts are already using it), so I would suggest to just replace this block with:
printf(" %zd", dspIconVal);
that will handle both 32/64 and negative/positive.

Note: gcc and clang have always supported that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like see these numbers in hex, especially with my shared CSE constant changes where we often have to add or subtract a small offset.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have not seen hex numbers being printed with a negative sign, but maybe it is fine. Thanks for the explanation.

// this - a GenTreeOp node
// comp - the compiler instance
//
void GenTreeOp::CheckDivideByConstOptimized(Compiler* comp)
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want this to happen in minopts (opts.OptimizationEnabled() == false?

Copy link
Contributor Author

@briansull briansull Jul 9, 2020

Choose a reason for hiding this comment

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

I will add a check for minopts to UsesDivideByConstOptimization()

@briansull briansull merged commit 389c981 into dotnet:master Jul 10, 2020
@briansull briansull deleted the cse-part1 branch July 10, 2020 15:34
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants