Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

@damageboy
Copy link

  • fixes #27442
  • Co-authored with @EgorBo holding my hand :)

@EgorBo
Copy link
Member

EgorBo commented Nov 8, 2019

I think you still need to check the overflow flag, the following case should throw an exception, shouldn't it?

checked
{
    int a = int.MaxValue;
    Console.WriteLine(a == -(-a));

    int b = int.MinValue;
    Console.WriteLine(b == -(-b));
}

(should work for TYP_FLOAT/DOUBLE without it)

@AaronRobinsonMSFT
Copy link
Member

/cc @dotnet/jit-contrib

@mikedn
Copy link

mikedn commented Nov 9, 2019

I think you still need to check the overflow flag

There's no overflow flag on GT_NEG.

@damageboy damageboy force-pushed the wip/issue27442 branch 3 times, most recently from b29fb23 to 37077b3 Compare November 9, 2019 16:28
@erozenfeld
Copy link
Member

erozenfeld commented Nov 11, 2019

@EgorBo The C# snippet in your comment will result in sub.ovf msil instructions, not neg. As @mikedn pointed out neg will never result in an overflow. From ECMA-335:

The neg instruction negates value and pushes the result on top of the stack. The return type is the
same as the operand type.
Negation of integral values is standard twos-complement negation. In particular, negating the
most negative number (which does not have a positive counterpart) yields the most negative
number. To detect this overflow use the sub.ovf instruction instead (i.e., subtract from 0). 

Copy link

@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.

The change looks good with 1 nit that is optional, thank you, @damageboy.

Could you please collect jit asm diffs so we now how many methods are affected and make sure there are no unexpected regressions?

In order to do that refer to https://github.com/dotnet/jitutils/blob/master/doc/diffs.md, the final command will look like:

C:\git\tools\jitutils\bin\jit-diff.bat diff -b "F:\git\coreclr\bin\tests\Windows_NT.x64.Checked\Tests\Core_Root_base" -d "F:\git\coreclr\bin\tests\Windows_NT.x64.Checked\Tests\Core_Root_diff" -o F:\diffs --core_root F:\git\coreclr\bin\tests\Windows_NT.x64.Checked\Tests\Core_Root -c

case GT_NOT:
case GT_NEG:
// Remove double negation
if (oper == GT_NEG && op1->OperIs(GT_NEG))

Choose a reason for hiding this comment

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

Nit: It is strange to see an if on switch operand.
I would do

case GT_NEG:
	if (op1->OperIs(GT_NEG))
	{
	    // Remove double negation
		GenTree* child = op1->AsOp()->gtGetOp1();
		return child;
	}
	__fallthrough;
case GT_NOT:
	old code.

Copy link
Author

Choose a reason for hiding this comment

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

Sure thing, it wasn't clear to me what the preferred style is, to keep the commonality or separate cases.

@damageboy damageboy force-pushed the wip/issue27442 branch 3 times, most recently from 2a6f00c to e185071 Compare November 13, 2019 18:11
- fixes #27442
- Co-authored with @EgorBo holding my hand :)
@ViktorHofer ViktorHofer added the * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) label Nov 14, 2019
@maryamariyan
Copy link

Thank you for your contribution. As announced in #27549 the dotnet/runtime repository will be used going forward for changes to this code base. Closing this PR as no more changes will be accepted into master for this repository. If you’d like to continue working on this change please move it to dotnet/runtime.

@BruceForstall
Copy link

@damageboy Are you going to open a PR for this in the https://github.com/dotnet/runtime repo? (Or did you already do so and I missed it?)

@damageboy
Copy link
Author

Yes! I am planning to do this sometime over this weekend :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants