Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitac46299

Browse files
committed
JIT: Remove double-{negation,not} in during morph phase
-fixes#13647- Deals with arithmetic negation as well as bitwise-not- Co-authored with@EgorBo holding my hand :)
1 parent661ac50 commitac46299

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

‎src/coreclr/src/jit/morph.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13585,6 +13585,12 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac)
1358513585

1358613586
case GT_NOT:
1358713587
case GT_NEG:
13588+
// Remove double negation/not
13589+
if (op1->OperIs(oper) && opts.OptimizationEnabled())
13590+
{
13591+
GenTree* child = op1->AsOp()->gtGetOp1();
13592+
return child;
13593+
}
1358813594

1358913595
/* Any constant cases should have been folded earlier */
1359013596
noway_assert(!op1->OperIsConst() || !opts.OptEnabled(CLFLG_CONSTANTFOLD) || optValnumCSE_phase);
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
usingSystem;
2+
usingSystem.Runtime.CompilerServices;
3+
4+
namespacecoreclr_test_13647
5+
{
6+
classdoublenegate
7+
{
8+
staticint_dummyValueInt=6;
9+
staticdouble_dummyValueDouble=6.0;
10+
11+
staticintMain(string[]args)
12+
{
13+
if(Test1()&&Test2()&&Test3()){
14+
Console.WriteLine("PASSED");
15+
return100;
16+
}
17+
Console.WriteLine("FAILED");
18+
return1;
19+
}
20+
21+
staticboolTest1()
22+
{
23+
varx=DoubleNegationInt(6);
24+
vary=
25+
DoubleNegationInt(
26+
DoubleNegationInt(
27+
DoubleNegationInt(x)));
28+
varz=DoubleNegationInt(_dummyValueInt);
29+
30+
if(x==6&&y==6&&z==6)
31+
returntrue;
32+
returnfalse;
33+
}
34+
35+
[MethodImpl(MethodImplOptions.AggressiveOptimization|MethodImplOptions.AggressiveInlining)]
36+
staticintNegationInt(intvalue)=>-value;
37+
38+
[MethodImpl(MethodImplOptions.AggressiveOptimization|MethodImplOptions.AggressiveInlining)]
39+
staticintDoubleNegationInt(intvalue)=>NegationInt(NegationInt(value));
40+
41+
staticboolTest2()
42+
{
43+
varx=DoubleNegationDouble(6.0);
44+
vary=
45+
DoubleNegationDouble(
46+
DoubleNegationDouble(
47+
DoubleNegationDouble(x)));
48+
varz=DoubleNegationDouble(_dummyValueDouble);
49+
50+
if(x==6.0&&y==6.0&&z==6.0)
51+
returntrue;
52+
returnfalse;
53+
}
54+
55+
[MethodImpl(MethodImplOptions.AggressiveOptimization|MethodImplOptions.AggressiveInlining)]
56+
staticdoubleNegationDouble(doublevalue)=>-value;
57+
58+
[MethodImpl(MethodImplOptions.AggressiveOptimization|MethodImplOptions.AggressiveInlining)]
59+
staticdoubleDoubleNegationDouble(doublevalue)=>NegationDouble(NegationDouble(value));
60+
61+
staticboolTest3()
62+
{
63+
varx=DoubleNotInt(6);
64+
vary=
65+
DoubleNotInt(
66+
DoubleNotInt(
67+
DoubleNotInt(x)));
68+
varz=DoubleNotInt(_dummyValueInt);
69+
70+
if(x==6&&y==6&&z==6)
71+
returntrue;
72+
returnfalse;
73+
}
74+
75+
[MethodImpl(MethodImplOptions.AggressiveOptimization|MethodImplOptions.AggressiveInlining)]
76+
staticintNotInt(intvalue)=>~value;
77+
78+
[MethodImpl(MethodImplOptions.AggressiveOptimization|MethodImplOptions.AggressiveInlining)]
79+
staticintDoubleNotInt(intvalue)=>NotInt(NotInt(value));
80+
}
81+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<ProjectSdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<DebugType>None</DebugType>
5+
</PropertyGroup>
6+
<PropertyGroup>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<CompileInclude="doublenegate.cs" />
10+
</ItemGroup>
11+
</Project>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp