[gcc r15-5056] trans-mem: Fix ICE caused by expand_assign_tm

2024-11-09 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:fe908af7dfc95c22284baf544279743a3389d4de

commit r15-5056-gfe908af7dfc95c22284baf544279743a3389d4de
Author: Jakub Jelinek 
Date:   Sat Nov 9 11:42:30 2024 +0100

trans-mem: Fix ICE caused by expand_assign_tm

My https://gcc.gnu.org/pipermail/gcc-patches/2024-November/668065.html
patch regressed
+FAIL: g++.dg/tm/pr45940-3.C  -std=gnu++11 (internal compiler error: in 
create_tmp_var, at gimple-expr.cc:484)
+FAIL: g++.dg/tm/pr45940-3.C  -std=gnu++11 (test for excess errors)
+FAIL: g++.dg/tm/pr45940-3.C  -std=gnu++14 (internal compiler error: in 
create_tmp_var, at gimple-expr.cc:484)
+FAIL: g++.dg/tm/pr45940-3.C  -std=gnu++14 (test for excess errors)
...
+FAIL: g++.dg/tm/pr45940-4.C  -std=gnu++26 (internal compiler error: in 
create_tmp_var, at gimple-expr.cc:484)
+FAIL: g++.dg/tm/pr45940-4.C  -std=gnu++26 (test for excess errors)
+FAIL: g++.dg/tm/pr45940-4.C  -std=gnu++98 (internal compiler error: in 
create_tmp_var, at gimple-expr.cc:484)
+FAIL: g++.dg/tm/pr45940-4.C  -std=gnu++98 (test for excess errors)
tests, but it turns out it is a preexisting bug.
If I modify the pr45940-3.C testcase
--- gcc/testsuite/g++.dg/tm/pr45940-3.C 2020-01-12 11:54:37.258400660 +0100
+++ gcc/testsuite/g++.dg/tm/pr45940-3.C 2024-11-08 10:35:11.918390743 +0100
@@ -16,6 +16,7 @@ class sp_counted_base
 {
 protected:
 int use_count_;// #shared
+int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, 
w, x, y, z, aa, ab, ac, ad, ae, af;
 public:
 __attribute__((transaction_safe))
 virtual void dispose() = 0; // nothrow
then it ICEs already on vanilla trunk.

The problem is that expand_assign_tm just wants to force it into
TM memcpy argument, if is_gimple_reg (reg), then it creates a temporary,
stores the value there and takes temporary address, otherwise it takes
address of rhs.  That doesn't work if rhs is an empty CONSTRUCTOR with
C++ non-POD type (TREE_ADDRESSABLE type), we ICE trying to create temporary,
because we shouldn't be creating a temporary.
Now before my patch with the CONSTRUCTOR only having a vtable pointer
(64bit) and 32-bit field, we gimplified the zero initialization just
as storing of 0s to the 2 fields, but as we are supposed to also clear
padding bits, we now gimplify it as MEM[...] = {}; to make sure
even the padding bits are cleared.  With the adjusted testcase,
we gimplified it even before as MEM[...] = {}; because it was simply
too large and clearing everything looked beneficial.

The following patch fixes this ICE by using TM memset, it is both
wasteful to force zero constructor into a temporary just to TM memcpy
it into the lhs, and in C++ cases like this invalid.

2024-11-09  Jakub Jelinek  

* trans-mem.cc (expand_assign_tm): Don't take address
of empty CONSTRUCTOR, instead use BUILT_IN_TM_MEMSET
to clear lhs in that case.  Formatting fixes.

Diff:
---
 gcc/trans-mem.cc | 35 +--
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/gcc/trans-mem.cc b/gcc/trans-mem.cc
index 893d5afe49fa..e9139b5fe534 100644
--- a/gcc/trans-mem.cc
+++ b/gcc/trans-mem.cc
@@ -2442,26 +2442,33 @@ expand_assign_tm (struct tm_region *region, 
gimple_stmt_iterator *gsi)
  gcall = gimple_build_assign (rtmp, rhs);
  gsi_insert_before (gsi, gcall, GSI_SAME_STMT);
}
+  else if (TREE_CODE (rhs) == CONSTRUCTOR
+  && CONSTRUCTOR_NELTS (rhs) == 0)
+   {
+ /* Don't take address of an empty CONSTRUCTOR, it might not
+work for C++ non-POD constructors at all and otherwise
+would be inefficient.  Use tm memset to clear lhs.  */
+ gcc_assert (!load_p && store_p);
+ rhs_addr = integer_zero_node;
+   }
   else
rhs_addr = gimplify_addr (gsi, rhs);
 
   // Choose the appropriate memory transfer function.
-  if (load_p && store_p)
-   {
- // ??? Figure out if there's any possible overlap between
- // the LHS and the RHS and if not, use MEMCPY.
- copy_fn = builtin_decl_explicit (BUILT_IN_TM_MEMMOVE);
-   }
+  if (store_p
+ && TREE_CODE (rhs) == CONSTRUCTOR
+ && CONSTRUCTOR_NELTS (rhs) == 0)
+   copy_fn = builtin_decl_explicit (BUILT_IN_TM_MEMSET);
+  else if (load_p && store_p)
+   // ??? Figure out if there's any possible overlap between
+   // the LHS and the RHS and if not, use MEMCPY.
+   copy_fn = builtin_decl_explicit (BUILT_IN_TM_MEMMOVE);
   else if (load_p)
