Skip to content

Commit

Permalink
"Fold overflow operations in value numbering" (second attempt after r…
Browse files Browse the repository at this point in the history
…evert) (#51440)

* Added a missing license header

* Added a test verifying that checked arithmetic is correct

* Added a test verifying that checked casts are correct

* Disabled the test for checked casts on Mono

* Refactored VNEvalShouldFold

* Refactored gtFoldExprConst to use helpers and follow the common code style

* Fixed the comment stating TYP_BYREF has no zero value

* Moved checking of overflow for arithmetic operations from gtFoldExprConst into a separate namespace

* Implemented folding of overflow arithmetic in value numbering

* Fixed some typos in valuenum.cpp/h

* Added identity-based evaluation for overflow arithmetic

* Made the definition of var_types a standalone header so that it can be safely #included'ed in utils.h

* Refactored gtFoldExpr some more, moved the overflow checking logic to CheckedOps, implemented overflow checking for floating point -> integer casts

* Implemented folding of checked casts in value numbering

* Demote the tests to Tier1

They throw and catch quite a few exceptions.

* Fixed a comment

UINT32 -> UINT64

* Made arithmetic CheckedOps functions templated

Reduces code duplication and obviates the need for
some conditions and casts.

They use the implementation from the Long* variants of
the old functions, except for "SubOverflows", where some
instantiations, unreachable at runtime, were using "size_t" as the
type argument and causing warnings. The relevant part of "AddOverflows"
has been inlined into "SubOverflows".

* Move the locals under "if" to avoid shadowing

* Use ClrSafeInt instead of custom code

* Fix a copy and paste mistake

Co-authored-by: Anton Lapounov <anton.lapounov@microsoft.com>

* Update src/coreclr/jit/utils.cpp

* Apply suggestions from code review

Co-authored-by: Anton Lapounov <anton.lapounov@microsoft.com>

* Assert type != TYP_BYREF in VNEvalShouldFold

The method is not prepared to handle them.
Also add a note about that to the header.
Also delete TODO-Review about it.

Right now the only caller of VNEvalShouldFold guards against
TYP_BYREF folding, so this assert is a safety measure against
future callers not taking byrefs into account.

* Drop the MAX_ prefix from MIN

Co-authored-by: Anton Lapounov <anton.lapounov@microsoft.com>
  • Loading branch information
SingleAccretion and AntonLapounov authored May 26, 2021
1 parent 5c875e4 commit 9603754
Show file tree
Hide file tree
Showing 24 changed files with 49,272 additions and 649 deletions.
1 change: 1 addition & 0 deletions src/coreclr/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ if (CLR_CMAKE_TARGET_WIN32)
valuenumtype.h
varset.h
vartype.h
vartypesdef.h
)

# Append clrjit.natvis file
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4992,6 +4992,9 @@ GenTree* Compiler::optExtractSideEffListFromConst(GenTree* tree)
bool ignoreRoot = true;

gtExtractSideEffList(tree, &sideEffList, GTF_SIDE_EFFECT, ignoreRoot);

JITDUMP("Extracted side effects from a constant tree [%06u]:\n", tree->gtTreeID);
DISPTREE(sideEffList);
}

return sideEffList;
Expand Down
Loading

0 comments on commit 9603754

Please sign in to comment.