From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 01/16] cmp: adapt testcase for compares' canonicalization
Date: Sun, 8 Nov 2020 02:19:31 +0100 [thread overview]
Message-ID: <20201108011939.94252-2-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20201108011939.94252-1-luc.vanoostenryck@gmail.com>
The current testcase, because it's just checking test-linearize's
output as-is, is very sensitive to small simplification changes.
Fix this by changing the tests into equivalent tests and then just
checking that these tests return '1'. This allows to test only what
really matters for canonicalization and make these tests very robust.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
validation/optim/canonical-cmp.c | 125 ++++---------------------------
1 file changed, 14 insertions(+), 111 deletions(-)
diff --git a/validation/optim/canonical-cmp.c b/validation/optim/canonical-cmp.c
index e0ca7db36368..9b930b1cbeaa 100644
--- a/validation/optim/canonical-cmp.c
+++ b/validation/optim/canonical-cmp.c
@@ -1,124 +1,27 @@
typedef signed int sint;
typedef unsigned int uint;
-sint seq(sint p, sint a) { return (123 == p) ? a : 0; }
-sint sne(sint p, sint a) { return (123 != p) ? a : 0; }
+sint seq(sint p, sint a) { return (123 == p) == (p == 123); }
+sint sne(sint p, sint a) { return (123 != p) == (p != 123); }
-sint slt(sint p, sint a) { return (123 > p) ? a : 0; }
-sint sle(sint p, sint a) { return (123 >= p) ? a : 0; }
-sint sge(sint p, sint a) { return (123 <= p) ? a : 0; }
-sint sgt(sint p, sint a) { return (123 < p) ? a : 0; }
+sint slt(sint p, sint a) { return (123 > p) == (p < 123); }
+sint sle(sint p, sint a) { return (123 >= p) == (p <= 123); }
+sint sge(sint p, sint a) { return (123 <= p) == (p >= 123); }
+sint sgt(sint p, sint a) { return (123 < p) == (p > 123); }
-uint ueq(uint p, uint a) { return (123 == p) ? a : 0; }
-uint une(uint p, uint a) { return (123 != p) ? a : 0; }
+uint ueq(uint p, uint a) { return (123 == p) == (p == 123); }
+uint une(uint p, uint a) { return (123 != p) == (p != 123); }
-uint ubt(uint p, uint a) { return (123 > p) ? a : 0; }
-uint ube(uint p, uint a) { return (123 >= p) ? a : 0; }
-uint uae(uint p, uint a) { return (123 <= p) ? a : 0; }
-uint uat(uint p, uint a) { return (123 < p) ? a : 0; }
+uint ubt(uint p, uint a) { return (123 > p) == (p < 123); }
+uint ube(uint p, uint a) { return (123 >= p) == (p <= 123); }
+uint uae(uint p, uint a) { return (123 <= p) == (p >= 123); }
+uint uat(uint p, uint a) { return (123 < p) == (p > 123); }
/*
* check-name: canonical-cmp
+ * check-description: check that constants move rightside
* check-command: test-linearize -Wno-decl $file
*
+ * check-output-ignore
* check-output-excludes: \\$123,
- *
- * check-output-start
-seq:
-.L0:
- <entry-point>
- seteq.32 %r3 <- %arg1, $123
- select.32 %r4 <- %r3, %arg2, $0
- ret.32 %r4
-
-
-sne:
-.L2:
- <entry-point>
- setne.32 %r8 <- %arg1, $123
- select.32 %r9 <- %r8, %arg2, $0
- ret.32 %r9
-
-
-slt:
-.L4:
- <entry-point>
- setlt.32 %r13 <- %arg1, $123
- select.32 %r14 <- %r13, %arg2, $0
- ret.32 %r14
-
-
-sle:
-.L6:
- <entry-point>
- setle.32 %r18 <- %arg1, $123
- select.32 %r19 <- %r18, %arg2, $0
- ret.32 %r19
-
-
-sge:
-.L8:
- <entry-point>
- setge.32 %r23 <- %arg1, $123
- select.32 %r24 <- %r23, %arg2, $0
- ret.32 %r24
-
-
-sgt:
-.L10:
- <entry-point>
- setgt.32 %r28 <- %arg1, $123
- select.32 %r29 <- %r28, %arg2, $0
- ret.32 %r29
-
-
-ueq:
-.L12:
- <entry-point>
- seteq.32 %r33 <- %arg1, $123
- select.32 %r34 <- %r33, %arg2, $0
- ret.32 %r34
-
-
-une:
-.L14:
- <entry-point>
- setne.32 %r38 <- %arg1, $123
- select.32 %r39 <- %r38, %arg2, $0
- ret.32 %r39
-
-
-ubt:
-.L16:
- <entry-point>
- setb.32 %r43 <- %arg1, $123
- select.32 %r44 <- %r43, %arg2, $0
- ret.32 %r44
-
-
-ube:
-.L18:
- <entry-point>
- setbe.32 %r48 <- %arg1, $123
- select.32 %r49 <- %r48, %arg2, $0
- ret.32 %r49
-
-
-uae:
-.L20:
- <entry-point>
- setae.32 %r53 <- %arg1, $123
- select.32 %r54 <- %r53, %arg2, $0
- ret.32 %r54
-
-
-uat:
-.L22:
- <entry-point>
- seta.32 %r58 <- %arg1, $123
- select.32 %r59 <- %r58, %arg2, $0
- ret.32 %r59
-
-
- * check-output-end
*/
--
2.29.2
next prev parent reply other threads:[~2020-11-08 1:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-08 1:19 [PATCH 00/16] simplify & canonicalize compares Luc Van Oostenryck
2020-11-08 1:19 ` Luc Van Oostenryck [this message]
2020-11-08 1:19 ` [PATCH 02/16] cmp: add testcases for the simplification of compares Luc Van Oostenryck
2020-11-08 1:19 ` [PATCH 03/16] cmp: add signed/unsigned to opcode table Luc Van Oostenryck
2020-11-08 1:19 ` [PATCH 04/16] cmp: move some code in a separate function: simplify_compare_constant() Luc Van Oostenryck
2020-11-08 1:19 ` [PATCH 05/16] cmp: use a few helpers for the simplification of compares Luc Van Oostenryck
2020-11-08 1:19 ` [PATCH 06/16] cmp: canonicalize unsigned (x {<,>=} C) --> (x {<=,>} C-1) Luc Van Oostenryck
2020-11-08 1:19 ` [PATCH 07/16] cmp: simplify unsigned (x {<=,>} UMAX) into {1,0} Luc Van Oostenryck
2020-11-08 1:19 ` [PATCH 08/16] cmp: canonicalize unsigned compare with UMAX or UMAX-1 Luc Van Oostenryck
2020-11-08 1:19 ` [PATCH 09/16] cmp: canonicalize unsigned (x {<=,>} SMAX) Luc Van Oostenryck
2020-11-08 1:21 ` [PATCH 10/16] cmp: simplify sext(x) cmp C --> x cmp C Luc Van Oostenryck
2020-11-08 1:21 ` [PATCH 11/16] cmp: simplify zext(x) " Luc Van Oostenryck
2020-11-08 1:21 ` [PATCH 12/16] cmp: simplify sext(x) cmps {SMAX,SMIN} Luc Van Oostenryck
2020-11-08 1:21 ` [PATCH 13/16] cmp: canonicalize sext(x) cmpu C (with C >= SMAX) Luc Van Oostenryck
2020-11-08 1:21 ` [PATCH 14/16] cmp: simplify zext(x) cmps C Luc Van Oostenryck
2020-11-08 1:21 ` [PATCH 15/16] cmp: simplify zext(x) cmpu C Luc Van Oostenryck
2020-11-08 1:21 ` [PATCH 16/16] cmp: simplify compares and sign/zero extend Luc Van Oostenryck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201108011939.94252-2-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).