-   {
- // Note that the store is non-transactional and cannot overlap.
- copy_fn = builtin_decl_explicit (BUILT_IN_TM_MEMCPY_RTWN);
-   }
+   // Note that the store is non-transactional and cannot overlap.
+   copy_fn = builtin_decl_explicit (B

[gcc r15-5055] c: minor fixes related to arrays of unspecified size

2024-11-09 Thread Martin Uecker via Gcc-cvs
https://gcc.gnu.org/g:114abf075c1e28358173756042049c9992ae6572

commit r15-5055-g114abf075c1e28358173756042049c9992ae6572
Author: Martin Uecker 
Date:   Fri Nov 1 10:15:44 2024 +0100

c: minor fixes related to arrays of unspecified size

The patch for PR117145 and PR117245 also fixed PR100420 and PR116284 which
are bugs related to arrays of unspecified size.  Those are now represented
as variable size arrays with size (0, 0).  There are still some loose ends,
which are resolved here by

1. adding a testcase for PR116284,
2. moving code related to creation and detection of arrays of unspecified
sizes in their own functions,
3. preferring a specified size over an unspecified size when forming
a composite type as required by C99 (PR118391)
4. removing useless code in comptypes_internal and composite_type_internal.

PR c/116284
PR c/117391

gcc/c/ChangeLog:
* c-tree.h (c_type_unspecified_p): New inline function.
* c-typeck.cc (c_build_array_type_unspecified): New function.
(comptypes_interal): Remove useless code.
(composite_type_internal): Update.
* c-decl.cc (grokdeclarator): Revise.

gcc/testsuite/ChangeLog:
* gcc.dg/pr116284.c: New test.
* gcc.dg/pr117391.c: New test.

Diff:
---
 gcc/c/c-decl.cc |  9 -
 gcc/c/c-tree.h  | 16 ---
 gcc/c/c-typeck.cc   | 43 ++---
 gcc/testsuite/gcc.dg/pr116284.c | 14 ++
 gcc/testsuite/gcc.dg/pr117391.c | 14 ++
 5 files changed, 72 insertions(+), 24 deletions(-)

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 42d329e4fd52..ac47ef24a3de 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -7501,10 +7501,6 @@ grokdeclarator (const struct c_declarator *declarator,
/* C99 6.7.5.2p4 */
if (decl_context == TYPENAME)
  warning (0, "%<[*]%> not in a declaration");
-   /* Array of unspecified size.  */
-   tree upper = build2 (COMPOUND_EXPR, TREE_TYPE (size_zero_node),
-integer_zero_node, size_zero_node);
-   itype = build_index_type (upper);
size_varies = true;
  }
 
@@ -7540,7 +7536,10 @@ grokdeclarator (const struct c_declarator *declarator,
if (!ADDR_SPACE_GENERIC_P (as) && as != TYPE_ADDR_SPACE (type))
  type = c_build_qualified_type (type,
 ENCODE_QUAL_ADDR_SPACE (as));
-   type = c_build_array_type (type, itype);
+   if (array_parm_vla_unspec_p)
+ type = c_build_array_type_unspecified (type);
+   else
+ type = c_build_array_type (type, itype);
  }
 
if (type != error_mark_node)
diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h
index c8e9731bfc42..f6bcbabb9d5b 100644
--- a/gcc/c/c-tree.h
+++ b/gcc/c/c-tree.h
@@ -776,12 +776,22 @@ extern struct c_switch *c_switch_stack;
 extern bool null_pointer_constant_p (const_tree);
 
 
-inline
-bool c_type_variably_modified_p (tree t)
+inline bool
+c_type_variably_modified_p (tree t)
 {
   return error_mark_node != t && C_TYPE_VARIABLY_MODIFIED (t);
 }
 
+inline bool
+c_type_unspecified_p (tree t)
+{
+  return error_mark_node != t
+&& C_TYPE_VARIABLE_SIZE (t) && TREE_CODE (t) == ARRAY_TYPE
+&& TYPE_DOMAIN (t) && TYPE_MAX_VALUE (TYPE_DOMAIN (t))
+&& TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == COMPOUND_EXPR
+&& integer_zerop (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0))
+&& integer_zerop (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 1));
+}
 
 extern bool char_type_p (tree);
 extern tree c_objc_common_truthvalue_conversion (location_t, tree,
@@ -883,10 +893,10 @@ extern tree c_reconstruct_complex_type (tree, tree);
 extern tree c_build_type_attribute_variant (tree ntype, tree attrs);
 extern tree c_build_pointer_type (tree type);
 extern tree c_build_array_type (tree type, tree domain);
+extern tree c_build_array_type_unspecified (tree type);
 extern tree c_build_function_type (tree type, tree args, bool no = false);
 extern tree c_build_pointer_type_for_mode (tree type, machine_mode mode, bool 
m);
 
-
 /* Set to 0 at beginning of a function definition, set to 1 if
a return statement that specifies a return value is seen.  */
 
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 6673cbf72947..201d75d2e9c9 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -358,7 +358,7 @@ qualify_type (tree type, tree like)
 }
 
 
