From d6e597592a6b0c3abf5d3c7ed148e762ca0b973e Mon Sep 17 00:00:00 2001 From: mertcandav Date: Fri, 31 Jan 2025 22:14:57 +0300 Subject: [PATCH] update compiler optimizations --- src/compiler/compiler-optimizations.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/compiler-optimizations.md b/src/compiler/compiler-optimizations.md index 8d5052e..ff65a38 100644 --- a/src/compiler/compiler-optimizations.md +++ b/src/compiler/compiler-optimizations.md @@ -87,7 +87,8 @@ Enables special optimizations for mathematical operations. - Converts modulo by 2 expressions to equivalent bitwise operation. - Eliminates neutral binary expressions such as such as addition/subtraction with the constant-zero. - Eliminates runtime overflow checking for binary shifing expressions if right operand is constant. -- Eliminates runtime overflow of the `x^0` computations. It will be simplified to `x` expression. +- Eliminates cost of the `x^0`, `0^x`, `x|0`, or `0|x` computations. It will be simplified to `x` expression. +- Eliminates cost of the `x&0`, `0&x` computations. It will be simplified to `0` expression. - Simplifies expressions such as `x+x` to `x<<1` if possible. - Simplifies expressions such as `x-x` to `0` if possible. @@ -97,6 +98,7 @@ Enables special optimizations for mathematical operations. Enables special optimizations for memory accessing. - Skips safety checks such as boundary checking if accessed to array via constant index expression. +- Removes the cost of boundary checking of expressions like `array[i&(len(array)-1)]` for arrays whose length is power of two. - If in a foreach iteration the iterated variable referred to by a immutable index variable is indexed, it is optimized as direct access and the cost of safety measures such as boundary checking is bypassed.
experimental
- If it can be understood that the index value used in any indexing process is within the boundaries, it removes the cost of boundary checking.
experimental
- If it can be understood that the smart pointer is not nil, it removes the cost of nil dereferencing.
experimental