diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2016-12-07 17:32:56 +0100 |
|---|---|---|
| committer | Christopher Li <sparse@chrisli.org> | 2017-02-13 09:34:46 +0800 |
| commit | 38bad4d8816cb2aaf4c86a972315dbdbecad2a80 (patch) | |
| tree | 68c569ee77aa565a919feb1f57986c78cfc699b9 /validation/optim | |
| parent | a0886db12307d2633b04ec44342099a2955794a5 (diff) | |
| download | sparse-dev-38bad4d8816cb2aaf4c86a972315dbdbecad2a80.tar.gz | |
simplify '(x op x)' to '0', '1' or 'x'
Most binops can be simplified when their two operands are
identical. For example '(x ^ x)' can be simplified into '0'.
The cases '(x / x)' and '(x % x)' are not simplified since this
is correct only when x is not zero.
The cases '(x || x)' and '(x && x)' are not simplified because
it's only correct when the operands are booleans/have already
been compared against zero and the linearization don't enforce that.
This patch add the code for these simplifications as well as
their corresponding test cases.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Signed-off-by: Christopher Li <sparse@chrisli.org>
Diffstat (limited to 'validation/optim')
| -rw-r--r-- | validation/optim/binops-same-args.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/validation/optim/binops-same-args.c b/validation/optim/binops-same-args.c new file mode 100644 index 00000000..9285655d --- /dev/null +++ b/validation/optim/binops-same-args.c @@ -0,0 +1,49 @@ +typedef unsigned int u32; + +int ssub(int a) { return a - a; } +u32 usub(u32 a) { return a - a; } + +int sdiv(int a) { return a / a; } +u32 udiv(u32 a) { return a / a; } +int smod(int a) { return a % a; } +u32 umod(u32 a) { return a % a; } + +int seq(int a) { return a == a; } +int sne(int a) { return a != a; } +int slt(int a) { return a < a; } +int sgt(int a) { return a > a; } +int sle(int a) { return a <= a; } +int sge(int a) { return a >= a; } + +u32 ueq(u32 a) { return a == a; } +u32 une(u32 a) { return a != a; } +u32 ult(u32 a) { return a < a; } +u32 ugt(u32 a) { return a > a; } +u32 ule(u32 a) { return a <= a; } +u32 uge(u32 a) { return a >= a; } + +u32 xor(u32 a) { return a ^ a; } + +u32 ior(u32 a) { return a | a; } +u32 and(u32 a) { return a & a; } + +/* + * check-name: double-unop + * check-command: test-linearize -Wno-decl $file + * check-output-ignore + * + * check-output-excludes: sub\\. + * check-output-contains: divs\\. + * check-output-contains: divu\\. + * check-output-contains: mods\\. + * check-output-contains: modu\\. + * check-output-excludes: seteq\\. + * check-output-excludes: setne\\. + * check-output-excludes: set[gl]t\\. + * check-output-excludes: set[gl]e\\. + * check-output-excludes: set[ab]\\. + * check-output-excludes: set[ab]e\\. + * check-output-excludes: xor\\. + * check-output-excludes: or\\. + * check-output-excludes: and\\. + */ |