-/* Check consistency of type TYP.E  For derived types, we test that
+/* Check consistency of type TYPE.  For derived types, we test that
C_TYPE_VARIABLE_SIZE and C_TYPE_VARIABLY_MODIFIED are consistent with
the requirements of the base type. 

[gcc r15-5067] c++: Fix tree_contains_struct for TRAIT_EXPR

2024-11-09 Thread Lewis Hyatt via Gcc-cvs
https://gcc.gnu.org/g:d7ef7d1258d8ef715be29dea0788a3e410c1d279

commit r15-5067-gd7ef7d1258d8ef715be29dea0788a3e410c1d279
Author: Lewis Hyatt 
Date:   Sat Nov 2 21:59:24 2024 -0400

c++: Fix tree_contains_struct for TRAIT_EXPR

CODE_CONTAINS_STRUCT () currently reports that a TRAIT_EXPR contains a
TS_EXP struct, but it does not actually start with a TS_EXP as an initial
sequence. In modules.cc, when we stream out a tree, we explicitly check for 
the
TS_EXP case and call note_location(t->exp.locus) if so. Currently, this
actually queries the tree_common::chain field of a tree_trait_expr, which
seems not to be used, returning 0, which is interpreted as UNKNOWN_LOCATION
and does no harm.

If location_t will change to be 64 bytes, as is under discussion, then on
32-bit platforms (well those, such as sparc, on which uint64_t has higher
alignment requirement than a pointer), reading t->exp.locus will end up
reading a different field (tree_trait_expr::type1) due to padding
offsets. That field is not generally 0, and the resulting bogus location_t
is sufficiently problematic to cause an ICE in the line_map code. Pretty
much any modules testcase displays the issue, such as partial-2_a.C.

Resolve by initializing tree_contains_struct with the correct value for
TRAIT_EXPR, namely TS_TYPED.

gcc/cp/ChangeLog:

* cp-objcp-common.cc (cp_common_init_ts): Change TRAIT_EXPR from
TS_EXP to TS_TYPED.

Diff:
---
 gcc/cp/cp-objcp-common.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc
index 7a0636f16532..1e43db31db8c 100644
--- a/gcc/cp/cp-objcp-common.cc
+++ b/gcc/cp/cp-objcp-common.cc
@@ -617,6 +617,7 @@ cp_common_init_ts (void)
   MARK_TS_TYPED (PTRMEM_CST);
   MARK_TS_TYPED (LAMBDA_EXPR);
   MARK_TS_TYPED (TYPE_ARGUMENT_PACK);
+  MARK_TS_TYPED (TRAIT_EXPR);
 
   /* Random new trees.  */
   MARK_TS_COMMON (BASELINK);
@@ -684,7 +685,6 @@ cp_common_init_ts (void)
   MARK_TS_EXP (TAG_DEFN);
   MARK_TS_EXP (TEMPLATE_ID_EXPR);
   MARK_TS_EXP (THROW_EXPR);
-  MARK_TS_EXP (TRAIT_EXPR);
   MARK_TS_EXP (TYPEID_EXPR);
   MARK_TS_EXP (TYPE_EXPR);
   MARK_TS_EXP (UNARY_PLUS_EXPR);


[gcc r15-5062] VN: Canonicalize compares before calling vn_nary_op_lookup_pieces

2024-11-09 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:af1277b4d0d274b8c8f6edffcee32b7f39f2df64

commit r15-5062-gaf1277b4d0d274b8c8f6edffcee32b7f39f2df64
Author: Andrew Pinski 
Date:   Thu Nov 7 09:40:15 2024 -0800

VN: Canonicalize compares before calling vn_nary_op_lookup_pieces

This is the followup as mentioned in
https://gcc.gnu.org/pipermail/gcc-patches/2024-November/667987.html .
We need to canonicalize the compares using tree_swap_operands_p instead
of checking CONSTANT_CLASS_P.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

* tree-ssa-sccvn.cc (visit_phi): Swap the operands
before calling vn_nary_op_lookup_pieces if
tree_swap_operands_p returns true.
(insert_predicates_for_cond): Use tree_swap_operands_p
instead of checking for CONSTANT_CLASS_P.
(process_bb): Swap the comparison and operands
if tree_swap_operands_p returns true.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/tree-ssa-sccvn.cc | 23 +--
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 1967bbdca84d..16299662b957 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -6067,6 +6067,9 @@ visit_phi (gimple *phi, bool *inserted, bool 
backedges_varying_p)
tree ops[2];
ops[0] = def;
ops[1] = sameval;
+   /* Canonicalize the operands order for eq below. */
+   if (tree_swap_operands_p (ops[0], ops[1]))
+ std::swap (ops[0], ops[1]);
tree val = vn_nary_op_lookup_pieces (2, EQ_EXPR,
 boolean_type_node,
 ops, &vnresult);
