]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end/117137 - expansion issue with vector equality compares
authorRichard Biener <rguenther@suse.de>
Tue, 15 Oct 2024 07:48:10 +0000 (09:48 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 15 Oct 2024 09:06:30 +0000 (11:06 +0200)
When expanding a COND_EXPR with a vector equality compare as condition
expand_cond_expr_using_cmove fails to properly go the cbranch path.
I failed to massage it's twisted logic so the simple fix is to make
sure to expand a vector condition separately which also generates
the expected code for the testcase:

        ptest   %xmm0, %xmm0
        cmovne  %edi, %eax

PR middle-end/117137
* expr.cc (expand_cond_expr_using_cmove): Make sure to
expand vector comparisons separately.

* gcc.dg/torture/pr117137.c: New testcase.

gcc/expr.cc
gcc/testsuite/gcc.dg/torture/pr117137.c [new file with mode: 0644]

index 7a471f20e794a9ca08b2f37d40c5bedcdd032721..da486cf85fdd3403fc5b1676d8794e9c9d7df0a8 100644 (file)
@@ -9524,7 +9524,8 @@ expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED,
                   EXPAND_NORMAL);
 
   if (TREE_CODE (treeop0) == SSA_NAME
-      && (srcstmt = get_def_for_expr_class (treeop0, tcc_comparison)))
+      && (srcstmt = get_def_for_expr_class (treeop0, tcc_comparison))
+      && !VECTOR_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (srcstmt))))
     {
       type = TREE_TYPE (gimple_assign_rhs1 (srcstmt));
       enum tree_code cmpcode = gimple_assign_rhs_code (srcstmt);
@@ -9534,7 +9535,8 @@ expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED,
       unsignedp = TYPE_UNSIGNED (type);
       comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
     }
-  else if (COMPARISON_CLASS_P (treeop0))
+  else if (COMPARISON_CLASS_P (treeop0)
+          && !VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (treeop0, 0))))
     {
       type = TREE_TYPE (TREE_OPERAND (treeop0, 0));
       enum tree_code cmpcode = TREE_CODE (treeop0);
diff --git a/gcc/testsuite/gcc.dg/torture/pr117137.c b/gcc/testsuite/gcc.dg/torture/pr117137.c
new file mode 100644 (file)
index 0000000..b6ce78d
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-msse4" { target { x86_64-*-* i?86-*-* } } } */
+
+long x[2];
+
+int
+foo (int c)
+{
+  long x0 = x[0], x1 = x[1];
+  int t = x0 != 0 | x1 != 0;
+  c *= t;
+  return c;
+}