aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/match.pd3
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/pr97325.c15
2 files changed, 17 insertions, 1 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index 952643f..a7032dc 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6196,7 +6196,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
&& direct_internal_fn_supported_p (IFN_CTZ, TREE_TYPE (@0),
OPTIMIZE_FOR_SPEED))
- (plus (CTZ:type @0) { build_one_cst (type); })))
+ (with { tree utype = unsigned_type_for (TREE_TYPE (@0)); }
+ (plus (CTZ:type (convert:utype @0)) { build_one_cst (type); }))))
#endif
(for ffs (BUILT_IN_FFS BUILT_IN_FFSL BUILT_IN_FFSLL
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr97325.c b/gcc/testsuite/gcc.c-torture/execute/pr97325.c
new file mode 100644
index 0000000..f734c85
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr97325.c
@@ -0,0 +1,15 @@
+/* PR tree-optimization/97325 */
+
+unsigned long long
+foo (unsigned long long c)
+{
+ return c ? __builtin_ffs (-(unsigned short) c) : 0;
+}
+
+int
+main ()
+{
+ if (foo (2) != 2)
+ __builtin_abort ();
+ return 0;
+}