@@ -7905,8 +7908,9 @@ insert_predicates_for_cond (tree_code code, tree lhs, 
tree rhs,
   if (!true_e && !false_e)
 return;
 
-  /* Canonicalize the comparison so the rhs are constants.  */
-  if (CONSTANT_CLASS_P (lhs))
+  /* Canonicalize the comparison if needed, putting
+ the constant in the rhs.  */
+  if (tree_swap_operands_p (lhs, rhs))
 {
   std::swap (lhs, rhs);
   code = swap_tree_comparison (code);
@@ -8145,7 +8149,15 @@ process_bb (rpo_elim &avail, basic_block bb,
  {
tree lhs = vn_valueize (gimple_cond_lhs (last));
tree rhs = vn_valueize (gimple_cond_rhs (last));
-   tree val = gimple_simplify (gimple_cond_code (last),
+   tree_code cmpcode = gimple_cond_code (last);
+   /* Canonicalize the comparison if needed, putting
+  the constant in the rhs.  */
+   if (tree_swap_operands_p (lhs, rhs))
+ {
+   std::swap (lhs, rhs);
+   cmpcode = swap_tree_comparison (cmpcode);
+  }
+   tree val = gimple_simplify (cmpcode,
boolean_type_node, lhs, rhs,
NULL, vn_valueize);
/* If the condition didn't simplfy see if we have recorded
@@ -8156,7 +8168,7 @@ process_bb (rpo_elim &avail, basic_block bb,
tree ops[2];
ops[0] = lhs;
ops[1] = rhs;
-   val = vn_nary_op_lookup_pieces (2, gimple_cond_code (last),
+   val = vn_nary_op_lookup_pieces (2, cmpcode,
boolean_type_node, ops,
&vnresult);
/* Got back a ssa name, then try looking up `val != 0`
@@ -8193,14 +8205,13 @@ process_bb (rpo_elim &avail, basic_block bb,
   important as early cleanup.  */
edge true_e, false_e;
extract_true_false_edges_from_block (bb, &true_e, &false_e);
-   enum tree_code code = gimple_cond_code (last);
if ((do_region && bitmap_bit_p (exit_bbs, true_e->dest->index))
|| !can_track_predicate_on_edge (true_e))
  true_e = NULL;
if ((do_region && bitmap_bit_p (exit_bbs, false_e->dest->index))
|| !can_track_predicate_on_edge (false_e))
  false_e = NULL;
-   insert_predicates_for_cond (code, lhs, rhs, true_e, false_e);
+   insert_predicates_for_cond (cmpcode, lhs, rhs, true_e, false_e);
  }
break;
  }


[gcc r15-5063] VN: Don't recurse on for the same value of `a | b` [PR117496]

2024-11-09 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:6e84a41622f56ca360d995e6092ded3b5a02ba40

commit r15-5063-g6e84a41622f56ca360d995e6092ded3b5a02ba40
Author: Andrew Pinski 
Date:   Fri Nov 8 13:39:05 2024 -0800

VN: Don't recurse on for the same value of `a | b` [PR117496]

After adding vn_valueize to the handle the `a | b ==/!= 0` case
of insert_predicates_for_cond, it would go into an infinite loop
as the Value number for either a or b could be the same as what it
is for the whole expression. This avoids that recursion so there is
no infinite loop here.

Bootstrapped and tested on x86_64-linux.

PR tree-optimization/117496

gcc/ChangeLog:

* tree-ssa-sccvn.cc (insert_predicates_for_cond): If the
valueization for the new lhs is the same as the old one,
don't recurse.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr117496-1.c: New test.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr117496-1.c | 25 +
 gcc/tree-ssa-sccvn.cc | 11 +--
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr117496-1.c 
b/gcc/testsuite/gcc.dg/torture/pr117496-1.c
new file mode 100644
index ..f35d13dfa85d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr117496-1.c
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+
+
+/* PR tree-optimization/117496 */
+/* This would go into an infinite loop into VN while recording
+   the predicates for the `tracks == 0 && wm == 0` GIMPLE_COND.
+   As wm_N and tracks_N would valueize back to `tracks | wm`.  */
+
+int main_argc, gargs_preemp, gargs_nopreemp;
+static void gargs();
+void main_argv() {
+  int tracks = 0;
+  gargs(main_argc, main_argv, &tracks);
+}
+void gargs(int, char *, int *tracksp) {
+  int tracks = *tracksp, wm;
+  for (;;) {
+if (tracks == 0)
+  wm |= 4;
+if (gargs_nopreemp)
+  gargs_preemp = 0;
+if (tracks == 0 && wm == 0)
+  tracks++;
+  }
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 16299662b957..e93acb44200e 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -7900,6 +7900,7 @@ insert_related_predicates_on_edge (enum tree_code code, 
tree *ops, edge pred_e)
 
 /* Insert on the TRUE_E true and FALSE_E false predicates
derived from LHS CODE RHS.  */
+
 static void
 insert_predicates_for_cond (tree_code code, tree lhs, tree rhs,
edge true_e, edge false_e)
@@ -7977,10 +7978,16 @@ insert_predicates_for_cond (tree_code code, tree lhs, 
tree rhs,
  tree nlhs;
 
  nlhs = vn_valueize (gimple_assign_rhs1 (def_stmt));
- insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr);
+ /* A valueization of the `a` might return the old lhs
+which is already handled above. */
+ if (nlhs != lhs)
+   insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr);
 
+ /* A valueization of the `b` might return the old lhs
+which is already handled above. */
  nlhs = vn_valueize (gimple_assign_rhs2 (def_stmt));
- insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr);
+ if (nlhs != lhs)
+   insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr);
}
 }
 }


