-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[Outdated] Implementation of CSE for GT_CNS_INT benefits ARM64. #36831
Changes from all commits
a7a3706
0c89250
e1716fa
fc4cddb
333ceef
33fb8b0
5d017f8
9d87148
f427256
140d6dd
29d02ea
e778781
84a208c
d5ccbdb
5b8b9bd
5a8fac2
5effd8e
d6ed1b1
640e945
2240392
0d84d8c
78ae001
34079eb
baf350e
0f66687
421fd5a
4b429fd
8340e81
83b5dc2
435bdd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3236,7 +3236,8 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions, Gen | |
return nullptr; | ||
} | ||
|
||
AssertionDsc* curAssertion = optGetAssertion(index); | ||
AssertionDsc* curAssertion = optGetAssertion(index); | ||
bool assertionKindIsEqual = (curAssertion->assertionKind == OAK_EQUAL); | ||
|
||
// Allow or not to reverse condition for OAK_NOT_EQUAL assertions. | ||
bool allowReverse = true; | ||
|
@@ -3251,7 +3252,7 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions, Gen | |
printf("\nVN relop based constant assertion prop in " FMT_BB ":\n", compCurBB->bbNum); | ||
printf("Assertion index=#%02u: ", index); | ||
printTreeID(op1); | ||
printf(" %s ", (curAssertion->assertionKind == OAK_EQUAL) ? "==" : "!="); | ||
printf(" %s ", assertionKindIsEqual ? "==" : "!="); | ||
if (genActualType(op1->TypeGet()) == TYP_INT) | ||
{ | ||
printf("%d\n", vnStore->ConstantValue<int>(vnCns)); | ||
|
@@ -3336,8 +3337,15 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions, Gen | |
|
||
op1->gtVNPair.SetBoth(vnCns); // Preserve the ValueNumPair, as ChangeOperConst/SetOper will clear it. | ||
|
||
// Also set the value number on the relop. | ||
if (curAssertion->assertionKind == OAK_EQUAL) | ||
// set foldResult to either 0 or 1 | ||
bool foldResult = assertionKindIsEqual; | ||
if (tree->gtOper == GT_NE) | ||
{ | ||
foldResult = !foldResult; | ||
} | ||
|
||
// Set the value number on the relop to 1 (true) or 0 (false) | ||
if (foldResult) | ||
{ | ||
tree->gtVNPair.SetBoth(vnStore->VNOneForType(TYP_INT)); | ||
} | ||
|
@@ -4947,6 +4955,12 @@ GenTree* Compiler::optVNConstantPropOnJTrue(BasicBlock* block, GenTree* test) | |
// | ||
Compiler::fgWalkResult Compiler::optVNConstantPropCurStmt(BasicBlock* block, Statement* stmt, GenTree* tree) | ||
{ | ||
// Don't perform const prop on expressions marked with GTF_DONT_CSE | ||
if (!tree->CanCSE()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was it unprofitable or incorrect to do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doing a constant prop here would replace the CSE LclVar with the original constant. |
||
{ | ||
return WALK_CONTINUE; | ||
} | ||
|
||
// Don't propagate floating-point constants into a TYP_STRUCT LclVar | ||
// This can occur for HFA return values (see hfa_sf3E_r.exe) | ||
if (tree->TypeGet() == TYP_STRUCT) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6320,7 +6320,10 @@ class Compiler | |
{ | ||
CSEdsc* csdNextInBucket; // used by the hash table | ||
|
||
unsigned csdHashKey; // the orginal hashkey | ||
size_t csdHashKey; // the orginal hashkey | ||
ssize_t csdConstDefValue; // When we CSE similar constants this is the value that we use as the def | ||
ValueNum csdConstDefVN; // When we CSE similar constants this is the ValueNumber that we use for the LclVar | ||
// assignment | ||
|
||
unsigned csdIndex; // 1..optCSECandidateCount | ||
bool csdLiveAcrossCall; | ||
|
@@ -6353,6 +6356,19 @@ class Compiler | |
// number, this will reflect it; otherwise, NoVN. | ||
}; | ||
|
||
#if defined(TARGET_XARCH) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this block live in target.h? |
||
#define CSE_CONST_SHARED_LOW_BITS 16 | ||
#else | ||
// ARM64 or ARM32 | ||
#define CSE_CONST_SHARED_LOW_BITS 12 | ||
#endif | ||
|
||
#ifdef TARGET_64BIT | ||
#define TARGET_SIGN_BIT (1ULL << 63) | ||
#else | ||
#define TARGET_SIGN_BIT (1ULL << 31) | ||
#endif | ||
|
||
static const size_t s_optCSEhashSize; | ||
CSEdsc** optCSEhash; | ||
CSEdsc** optCSEtab; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a correctness fix? Were we getting wrong VN pair for
!=
in the past?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is incorrectly assigning the wrong constant value number. I found similar code
It was occasionally happening in the framework dlls and the the beq_r8 test cases.
Our code has two chances to fold the expression, the first one will fold compares with two constant arguments,
which is the common case. If that doesn't fold then it tries folding using the value numbers and that path was wrong and caused the beq_r8 tests to fail with my CSE changes.