diff mbox series

middle-end/117137 - expansion issue with vector equality compares

Message ID 20241015082658.CA9FA3858D33@sourceware.org
State New
Headers show
Series middle-end/117137 - expansion issue with vector equality compares | expand

Commit Message

Richard Biener Oct. 15, 2024, 8:26 a.m. UTC
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

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.  Will
push if it succeeds.

Richard.

	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                             |  6 ++++--
 gcc/testsuite/gcc.dg/torture/pr117137.c | 13 +++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr117137.c
diff mbox series

Patch

diff --git a/gcc/expr.cc b/gcc/expr.cc
index 7a471f20e79..da486cf85fd 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -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
index 00000000000..b6ce78d8608
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr117137.c
@@ -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;
+}