summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture
diff options
context:
space:
mode:
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2002-06-15 16:55:24 +0000
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2002-06-15 16:55:24 +0000
commit7835f1631a7aa5fc714a0025400cecff89623c1f (patch)
treec9fc91c5bbced804e712ce47aaa7397c5a3ed98d /gcc/testsuite/gcc.c-torture
parentc838fbd9db68b85656198e796d215ead57c8c7e3 (diff)
downloadgcc-7835f1631a7aa5fc714a0025400cecff89623c1f.tar.gz
* fold-const.c (comparison_to_compcode): New function to convert
an comparison TREE CODE into a bit-based representation. (compcode_to_comparison): New function to convert from this bit based representation back to a comparison TREE CODE. (fold_truthop): Simplify (x<y) && (x==y) and related composite comparisons. * gcc.c-tortuture/execute/compare-1.c: New test case. * gcc.c-tortuture/execute/compare-2.c: New test case. * gcc.c-tortuture/execute/compare-3.c: New test case. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@54647 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.c-torture')
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/compare-1.c119
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/compare-2.c24
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/compare-3.c86
3 files changed, 229 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.c-torture/execute/compare-1.c b/gcc/testsuite/gcc.c-torture/execute/compare-1.c
new file mode 100644
index 00000000000..78b465024ea
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/compare-1.c
@@ -0,0 +1,119 @@
+/* Copyright (C) 2002 Free Software Foundation.
+
+ Test for correctness of composite comparisons.
+
+ Written by Roger Sayle, 3rd June 2002. */
+
+extern void abort (void);
+
+int ieq (int x, int y, int ok)
+{
+ if ((x<=y) && (x>=y))
+ {
+ if (!ok) abort ();
+ }
+ else
+ if (ok) abort ();
+
+ if ((x<=y) && (x==y))
+ {
+ if (!ok) abort ();
+ }
+ else
+ if (ok) abort ();
+
+ if ((x<=y) && (y<=x))
+ {
+ if (!ok) abort ();
+ }
+ else
+ if (ok) abort ();
+
+ if ((y==x) && (x<=y))
+ {
+ if (!ok) abort ();
+ }
+ else
+ if (ok) abort ();
+}
+
+int ine (int x, int y, int ok)
+{
+ if ((x<y) || (x>y))
+ {
+ if (!ok) abort ();
+ }
+ else
+ if (ok) abort ();
+}
+
+int ilt (int x, int y, int ok)
+{
+ if ((x<y) && (x!=y))
+ {
+ if (!ok) abort ();
+ }
+ else
+ if (ok) abort ();
+}
+
+int ile (int x, int y, int ok)
+{
+ if ((x<y) || (x==y))
+ {
+ if (!ok) abort ();
+ }
+ else
+ if (ok) abort ();
+}
+
+int igt (int x, int y, int ok)
+{
+ if ((x>y) && (x!=y))
+ {
+ if (!ok) abort ();
+ }
+ else
+ if (ok) abort ();
+}
+
+int ige (int x, int y, int ok)
+{
+ if ((x>y) || (x==y))
+ {
+ if (!ok) abort ();
+ }
+ else
+ if (ok) abort ();
+}
+
+int
+main ()
+{
+ ieq (1, 4, 0);
+ ieq (3, 3, 1);
+ ieq (5, 2, 0);
+
+ ine (1, 4, 1);
+ ine (3, 3, 0);
+ ine (5, 2, 1);
+
+ ilt (1, 4, 1);
+ ilt (3, 3, 0);
+ ilt (5, 2, 0);
+
+ ile (1, 4, 1);
+ ile (3, 3, 1);
+ ile (5, 2, 0);
+
+ igt (1, 4, 0);
+ igt (3, 3, 0);
+ igt (5, 2, 1);
+
+ ige (1, 4, 0);
+ ige (3, 3, 1);
+ ige (5, 2, 1);
+
+ return 0;
+}
+
diff --git a/gcc/testsuite/gcc.c-torture/execute/compare-2.c b/gcc/testsuite/gcc.c-torture/execute/compare-2.c
new file mode 100644
index 00000000000..858df294eca
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/compare-2.c
@@ -0,0 +1,24 @@
+/* Copyright (C) 2002 Free Software Foundation.
+
+ Ensure that the composite comparison optimization doesn't misfire
+ and attempt to combine a signed comparison with an unsigned one.
+
+ Written by Roger Sayle, 3rd June 2002. */
+
+extern void abort (void);
+
+int
+foo (int x, int y)
+{
+ /* If miscompiled the following may become "x == y". */
+ return (x<=y) && ((unsigned int)x >= (unsigned int)y);
+}
+
+int
+main ()
+{
+ if (! foo (-1,0))
+ abort ();
+ return 0;
+}
+
diff --git a/gcc/testsuite/gcc.c-torture/execute/compare-3.c b/gcc/testsuite/gcc.c-torture/execute/compare-3.c
new file mode 100644
index 00000000000..6549c904b52
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/compare-3.c
@@ -0,0 +1,86 @@
+/* Copyright (C) 2002 Free Software Foundation.
+
+ Test for composite comparison always true/false optimization.
+
+ Written by Roger Sayle, 7th June 2002. */
+
+extern void link_error0 ();
+extern void link_error1 ();
+
+void
+test1 (int x, int y)
+{
+ if ((x==y) && (x!=y))
+ link_error0();
+}
+
+void
+test2 (int x, int y)
+{
+ if ((x<y) && (x>y))
+ link_error0();
+}
+
+void
+test3 (int x, int y)
+{
+ if ((x<y) && (y<x))
+ link_error0();
+}
+
+void
+test4 (int x, int y)
+{
+ if ((x==y) || (x!=y))
+ {
+ }
+ else
+ link_error1 ();
+}
+
+void
+test5 (int x, int y)
+{
+ if ((x>=y) || (x<y))
+ {
+ }
+ else
+ link_error1 ();
+}
+
+void
+test6 (int x, int y)
+{
+ if ((x<=y) || (y<x))
+ {
+ }
+ else
+ link_error1 ();
+}
+
+void
+all_tests (int x, int y)
+{
+ test1 (x, y);
+ test2 (x, y);
+ test3 (x, y);
+ test4 (x, y);
+ test5 (x, y);
+ test6 (x, y);
+}
+
+int
+main ()
+{
+ all_tests (0, 0);
+ all_tests (1, 2);
+ all_tests (4, 3);
+
+ return 0;
+}
+
+#ifndef __OPTIMIZE__
+void link_error0() {}
+void link_error1() {}
+#endif /* ! __OPTIMIZE__ */
+