https://gcc.gnu.org/g:600cab162c561c3061317c998972b0ed1b681d5b

commit r15-5441-g600cab162c561c3061317c998972b0ed1b681d5b
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Tue Nov 19 10:25:57 2024 +0100

    bitintlower: Handle PAREN_EXPR [PR117459]
    
    The following patch handles PAREN_EXPR in bitint lowering, and handles it
    as an optimization barrier, so that temporary arithmetics from PAREN_EXPR
    isn't mixed with temporary arithmetics from outside of the PAREN_EXPR.
    
    2024-11-19  Jakub Jelinek  <ja...@redhat.com>
    
            PR middle-end/117459
            * gimple-lower-bitint.cc (bitint_large_huge::handle_stmt,
            bitint_large_huge::lower_stmt): Handle PAREN_EXPR.
    
            * gcc.dg/torture/bitint-74.c: New test.

Diff:
---
 gcc/gimple-lower-bitint.cc               |  5 ++++-
 gcc/testsuite/gcc.dg/torture/bitint-74.c | 27 +++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index 6fc425375b12..ea56c4c5bf8b 100644
--- a/gcc/gimple-lower-bitint.cc
+++ b/gcc/gimple-lower-bitint.cc
@@ -2143,6 +2143,7 @@ bitint_large_huge::handle_stmt (gimple *stmt, tree idx)
                                                idx),
                                gimple_assign_rhs2 (stmt), idx);
        case SSA_NAME:
+       case PAREN_EXPR:
        case INTEGER_CST:
          return handle_operand (gimple_assign_rhs1 (stmt), idx);
        CASE_CONVERT:
@@ -5609,7 +5610,9 @@ bitint_large_huge::lower_stmt (gimple *stmt)
       || gimple_store_p (stmt)
       || gimple_assign_load_p (stmt)
       || eq_p
-      || mergeable_cast_p)
+      || mergeable_cast_p
+      || (is_gimple_assign (stmt)
+         && gimple_assign_rhs_code (stmt) == PAREN_EXPR))
     {
       lhs = lower_mergeable_stmt (stmt, cmp_code, cmp_op1, cmp_op2);
       if (!eq_p)
diff --git a/gcc/testsuite/gcc.dg/torture/bitint-74.c 
b/gcc/testsuite/gcc.dg/torture/bitint-74.c
new file mode 100644
index 000000000000..f9abe2367656
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/bitint-74.c
@@ -0,0 +1,27 @@
+/* PR middle-end/117459 */
+/* { dg-do run { target bitint } } */
+/* { dg-options "-std=c23" } */
+/* { dg-skip-if "" { ! run_expensive_tests }  { "*" } { "-O0" "-O2" } } */
+/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
+
+#if __BITINT_MAXWIDTH__ >= 255
+_BitInt(255) b, c, d;
+
+_BitInt(255)
+foo ()
+{
+  return __builtin_assoc_barrier (b + c) + d;
+}
+#endif
+
+int
+main ()
+{
+#if __BITINT_MAXWIDTH__ >= 255
+  b = 
3162082328713384445049140446737468449630746270013462291267283007210433157591wb;
+  c = 
12998515555477887328635550261966833804427562203752161174274777867442907371807wb;
+  d = 
5016523343681809792116154509287659112784399275423992541459788346980443294044wb;
+  if (foo () != 
21177121227873081565800845217991961366842707749189616007001849221633783823442wb)
+    __builtin_abort ();
+#endif
+}

Reply via email to