summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture
diff options
context:
space:
mode:
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2002-05-06 22:59:38 +0000
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2002-05-06 22:59:38 +0000
commit203a24c48cbfcda34d7d513914e2bad55c062925 (patch)
tree42a44a69dbd2f8b714055533a4e34ddf161eabd9 /gcc/testsuite/gcc.c-torture
parent318fdd81915678cdc4e744ad9aa51cbfef2b9fc1 (diff)
downloadgcc-203a24c48cbfcda34d7d513914e2bad55c062925.tar.gz
PR opt/3995
* fold-const.c (sign_bit_p): New function. (fold) [EQ_EXPR]: Use this to convert (A & C) == 0 into A >= 0 and (A & C) != 0 into A < 0, when constant C is the sign bit of A's type. Reapply fold when converting (A & C) == C into (A & C) != 0. (fold_binary_op_with_conditional_arg): Fix typo in comment. testsuite/ * gcc.c-torture/execute/20020506-1.c: New test case. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@53241 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.c-torture')
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/20020506-1.c333
1 files changed, 333 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.c-torture/execute/20020506-1.c b/gcc/testsuite/gcc.c-torture/execute/20020506-1.c
new file mode 100644
index 00000000000..bcbd45bf6ca
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/20020506-1.c
@@ -0,0 +1,333 @@
+/* Copyright (C) 2002 Free Software Foundation.
+
+ Test that (A & C1) op C2 optimizations behave correctly where C1 is
+ a constant power of 2, op is == or !=, and C2 is C1 or zero.
+
+ Written by Roger Sayle, 5th May 2002. */
+
+#include <limits.h>
+
+extern void abort (void);
+
+void test1 (signed char c, int set);
+void test2 (unsigned char c, int set);
+void test3 (short s, int set);
+void test4 (unsigned short s, int set);
+void test5 (int i, int set);
+void test6 (unsigned int i, int set);
+void test7 (long long l, int set);
+void test8 (unsigned long long l, int set);
+
+#ifndef LONG_LONG_MAX
+#define LONG_LONG_MAX __LONG_LONG_MAX__
+#endif
+#ifndef LONG_LONG_MIN
+#define LONG_LONG_MIN (-LONG_LONG_MAX-1)
+#endif
+#ifndef ULONG_LONG_MAX
+#define ULONG_LONG_MAX (LONG_LONG_MAX * 2ULL + 1)
+#endif
+
+
+void
+test1 (signed char c, int set)
+{
+ if ((c & (SCHAR_MAX+1)) == 0)
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+
+ if ((c & (SCHAR_MAX+1)) != 0)
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((c & (SCHAR_MAX+1)) == (SCHAR_MAX+1))
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((c & (SCHAR_MAX+1)) != (SCHAR_MAX+1))
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+}
+
+void
+test2 (unsigned char c, int set)
+{
+ if ((c & (SCHAR_MAX+1)) == 0)
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+
+ if ((c & (SCHAR_MAX+1)) != 0)
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((c & (SCHAR_MAX+1)) == (SCHAR_MAX+1))
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((c & (SCHAR_MAX+1)) != (SCHAR_MAX+1))
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+}
+
+void
+test3 (short s, int set)
+{
+ if ((s & (SHRT_MAX+1)) == 0)
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+
+ if ((s & (SHRT_MAX+1)) != 0)
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((s & (SHRT_MAX+1)) == (SHRT_MAX+1))
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((s & (SHRT_MAX+1)) != (SHRT_MAX+1))
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+}
+
+void
+test4 (unsigned short s, int set)
+{
+ if ((s & (SHRT_MAX+1)) == 0)
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+
+ if ((s & (SHRT_MAX+1)) != 0)
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((s & (SHRT_MAX+1)) == (SHRT_MAX+1))
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((s & (SHRT_MAX+1)) != (SHRT_MAX+1))
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+}
+
+void
+test5 (int i, int set)
+{
+ if ((i & (INT_MAX+1U)) == 0)
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+
+ if ((i & (INT_MAX+1U)) != 0)
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((i & (INT_MAX+1U)) == (INT_MAX+1U))
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((i & (INT_MAX+1U)) != (INT_MAX+1U))
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+}
+
+void
+test6 (unsigned int i, int set)
+{
+ if ((i & (INT_MAX+1U)) == 0)
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+
+ if ((i & (INT_MAX+1U)) != 0)
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((i & (INT_MAX+1U)) == (INT_MAX+1U))
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((i & (INT_MAX+1U)) != (INT_MAX+1U))
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+}
+
+void
+test7 (long long l, int set)
+{
+ if ((l & (LONG_LONG_MAX+1ULL)) == 0)
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+
+ if ((l & (LONG_LONG_MAX+1ULL)) != 0)
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((l & (LONG_LONG_MAX+1ULL)) == (LONG_LONG_MAX+1ULL))
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((l & (LONG_LONG_MAX+1ULL)) != (LONG_LONG_MAX+1ULL))
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+}
+
+void
+test8 (unsigned long long l, int set)
+{
+ if ((l & (LONG_LONG_MAX+1ULL)) == 0)
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+
+ if ((l & (LONG_LONG_MAX+1ULL)) != 0)
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((l & (LONG_LONG_MAX+1ULL)) == (LONG_LONG_MAX+1ULL))
+ {
+ if (!set) abort ();
+ }
+ else
+ if (set) abort ();
+
+ if ((l & (LONG_LONG_MAX+1ULL)) != (LONG_LONG_MAX+1ULL))
+ {
+ if (set) abort ();
+ }
+ else
+ if (!set) abort ();
+}
+
+int
+main ()
+{
+ test1 (0, 0);
+ test1 (SCHAR_MAX, 0);
+ test1 (SCHAR_MIN, 1);
+ test1 (UCHAR_MAX, 1);
+
+ test2 (0, 0);
+ test2 (SCHAR_MAX, 0);
+ test2 (SCHAR_MIN, 1);
+ test2 (UCHAR_MAX, 1);
+
+ test3 (0, 0);
+ test3 (SHRT_MAX, 0);
+ test3 (SHRT_MIN, 1);
+ test3 (USHRT_MAX, 1);
+
+ test4 (0, 0);
+ test4 (SHRT_MAX, 0);
+ test4 (SHRT_MIN, 1);
+ test4 (USHRT_MAX, 1);
+
+ test5 (0, 0);
+ test5 (INT_MAX, 0);
+ test5 (INT_MIN, 1);
+ test5 (UINT_MAX, 1);
+
+ test6 (0, 0);
+ test6 (INT_MAX, 0);
+ test6 (INT_MIN, 1);
+ test6 (UINT_MAX, 1);
+
+ test7 (0, 0);
+ test7 (LONG_LONG_MAX, 0);
+ test7 (LONG_LONG_MIN, 1);
+ test7 (ULONG_LONG_MAX, 1);
+
+ test8 (0, 0);
+ test8 (LONG_LONG_MAX, 0);
+ test8 (LONG_LONG_MIN, 1);
+ test8 (ULONG_LONG_MAX, 1);
+
+ return 0;
+}
+