[gcc r15-5064] fold: Remove (rrotate (rrotate A CST) CST) folding [PR117492]

2024-11-09 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:ed88bc2344321ee21e92afdd83b50699c4e4df79

commit r15-5064-ged88bc2344321ee21e92afdd83b50699c4e4df79
Author: Andrew Pinski 
Date:   Fri Nov 8 14:46:18 2024 -0800

fold: Remove (rrotate (rrotate A CST) CST) folding [PR117492]

This removes an (broken) simplification from fold which is already handled 
in match.
The reason why it was broken is because of the use of wi::to_wide on the 
RHS of the
rotate which could be 2 different types even though the LHS was the same 
type.
Since it is already handled in match (by the patterns for
`Turn (a OP c1) OP c2 into a OP (c1+c2).`). It can be removed without 
losing any optimizations.

Bootstrapped and tested on x86_64-linux-gnu.

PR middle-end/117492

gcc/ChangeLog:

* fold-const.cc (fold_binary_loc): Remove `Two consecutive rotates 
adding up
to the some integer` simplifcation.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr117492-1.c: New test.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/fold-const.cc | 10 --
 gcc/testsuite/gcc.dg/torture/pr117492-1.c | 16 
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 0e374294c014..1e8ae1ab493b 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -12530,16 +12530,6 @@ fold_binary_loc (location_t loc, enum tree_code code, 
tree type,
   arg01, arg1));
}
 
-  /* Two consecutive rotates adding up to the some integer
-multiple of the precision of the type can be ignored.  */
-  if (code == RROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST
- && TREE_CODE (arg0) == RROTATE_EXPR
- && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
- && wi::umod_trunc (wi::to_wide (arg1)
-+ wi::to_wide (TREE_OPERAND (arg0, 1)),
-prec) == 0)
-   return fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
-
   return NULL_TREE;
 
 case MIN_EXPR:
diff --git a/gcc/testsuite/gcc.dg/torture/pr117492-1.c 
b/gcc/testsuite/gcc.dg/torture/pr117492-1.c
new file mode 100644
index ..543d8b7e709c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr117492-1.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* PR middle-end/117492 */
+
+/* This code would ICE in fold due to code which was using wi::to_wide with 
different types
+   and adding them. */
+
+typedef unsigned u;
+
+u
+foo(u x)
+{
+  return
+__builtin_stdc_rotate_left((unsigned)
+  __builtin_stdc_rotate_right(x, 0x10001ull),
+  1);
+}


[gcc r15-5065] Darwin: Support '-ObjC{, ++}' as shorthand for -xobjective-c{, ++} [PR117478].

2024-11-09 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:7729df2f828a8a4f217a76e7ae763bdac95dee71

commit r15-5065-g7729df2f828a8a4f217a76e7ae763bdac95dee71
Author: Iain Sandoe 
Date:   Thu Nov 7 17:17:46 2024 +

Darwin: Support '-ObjC{,++}' as shorthand for -xobjective-c{,++} [PR117478].

This improves compatibility with clang, and is used by some projects.

PR target/117478

gcc/ChangeLog:

* config/darwin-driver.cc (darwin_driver_init): Handle ObjC/ObjC++
* config/darwin.opt: Add ObjC/ObjC++ as driver-only options.

Signed-off-by: Iain Sandoe 

Diff:
---
 gcc/config/darwin-driver.cc | 10 ++
 gcc/config/darwin.opt   |  6 ++
 2 files changed, 16 insertions(+)

diff --git a/gcc/config/darwin-driver.cc b/gcc/config/darwin-driver.cc
index 2aa0b0cd9e4f..f2aa6be6eea1 100644
--- a/gcc/config/darwin-driver.cc
+++ b/gcc/config/darwin-driver.cc
@@ -351,6 +351,16 @@ darwin_driver_init (unsigned int *decoded_options_count,
noexport_p = false;
  break;
 
+   case OPT_ObjC:
+ (*decoded_options)[i].opt_index = OPT_x;
+ (*decoded_options)[i].arg = "objective-c";
+ break;
+
+   case OPT_ObjC__:
+ (*decoded_options)[i].opt_index = OPT_x;
+ (*decoded_options)[i].arg = "objective-c++";
+ break;
+
default:
  break;
}
diff --git a/gcc/config/darwin.opt b/gcc/config/darwin.opt
index 114048045b90..b105828551c5 100644
--- a/gcc/config/darwin.opt
+++ b/gcc/config/darwin.opt
@@ -261,6 +261,12 @@ noseglinkedit
 Driver RejectNegative Negative(seglinkedit)
 (Obsolete) This is the default.
 
