]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/122647 - missing bool pattern for bool -> float conversion
authorRichard Biener <rguenther@suse.de>
Wed, 12 Nov 2025 09:03:23 +0000 (10:03 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 12 Nov 2025 10:20:05 +0000 (11:20 +0100)
The following adds missing support for bool to float conversion which
can be exposed via C++ __builtin_bit_cast.  It also corrects a too
lose check in vectorizable_conversion which would have resolved the
ICE but left us with the missed optimization.

PR tree-optimization/122647
* tree-vect-stmts.cc (vectorizable_conversion): Fix guard on
bool to non-bool conversion.
* tree-vect-patterns.cc (vect_recog_bool_pattern): Also handle
FLOAT_EXPR from bool.

* g++.dg/vect/pr122647.cc: New testcase.

gcc/testsuite/g++.dg/vect/pr122647.cc [new file with mode: 0644]
gcc/tree-vect-patterns.cc
gcc/tree-vect-stmts.cc

diff --git a/gcc/testsuite/g++.dg/vect/pr122647.cc b/gcc/testsuite/g++.dg/vect/pr122647.cc
new file mode 100644 (file)
index 0000000..d7203bd
--- /dev/null
@@ -0,0 +1,18 @@
+// { dg-do compile }
+
+void av(float *au)
+{
+  for (int i = 0; i < 1024; ++i)
+  {
+    float t = i;
+    int tt = __builtin_bit_cast(int, t);
+    bool t1 = tt;
+    float t2 = t1;
+    int t3 = __builtin_bit_cast(int, t2);
+    bool t4 = t3;
+    float t5 = t5;
+    au[i] = t4;
+  }
+}
+
+// { dg-final { scan-tree-dump "optimized: loop vectorized" "vect" { target { { vect_uintfloat_cvt && vect_float } && vect_bool_cmp } } } }
index 878a045c4364c4b379b9d223631605c4aac32ca4..db510e5f9b9602f380b3cdde7228411ad23b9508 100644 (file)
@@ -5991,10 +5991,10 @@ vect_recog_bool_pattern (vec_info *vinfo,
   hash_set<gimple *> bool_stmts;
 
   if (CONVERT_EXPR_CODE_P (rhs_code)
-      || rhs_code == VIEW_CONVERT_EXPR)
+      || rhs_code == VIEW_CONVERT_EXPR
+      || rhs_code == FLOAT_EXPR)
     {
-      if (! INTEGRAL_TYPE_P (TREE_TYPE (lhs))
-         || VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (lhs)))
+      if (VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (lhs)))
        return NULL;
       vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (lhs));
 
@@ -6023,7 +6023,9 @@ vect_recog_bool_pattern (vec_info *vinfo,
                                  pattern_stmt, new_vectype);
 
          lhs = vect_recog_temp_ssa_var (TREE_TYPE (lhs), NULL);
-         pattern_stmt = gimple_build_assign (lhs, CONVERT_EXPR, tmp);
+         pattern_stmt
+           = gimple_build_assign (lhs, (rhs_code == FLOAT_EXPR
+                                        ? FLOAT_EXPR : CONVERT_EXPR), tmp);
        }
 
       *type_out = vectype;
index 25ec87022f2ad5726dcc71aa1630b655e2ecfe0b..b0f15902c8195c2b7650a5a2b41de389fce7f342 100644 (file)
@@ -5402,7 +5402,7 @@ vectorizable_conversion (vec_info *vinfo,
     }
 
   if (VECTOR_BOOLEAN_TYPE_P (vectype_out)
-      && !VECTOR_BOOLEAN_TYPE_P (vectype_in))
+      != VECTOR_BOOLEAN_TYPE_P (vectype_in))
     {
       if (dump_enabled_p ())
        dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,