commit f1d4b4f918a9c5b25a82b7bfccb08aa5e647f41c
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Jul 27 11:10:33 2023

    Bump BASE-VER
    
    2023-07-27  Jakub Jelinek  <jakub@redhat.com>
    
            * BASE-VER: Set to 13.2.1.

diff --git a/gcc/BASE-VER b/gcc/BASE-VER
index 67aee23940e..947f4e99630 100644
--- a/gcc/BASE-VER
+++ b/gcc/BASE-VER
@@ -1 +1 @@
-13.2.0
+13.2.1

commit 7004272e9b16e801eb856a991930d81e9c501532
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Jul 24 08:40:19 2023

    tree-optimization/110766 - missing PHI location check
    
    The following adds a missing PHI location check before querying
    the loop latch PHI arg from it.
    
            PR tree-optimization/110766
            * tree-scalar-evolution.cc
            (analyze_and_compute_bitwise_induction_effect): Check the PHI
            is defined in the loop header.
    
            * gcc.dg/torture/pr110766.c: New testcase.
    
    (cherry picked from commit fb132cdfb204bc12851eb1d5852eef6f03c13af3)

diff --git a/gcc/testsuite/gcc.dg/torture/pr110766.c b/gcc/testsuite/gcc.dg/torture/pr110766.c
new file mode 100644
index 00000000000..97dcacf1e00
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr110766.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+
+int a, b, c, e;
+short d, f;
+int g(int h) { return h > a ? h : h << a; }
+int main() {
+  while (e) {
+    b = 0;
+    for (; b < 3; b++)
+      if (c) {
+        e = g(1);
+        f = e | d;
+      }
+    d = 0;
+  }
+  return 0;
+}
diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc
index 25e962530cd..ffef0edb60a 100644
--- a/gcc/tree-scalar-evolution.cc
+++ b/gcc/tree-scalar-evolution.cc
@@ -3523,6 +3523,7 @@ analyze_and_compute_bitwise_induction_effect (class loop* loop,
   if (!gimple_bitwise_induction_p (phidef, &match_op[0], NULL)
       || TREE_CODE (match_op[2]) != SSA_NAME
       || !(header_phi = dyn_cast <gphi *> (SSA_NAME_DEF_STMT (match_op[2])))
+      || gimple_bb (header_phi) != loop->header
       || gimple_phi_num_args (header_phi) != 2)
     return NULL_TREE;
 

commit 064a4ec9d7107c8278a759cb61dc161548c846ee
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Jul 26 09:28:10 2023

    tree-optimization/110799 - fix bug in code hoisting
    
    Code hoisting part of GIMPLE PRE failed to adjust the TBAA behavior
    of common loads in the case the alias set of the ref was the same
    but the base alias set was not.  It also failed to adjust the
    base behavior, assuming it would match.  The following plugs this
    hole.
    
            PR tree-optimization/110799
            * tree-ssa-pre.cc (compute_avail): More thoroughly match
            up TBAA behavior of redundant loads.
    
            * gcc.dg/torture/pr110799.c: New testcase.
    
    (cherry picked from commit 565e0e80660dac24e5193873ca07542b99cd8bc3)

diff --git a/gcc/testsuite/gcc.dg/torture/pr110799.c b/gcc/testsuite/gcc.dg/torture/pr110799.c
new file mode 100644
index 00000000000..53f06f079e1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr110799.c
@@ -0,0 +1,46 @@
+/* { dg-do run { target { { *-*-linux* *-*-gnu* *-*-uclinux* } && mmap } } } */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+
+struct S {
+    int a;
+};
+struct M {
+    int a, b;
+};
+
+int __attribute__((noipa))
+f(struct S *p, int c, int d)
+{
+  int r;
+  if (c)
+    {
+      if (d)
+	r = p->a;
+      else
+	r = ((struct M*)p)->a;
+    }
+  else
+    r = ((struct M*)p)->b;
+  return r;
+}
+
+int main ()
+{
+  long pgsz = sysconf(_SC_PAGESIZE);
+  if (pgsz < sizeof (struct M))
+    return 0;
+  char *p = mmap ((void *) 0, 2 * pgsz, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS,
+		  -1, 0);
+  if (p == MAP_FAILED)
+    return 0;
+  if (mprotect (p, pgsz, PROT_READ | PROT_WRITE))
+    return 0;
+  struct S *q = (struct S *)(p + pgsz) - 1;
+  q->a = 42;
+  if (f (q, 1, 1) != 42)
+    abort ();
+  return 0;
+}
diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc
index 7bc96ba95fa..dfcc9ec4711 100644
--- a/gcc/tree-ssa-pre.cc
+++ b/gcc/tree-ssa-pre.cc
@@ -4181,8 +4181,10 @@ compute_avail (function *fun)
 		      /* TBAA behavior is an obvious part so make sure
 		         that the hashtable one covers this as well
 			 by adjusting the ref alias set and its base.  */
-		      if (ref->set == set
-			  || alias_set_subset_of (set, ref->set))
+		      if ((ref->set == set
+			   || alias_set_subset_of (set, ref->set))
+			  && (ref->base_set == base_set
+			      || alias_set_subset_of (base_set, ref->base_set)))
 			;
 		      else if (ref1->opcode != ref2->opcode
 			       || (ref1->opcode != MEM_REF
@@ -4194,16 +4196,19 @@ compute_avail (function *fun)
 			  operands.release ();
 			  continue;
 			}
-		      else if (alias_set_subset_of (ref->set, set))
+		      else if (ref->set == set
+			       || alias_set_subset_of (ref->set, set))
 			{
+			  tree reft = reference_alias_ptr_type (rhs1);
 			  ref->set = set;
+			  ref->base_set = set;
 			  if (ref1->opcode == MEM_REF)
 			    ref1->op0
-			      = wide_int_to_tree (TREE_TYPE (ref2->op0),
+			      = wide_int_to_tree (reft,
 						  wi::to_wide (ref1->op0));
 			  else
 			    ref1->op2
-			      = wide_int_to_tree (TREE_TYPE (ref2->op2),
+			      = wide_int_to_tree (reft,
 						  wi::to_wide (ref1->op2));
 			}
 		      else

commit 00c806ea70406e6e67170e51095533dcb8a20cf8
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Jul 27 12:34:34 2023

    XFAIL parts broken deliberately by r13-1762-gf9d4c3b45c5ed5
    
    The following XFAILs recognizing a complex store as memset.
    
            PR tree-optimization/110829
            * gcc.dg/pr56837.c: XFAIL part of the testcase.
    
    (cherry picked from commit 41482832ad0aeaa0e4ae2f8d2beff17023cd00bf)

diff --git a/gcc/testsuite/gcc.dg/pr56837.c b/gcc/testsuite/gcc.dg/pr56837.c
index 0bb958f0b0d..6466b119489 100644
--- a/gcc/testsuite/gcc.dg/pr56837.c
+++ b/gcc/testsuite/gcc.dg/pr56837.c
@@ -62,5 +62,5 @@ fv (void)
 /* { dg-final { scan-tree-dump-times "memset ..d, 68, 8192.;" 1 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "memset ..l, 124, 8192.;" 1 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "memset ..b, 1, 1024.;" 1 "optimized" } } */
-/* { dg-final { scan-tree-dump-times "memset ..c, 68, 16384.;" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "memset ..c, 68, 16384.;" 1 "optimized" { xfail *-*-* } } } */
 /* { dg-final { scan-tree-dump-times "memset ..v, 18, 16384.;" 1 "optimized" } } */

commit 8e811edea309b2097e23cde48ee6fb6467a9094d
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Jul 26 22:52:13 2023

    c++: unifying REAL_CSTs [PR110809]
    
    This teaches unify how to compare two REAL_CSTs.
    
            PR c++/110809
    
    gcc/cp/ChangeLog:
    
            * pt.cc (unify) <case INTEGER_CST>: Generalize to handle
            REAL_CST as well.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/nontype-float3.C: New test.
    
    (cherry picked from commit 744e1f35266dbd6b6fb95c7e8422562815f8b56f)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index fa9c29d4e4f..fd6bb4a2167 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -24918,12 +24918,13 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
       /* Types INTEGER_CST and MINUS_EXPR can come from array bounds.  */
       /* Type INTEGER_CST can come from ordinary constant template args.  */
     case INTEGER_CST:
+    case REAL_CST:
       while (CONVERT_EXPR_P (arg))
 	arg = TREE_OPERAND (arg, 0);
 
-      if (TREE_CODE (arg) != INTEGER_CST)
+      if (TREE_CODE (arg) != TREE_CODE (parm))
 	return unify_template_argument_mismatch (explain_p, parm, arg);
-      return (tree_int_cst_equal (parm, arg)
+      return (simple_cst_equal (parm, arg)
 	      ? unify_success (explain_p)
 	      : unify_template_argument_mismatch (explain_p, parm, arg));
 
diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-float3.C b/gcc/testsuite/g++.dg/cpp2a/nontype-float3.C
new file mode 100644
index 00000000000..044fb99905a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/nontype-float3.C
@@ -0,0 +1,12 @@
+// PR c++/110809
+// { dg-do compile { target c++20 } }
+
+template<class, double> struct A { };
+
+template<class T> void f(A<T, 1.0>);
+template<class T> void f(A<T, 2.0>);
+
+int main() {
+  f(A<int, 1.0>{});
+  f(A<int, 1.1>{}); // { dg-error "no match" }
+}
