diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2021-04-18 00:45:43 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2021-04-18 17:18:57 +0200 |
| commit | 48eb2ca449b7f8e8e0684a2d92c8a1d0224861da (patch) | |
| tree | 18fd21d390a3d696e77fe5e78233fcfc4b019aa2 /validation/optim/canonical-cmp-zero.c | |
| parent | eb4cdd21b7d0cedbbeff7f70e24473706ccce5a6 (diff) | |
| download | sparse-dev-48eb2ca449b7f8e8e0684a2d92c8a1d0224861da.tar.gz | |
canonicalize constant signed compares toward zero
Currently, signed compares against a constant are canonicalized
toward the smallest possible constant. So, the following
canonicalization are done:
x < 256 --> x <= 255
x < -2047 --> x <= -2048
This has two advantages:
1) it maximalizes the number of constants possible for a given bit size.
2) it allows to remove all < and all >=
But it has also a serious disadvantages: a simple comparison against
zero, like:
x >= 0
is canonicalized into:
x > -1
Which can be more costly for some architectures if translated as such ,
is also less readable than the version using 0 and is also sometimes
quite more complicated to match in some simplification patterns.
So, canonicalize it using 'towards 0' / using the smallest constant
in absolute value.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation/optim/canonical-cmp-zero.c')
| -rw-r--r-- | validation/optim/canonical-cmp-zero.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/validation/optim/canonical-cmp-zero.c b/validation/optim/canonical-cmp-zero.c new file mode 100644 index 00000000..e01a00e6 --- /dev/null +++ b/validation/optim/canonical-cmp-zero.c @@ -0,0 +1,74 @@ +int f00(int x) { return x >= 0; } +int f01(int x) { return x > -1; } +int f02(int x) { return x < 1; } +int f03(int x) { return x <= 0; } + +int f10(int x) { return x < 16; } +int f11(int x) { return x <= 15; } + +int f20(int x) { return x > -9; } +int f21(int x) { return x >= -8; } + +/* + * check-name: canonical-cmp-zero + * check-command: test-linearize -Wno-decl $file + * + * check-output-start +f00: +.L0: + <entry-point> + setge.32 %r2 <- %arg1, $0 + ret.32 %r2 + + +f01: +.L2: + <entry-point> + setge.32 %r5 <- %arg1, $0 + ret.32 %r5 + + +f02: +.L4: + <entry-point> + setle.32 %r8 <- %arg1, $0 + ret.32 %r8 + + +f03: +.L6: + <entry-point> + setle.32 %r11 <- %arg1, $0 + ret.32 %r11 + + +f10: +.L8: + <entry-point> + setle.32 %r14 <- %arg1, $15 + ret.32 %r14 + + +f11: +.L10: + <entry-point> + setle.32 %r17 <- %arg1, $15 + ret.32 %r17 + + +f20: +.L12: + <entry-point> + setge.32 %r20 <- %arg1, $0xfffffff8 + ret.32 %r20 + + +f21: +.L14: + <entry-point> + setge.32 %r23 <- %arg1, $0xfffffff8 + ret.32 %r23 + + + * check-output-end + */ |