+ObjC
+Driver RejectNegative
+
+ObjC++
+Driver RejectNegative
+
 object
 Driver RejectNegative


[gcc r15-5057] arm: Fix ICE on arm_mve.h pragma without MVE types [PR117408]

2024-11-09 Thread Torbjorn Svensson via Gcc-cvs
https://gcc.gnu.org/g:8b04f60f88079c41b5cb1bf3b7c798703cceea18

commit r15-5057-g8b04f60f88079c41b5cb1bf3b7c798703cceea18
Author: Torbjörn SVENSSON 
Date:   Fri Nov 1 17:47:48 2024 +0100

arm: Fix ICE on arm_mve.h pragma without MVE types [PR117408]

Starting with r14-435-g00d97bf3b5a, doing `#pragma arm "arm_mve.h"
false` or `#pragma arm "arm_mve.h" true` without first doing
`#pragma arm "arm_mve_types.h"` causes GCC to ICE.

gcc/ChangeLog:

PR target/117408
* config/arm/arm-mve-builtins.cc(handle_arm_mve_h): Detect if MVE
types is missing and if so, return error.

gcc/testsuite/ChangeLog:

PR target/117408
* gcc.target/arm/mve/pr117408-1.c: New test.
* gcc.target/arm/mve/pr117408-2.c: Likewise.

Signed-off-by: Torbjörn SVENSSON 

Diff:
---
 gcc/config/arm/arm-mve-builtins.cc| 7 +++
 gcc/testsuite/gcc.target/arm/mve/pr117408-1.c | 7 +++
 gcc/testsuite/gcc.target/arm/mve/pr117408-2.c | 7 +++
 3 files changed, 21 insertions(+)

diff --git a/gcc/config/arm/arm-mve-builtins.cc 
b/gcc/config/arm/arm-mve-builtins.cc
index af1908691b6f..ed3d6000641e 100644
--- a/gcc/config/arm/arm-mve-builtins.cc
+++ b/gcc/config/arm/arm-mve-builtins.cc
@@ -535,6 +535,13 @@ handle_arm_mve_h (bool preserve_user_namespace)
   return;
 }
 
+  if (!handle_arm_mve_types_p)
+{
+  error ("this definition requires MVE types, please include %qs",
+"arm_mve_types.h");
+  return;
+}
+
   /* Define MVE functions.  */
   function_table = new hash_table (1023);
   function_builder builder;
diff --git a/gcc/testsuite/gcc.target/arm/mve/pr117408-1.c 
b/gcc/testsuite/gcc.target/arm/mve/pr117408-1.c
new file mode 100644
index ..25eaf67e2979
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/mve/pr117408-1.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target arm_v8_1m_mve_ok } */
+/* { dg-add-options arm_v8_1m_mve } */
+
+/* It doesn't really matter if this produces errors missing types,
+  but it mustn't trigger an ICE.  */
+#pragma GCC arm "arm_mve.h" false /* { dg-error "this definition requires MVE 
types, please include 'arm_mve_types.h'" } */
diff --git a/gcc/testsuite/gcc.target/arm/mve/pr117408-2.c 
b/gcc/testsuite/gcc.target/arm/mve/pr117408-2.c
new file mode 100644
index ..c3a0af25f778
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/mve/pr117408-2.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target arm_v8_1m_mve_ok } */
+/* { dg-add-options arm_v8_1m_mve } */
+
+/* It doesn't really matter if this produces errors missing types,
+  but it mustn't trigger an ICE.  */
+#pragma GCC arm "arm_mve.h" true /* { dg-error "this definition requires MVE 
types, please include 'arm_mve_types.h'" } */


[gcc r14-10912] arm: Fix ICE on arm_mve.h pragma without MVE types [PR117408]

2024-11-09 Thread Torbjorn Svensson via Gcc-cvs
https://gcc.gnu.org/g:e277e1082a86efa7e8649e2664c109eacf8dccb9

commit r14-10912-ge277e1082a86efa7e8649e2664c109eacf8dccb9
Author: Torbjörn SVENSSON 
Date:   Fri Nov 1 17:47:48 2024 +0100

arm: Fix ICE on arm_mve.h pragma without MVE types [PR117408]

Starting with r14-435-g00d97bf3b5a, doing `#pragma arm "arm_mve.h"
false` or `#pragma arm "arm_mve.h" true` without first doing
`#pragma arm "arm_mve_types.h"` causes GCC to ICE.

gcc/ChangeLog:

PR target/117408
* config/arm/arm-mve-builtins.cc(handle_arm_mve_h): Detect if MVE
types is missing and if so, return error.

gcc/testsuite/ChangeLog:

