Add gtGetOp2IfPresent()
authorBruce Forstall <brucefo@microsoft.com>
Tue, 7 Feb 2017 04:15:07 +0000 (20:15 -0800)
committerBruce Forstall <brucefo@microsoft.com>
Wed, 8 Feb 2017 23:13:53 +0000 (15:13 -0800)
commit278fd5ee38b82acc3e8e3427a922c86830c337a1
tree10afaf400dd07c1f24d67eb00fae1c0c78e45f91
parent1be986c11a5410d301c4e5cf3a8d81b7684d311a
Add gtGetOp2IfPresent()

It was noticed that many uses of gtGetOp2() fully expect op2 to
exist and be non-nullptr, and the use of gtGetOp2() was simply
for style/readability purposes. However, it has a cost, as it
checks whether the tree is binary first, and returns nullptr if
not. For most cases, this is unecessary and expensive.

Introduce a new gtGetOp2IfPresent() function that captures the
previous behavior: checking if the tree node is binary before
returning op2, or returning nullptr otherwise. gtGetOp2() is
changed to simply return gtOp2 directly, without any checking
in non-DEBUG builds. It can be used if you know the op2 exists.

Most uses of gtGetOp2() were left alone (and hence get the new
behavior). The ones that need the old behavior were renamed
gtGetOp2IfPresent().

Mostly newer code is affected, as older code would generally
access gtOp2 directly, whereas newer code started using gtGetOp2()
for style and symmetry, especially after gtGetOp1() was introduced.

Commit migrated from https://github.com/dotnet/coreclr/commit/8ed2c04cb49593a6b582c0f1a96c3a67da36dfab
14 files changed:
src/coreclr/src/jit/codegenlegacy.cpp
src/coreclr/src/jit/compiler.cpp
src/coreclr/src/jit/flowgraph.cpp
src/coreclr/src/jit/gentree.cpp
src/coreclr/src/jit/gentree.h
src/coreclr/src/jit/lower.h
src/coreclr/src/jit/lsraarm.cpp
src/coreclr/src/jit/lsraarm64.cpp
src/coreclr/src/jit/lsraxarch.cpp
src/coreclr/src/jit/morph.cpp
src/coreclr/src/jit/rationalize.cpp
src/coreclr/src/jit/regalloc.cpp
src/coreclr/src/jit/registerfp.cpp
src/coreclr/src/jit/stackfp.cpp