Hi,
this patch extends the simplification formerly done in fold_widened_comparison
and now in match.pd to all integral types instead of just integer types, and
comes with an Ada testcase for the enumeral type case.
The patch introduces a failure in the C testsuite:
FAIL: gcc.dg/atomic-noinline.c execution test
because the testcase is broken:
/* The fake external function should return 10. */
if (__atomic_is_lock_free (4, 0) != 10)
abort ();
__atomic_is_lock_free returns a boolean so it cannot return 10...
Tested on x86_64-suse-linux, OK for the mainline?
2015-10-26 Eric Botcazou <ebotca...@adacore.com>
* match.pd (fold_widened_comparison): Apply simplifications to
all integral types.
2015-10-26 Eric Botcazou <ebotca...@adacore.com>
* gcc.dg/atomic-noinline.c: Fix test on __atomic_is_lock_free.
* gcc.dg/atomic-noinline-aux.c: Fix its return type.
* gnat.dg/opt51.adb: New test.
* gnat.dg/opt51_pkg.ads: New helper.
--
Eric Botcazou
Index: match.pd
===================================================================
--- match.pd (revision 229283)
+++ match.pd (working copy)
@@ -2067,12 +2067,11 @@ (define_operator_list RINT BUILT_IN_RINT
&& (TYPE_UNSIGNED (TREE_TYPE (@00))
== TYPE_UNSIGNED (TREE_TYPE (@10))))
|| (TREE_CODE (@10) == INTEGER_CST
- && (TREE_CODE (TREE_TYPE (@00)) == INTEGER_TYPE
- || TREE_CODE (TREE_TYPE (@00)) == BOOLEAN_TYPE)
+ && INTEGRAL_TYPE_P (TREE_TYPE (@00))
&& int_fits_type_p (@10, TREE_TYPE (@00)))))
(cmp @00 (convert @10))
(if (TREE_CODE (@10) == INTEGER_CST
- && TREE_CODE (TREE_TYPE (@00)) == INTEGER_TYPE
+ && INTEGRAL_TYPE_P (TREE_TYPE (@00))
&& !int_fits_type_p (@10, TREE_TYPE (@00)))
(with
{
Index: testsuite/gcc.dg/atomic-noinline-aux.c
===================================================================
--- testsuite/gcc.dg/atomic-noinline-aux.c (revision 229283)
+++ testsuite/gcc.dg/atomic-noinline-aux.c (working copy)
@@ -64,7 +64,7 @@ __atomic_fetch_nand_1 (unsigned char *p,
return ret;
}
-int __atomic_is_lock_free (int i, void *p)
+bool __atomic_is_lock_free (int i, void *p)
{
- return 10;
+ return true;
}
Index: testsuite/gcc.dg/atomic-noinline.c
===================================================================
--- testsuite/gcc.dg/atomic-noinline.c (revision 229283)
+++ testsuite/gcc.dg/atomic-noinline.c (working copy)
@@ -46,10 +46,9 @@ main ()
if (cs != 1)
abort ();
- /* The fake external function should return 10. */
- if (__atomic_is_lock_free (4, 0) != 10)
+ if (!__atomic_is_lock_free (4, 0))
abort ();
-
+
/* PR 51040 was caused by arithmetic code not patching up nand_fetch properly
when used an an external function. Look for proper return value here. */
ac = 0x3C;
@@ -59,6 +58,3 @@ main ()
return 0;
}
-
-
-
-- { dg-do compile }
-- { dg-options "-O2 -fdump-tree-optimized" }
with Opt51_Pkg; use Opt51_Pkg;
procedure Opt51 (E: Enum; F : out Float) is
begin
case (E) is
when One =>
F := 1.0;
when Two =>
F := 2.0;
when Three =>
F := 3.0;
when others =>
raise Program_Error;
end case;
end;
-- { dg-final { scan-tree-dump-not "check_PE_Explicit_Raise" "optimized" } }
package Opt51_Pkg is
type Enum is (One, Two, Three);
end Opt51_Pkg;