PR target/117408
* gcc.target/arm/mve/pr117408-1.c: New test.
* gcc.target/arm/mve/pr117408-2.c: Likewise.

Signed-off-by: Torbjörn SVENSSON 
(cherry picked from commit 8b04f60f88079c41b5cb1bf3b7c798703cceea18)

Diff:
---
 gcc/config/arm/arm-mve-builtins.cc| 7 +++
 gcc/testsuite/gcc.target/arm/mve/pr117408-1.c | 7 +++
 gcc/testsuite/gcc.target/arm/mve/pr117408-2.c | 7 +++
 3 files changed, 21 insertions(+)

diff --git a/gcc/config/arm/arm-mve-builtins.cc 
b/gcc/config/arm/arm-mve-builtins.cc
index 7e8217666fee..e1826ae40527 100644
--- a/gcc/config/arm/arm-mve-builtins.cc
+++ b/gcc/config/arm/arm-mve-builtins.cc
@@ -492,6 +492,13 @@ handle_arm_mve_h (bool preserve_user_namespace)
   return;
 }
 
+  if (!handle_arm_mve_types_p)
+{
+  error ("this definition requires MVE types, please include %qs",
+"arm_mve_types.h");
+  return;
+}
+
   /* Define MVE functions.  */
   function_table = new hash_table (1023);
   function_builder builder;
diff --git a/gcc/testsuite/gcc.target/arm/mve/pr117408-1.c 
b/gcc/testsuite/gcc.target/arm/mve/pr117408-1.c
new file mode 100644
index ..25eaf67e2979
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/mve/pr117408-1.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target arm_v8_1m_mve_ok } */
+/* { dg-add-options arm_v8_1m_mve } */
+
+/* It doesn't really matter if this produces errors missing types,
+  but it mustn't trigger an ICE.  */
+#pragma GCC arm "arm_mve.h" false /* { dg-error "this definition requires MVE 
types, please include 'arm_mve_types.h'" } */
diff --git a/gcc/testsuite/gcc.target/arm/mve/pr117408-2.c 
b/gcc/testsuite/gcc.target/arm/mve/pr117408-2.c
new file mode 100644
index ..c3a0af25f778
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/mve/pr117408-2.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target arm_v8_1m_mve_ok } */
+/* { dg-add-options arm_v8_1m_mve } */
+
+/* It doesn't really matter if this produces errors missing types,
+  but it mustn't trigger an ICE.  */
+#pragma GCC arm "arm_mve.h" true /* { dg-error "this definition requires MVE 
types, please include 'arm_mve_types.h'" } */


[gcc r15-5059] contrib: Add 2 further ignored commits

2024-11-09 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:7ffda969ed49cedfdf9e1a16d1059cb7f9443605

commit r15-5059-g7ffda969ed49cedfdf9e1a16d1059cb7f9443605
Author: Jakub Jelinek 
Date:   Sat Nov 9 16:57:26 2024 +0100

contrib: Add 2 further ignored commits

r15-4998 and r15-5004 had wrong commit message, add those to
ignored commits.  ChangeLog will need to be added manually.

2024-11-09  Jakub Jelinek  

* gcc-changelog/git_update_version.py (ignored_commits): Add 2
further commits.

Diff:
---
 contrib/gcc-changelog/git_update_version.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/contrib/gcc-changelog/git_update_version.py 
