https://gcc.gnu.org/g:79b881df72c946f2ba61879c36ae93b0cb974617

commit r15-4350-g79b881df72c946f2ba61879c36ae93b0cb974617
Author: Richard Biener <rguent...@suse.de>
Date:   Tue Oct 15 09:48:10 2024 +0200

    middle-end/117137 - expansion issue with vector equality compares
    
    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.

Diff:
---
 gcc/expr.cc                             |  6 ++++--
 gcc/testsuite/gcc.dg/torture/pr117137.c | 13 +++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/gcc/expr.cc b/gcc/expr.cc
index 7a471f20e794..da486cf85fdd 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 000000000000..b6ce78d86087
--- /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;
+}

Reply via email to