diff options
| author | Jorropo <jorropo.pgm@gmail.com> | 2024-01-10 07:31:57 +0100 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-01-23 00:02:36 +0000 |
| commit | bbd0bc22ea4bc447a4d009db7d5137688820896d (patch) | |
| tree | 2bc5744f46afe2f2d8e4da9be085d5144a6a0eb1 /src/cmd/compile/internal/ssa/_gen/generic.rules | |
| parent | 370f1a88edfec10c071fbf700328048a83bee9fc (diff) | |
| download | go-bbd0bc22ea4bc447a4d009db7d5137688820896d.tar.xz | |
cmd/compile: improve integer comparisons with numeric bounds
This do:
- Fold always false or always true comparisons for ints and uint.
- Reduce < and <= where the true set is only one value to == with such value.
Change-Id: Ie9e3f70efd1845bef62db56543f051a50ad2532e
Reviewed-on: https://go-review.googlesource.com/c/go/+/555135
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/cmd/compile/internal/ssa/_gen/generic.rules')
| -rw-r--r-- | src/cmd/compile/internal/ssa/_gen/generic.rules | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/ssa/_gen/generic.rules b/src/cmd/compile/internal/ssa/_gen/generic.rules index aeda62591a..4c475d31e0 100644 --- a/src/cmd/compile/internal/ssa/_gen/generic.rules +++ b/src/cmd/compile/internal/ssa/_gen/generic.rules @@ -601,9 +601,49 @@ (Or(64|32|16|8) x (Or(64|32|16|8) x y)) => (Or(64|32|16|8) x y) (Xor(64|32|16|8) x (Xor(64|32|16|8) x y)) => y -// Unsigned comparisons to zero. -(Less(64U|32U|16U|8U) _ (Const(64|32|16|8) [0])) => (ConstBool [false]) -(Leq(64U|32U|16U|8U) (Const(64|32|16|8) [0]) _) => (ConstBool [true]) +// Fold comparisons with numeric bounds +(Less(64|32|16|8)U _ (Const(64|32|16|8) [0])) => (ConstBool [false]) +(Leq(64|32|16|8)U (Const(64|32|16|8) [0]) _) => (ConstBool [true]) +(Less(64|32|16|8)U (Const(64|32|16|8) [-1]) _) => (ConstBool [false]) +(Leq(64|32|16|8)U _ (Const(64|32|16|8) [-1])) => (ConstBool [true]) +(Less64 _ (Const64 [math.MinInt64])) => (ConstBool [false]) +(Less32 _ (Const32 [math.MinInt32])) => (ConstBool [false]) +(Less16 _ (Const16 [math.MinInt16])) => (ConstBool [false]) +(Less8 _ (Const8 [math.MinInt8 ])) => (ConstBool [false]) +(Leq64 (Const64 [math.MinInt64]) _) => (ConstBool [true]) +(Leq32 (Const32 [math.MinInt32]) _) => (ConstBool [true]) +(Leq16 (Const16 [math.MinInt16]) _) => (ConstBool [true]) +(Leq8 (Const8 [math.MinInt8 ]) _) => (ConstBool [true]) +(Less64 (Const64 [math.MaxInt64]) _) => (ConstBool [false]) +(Less32 (Const32 [math.MaxInt32]) _) => (ConstBool [false]) +(Less16 (Const16 [math.MaxInt16]) _) => (ConstBool [false]) +(Less8 (Const8 [math.MaxInt8 ]) _) => (ConstBool [false]) +(Leq64 _ (Const64 [math.MaxInt64])) => (ConstBool [true]) +(Leq32 _ (Const32 [math.MaxInt32])) => (ConstBool [true]) +(Leq16 _ (Const16 [math.MaxInt16])) => (ConstBool [true]) +(Leq8 _ (Const8 [math.MaxInt8 ])) => (ConstBool [true]) + +// Canonicalize <= on numeric bounds and < near numeric bounds to == +(Leq(64|32|16|8)U x c:(Const(64|32|16|8) [0])) => (Eq(64|32|16|8) x c) +(Leq(64|32|16|8)U c:(Const(64|32|16|8) [-1]) x) => (Eq(64|32|16|8) x c) +(Less(64|32|16|8)U x (Const(64|32|16|8) <t> [1])) => (Eq(64|32|16|8) x (Const(64|32|16|8) <t> [0])) +(Less(64|32|16|8)U (Const(64|32|16|8) <t> [-2]) x) => (Eq(64|32|16|8) x (Const(64|32|16|8) <t> [-1])) +(Leq64 x c:(Const64 [math.MinInt64])) => (Eq64 x c) +(Leq32 x c:(Const32 [math.MinInt32])) => (Eq32 x c) +(Leq16 x c:(Const16 [math.MinInt16])) => (Eq16 x c) +(Leq8 x c:(Const8 [math.MinInt8 ])) => (Eq8 x c) +(Leq64 c:(Const64 [math.MaxInt64]) x) => (Eq64 x c) +(Leq32 c:(Const32 [math.MaxInt32]) x) => (Eq32 x c) +(Leq16 c:(Const16 [math.MaxInt16]) x) => (Eq16 x c) +(Leq8 c:(Const8 [math.MaxInt8 ]) x) => (Eq8 x c) +(Less64 x (Const64 <t> [math.MinInt64+1])) => (Eq64 x (Const64 <t> [math.MinInt64])) +(Less32 x (Const32 <t> [math.MinInt32+1])) => (Eq32 x (Const32 <t> [math.MinInt32])) +(Less16 x (Const16 <t> [math.MinInt16+1])) => (Eq16 x (Const16 <t> [math.MinInt16])) +(Less8 x (Const8 <t> [math.MinInt8 +1])) => (Eq8 x (Const8 <t> [math.MinInt8 ])) +(Less64 (Const64 <t> [math.MaxInt64-1]) x) => (Eq64 x (Const64 <t> [math.MaxInt64])) +(Less32 (Const32 <t> [math.MaxInt32-1]) x) => (Eq32 x (Const32 <t> [math.MaxInt32])) +(Less16 (Const16 <t> [math.MaxInt16-1]) x) => (Eq16 x (Const16 <t> [math.MaxInt16])) +(Less8 (Const8 <t> [math.MaxInt8 -1]) x) => (Eq8 x (Const8 <t> [math.MaxInt8 ])) // Ands clear bits. Ors set bits. // If a subsequent Or will set all the bits |