b/contrib/gcc-changelog/git_update_version.py
index ec06fc965f8a..005dcca769a7 100755
--- a/contrib/gcc-changelog/git_update_version.py
+++ b/contrib/gcc-changelog/git_update_version.py
@@ -42,7 +42,9 @@ ignored_commits = {
 '040e5b0edbca861196d9e2ea2af5e805769c8d5d',
 '8057f9aa1f7e70490064de796d7a8d42d446caf8',
 '109f1b28fc94c93096506e3df0c25e331cef19d0',
-'39f81924d88e3cc197fc3df74204c9b5e01e12f7'}
+'39f81924d88e3cc197fc3df74204c9b5e01e12f7',
+'8e6a25b01becf449d54154b7e83de5f4955cba37',
+'13cf22eb557eb5e3d796822247d8d4957bdb25da'}
 
 FORMAT = '%(asctime)s:%(levelname)s:%(name)s:%(message)s'
 logging.basicConfig(level=logging.INFO, format=FORMAT,


[gcc r15-5058] m2: Fix up dependencies some more

2024-11-09 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:44682fbead3bba7345e0a575a8a680d10e75ae48

commit r15-5058-g44682fbead3bba7345e0a575a8a680d10e75ae48
Author: Jakub Jelinek 
Date:   Sat Nov 9 16:45:44 2024 +0100

m2: Fix up dependencies some more

Every now and then my x86_64-linux bootstrap fails due to missing
dependencies somewhere in m2, usually during stage3.  I'm using
make -j32 and run 2 bootstraps concurrently (x86_64-linux and i686-linux)
on the same box.

Last night the same happened to me again,
with the first error
In file included from ./tm.h:29,
 from ../../gcc/backend.h:28,
 from ../../gcc/m2/gm2-gcc/gcc-consolidation.h:27,
 from m2/gm2-compiler-boot/M2AsmUtil.c:26:
../../gcc/config/i386/i386.h:2484:10: fatal error: insn-attr-common.h: No 
such file or directory
 2484 | #include "insn-attr-common.h"
  |  ^~~~
compilation terminated.
make[3]: *** [../../gcc/m2/Make-lang.in:1576: 
m2/gm2-compiler-boot/M2AsmUtil.o] Error 1
make[3]: *** Waiting for unfinished jobs

Now, gcc/Makefile.in has a general rule:
 # In order for parallel make to really start compiling the expensive
 # objects from $(OBJS) as early as possible, build all their
 # prerequisites strictly before all objects.
 $(ALL_HOST_OBJS) : | $(generated_files)
which ensures that everything that might depend on the generated files
waits for those to be generated.
The above error clearly shows that such waiting didn't happen for
m2/gm2-compiler-boot/M2AsmUtil.o and some others.
ALL_HOST_OBJS includes $(ALL_HOST_FRONTEND_OBJS),
where the latter is
ALL_HOST_FRONTEND_OBJS = $(foreach v,$(CONFIG_LANGUAGES),$($(v)_OBJS))
m2_OBJS already includes various *.o files, for all those we wait until
the generated files are generated.  Though, seems
cc1gm2 depends on m2/stage1/cc1gm2 (which is just copied there),
and that depends on m2/gm2-compiler-boot/m2flex.o,
$(GM2_C_OBJS) and m2/gm2-gcc/rtegraph.o already included in m2_OBJS,
but also on
$(GM2_LIBS_BOOT) $(MC_LIBS)
where
MC_LIBS=m2/mc-boot-ch/Glibc.o m2/mc-boot-ch/Gmcrts.o
GM2_LIBS_BOOT = m2/gm2-compiler-boot/gm2.a \
m2/gm2-libs-boot/libgm2.a \
$(GM2-BOOT-O)
GM2-BOOT-O isn't defined, and the 2 libraries depend on
$(BUILD-LIBS-BOOT) $(BUILD-COMPILER-BOOT)

So, the following patch adds those to m2_OBJS.

I'm not sure if something further is needed, like some objects
used to build the helper programs, mc and whatever else is needed,
I guess it depends on if they use or can use say tm.h or similar
headers which depend on the generated headers.

2024-11-09  Jakub Jelinek  

gcc/m2/
* Make-lang.in (m2_OBJS): Add $(BUILD-LIBS-BOOT),
$(BUILD-COMPILER-BOOT) and $(MC_LIBS).

Diff:
---
 gcc/m2/Make-lang.in | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
index 480c4fb28a7e..43d8119cacd3 100644
--- a/gcc/m2/Make-lang.in
+++ b/gcc/m2/Make-lang.in
@@ -580,7 +580,8 @@ GM2_LIBS_BOOT = m2/gm2-compiler-boot/gm2.a \
 $(GM2-BOOT-O)
 
 m2_OBJS = $(GM2_C_OBJS) m2/gm2-gcc/rtegraph.o \
-   m2/gm2-compiler-boot/m2flex.o
+   m2/gm2-compiler-boot/m2flex.o \
+   $(BUILD-LIBS-BOOT) $(BUILD-COMPILER-BOOT) $(MC_LIBS)
 
 cc1gm2$(exeext): m2/stage1/cc1gm2$(exeext) $(m2.prev)
cp -p $< $@


[gcc r15-5061] ChangeLog: Manually add entries for r15-4998 and r15-5004

2024-11-09 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:0284886b8eb6f64676a56c420325ab0a9f911e70

commit r15-5061-g0284886b8eb6f64676a56c420325ab0a9f911e70
Author: Jakub Jelinek 
Date:   Sat Nov 9 17:11:34 2024 +0100

ChangeLog: Manually add entries for r15-4998 and r15-5004

These commits used *.c rather than *.cc suffix and miracuously got through
the pre-commit hook but broke ChangeLog generation.

Diff:
---
 gcc/ChangeLog | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 23ee454e3f24..7fae8aacdf98 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -177,6 +177,11 @@
laxer, adapted and moved from...
(pass_tree_ifcombine::execute): ... here.
 
+2024-11-07  Alexandre Oliva  
+
+   * tree-ssa-ifcombine.cc (ifcombine_replace_cond): Support
+   TRUTH_ANDIF cond exprs.
+
 2024-11-07  Alexandre Oliva  
 
* tree-ssa-ifcombine.cc (recognize_if_then_else): Support
@@ -215,6 +220,11 @@
* tree-ssa-ifcombine.cc (ifcombine_ifandif): Drop redundant
result_inv parm.  Adjust all callers.
 
+2024-11-07  Alexandre Oliva  
+
+   * tree-ssa-ifcombine.cc (bb_no_side_effects_p): Allow vuses,
+   but not vdefs.
+
 2024-11-07  xuli  
 
* match.pd: Add the form1 of signed imm .SAT_ADD matching.