https://gcc.gnu.org/g:24bc02b1eda3795163616c02725ee14bac9d975c

commit r16-4728-g24bc02b1eda3795163616c02725ee14bac9d975c
Author: Andrew Pinski <[email protected]>
Date:   Wed Oct 29 16:30:50 2025 -0700

    gimple-fold: Remove assume_aligned folding
    
    So in the end I agree with Richi's comment at
    https://gcc.gnu.org/pipermail/gcc-patches/2025-October/698856.html:
    > I see.  I wonder whether it would be better to leave 
__builtin_assume_aligned
    > around then, because that inherently introduces the copy and it would 
show why.
    > TER / SSA coalescing might make a mess our of the copies you leave in 
place
    > anyway, no?
    
    This leaves __builtin_assume_aligned around.
    Will also push the revert of r16-4637-g8590b32deac05e along side this.
    
    gcc/ChangeLog:
    
            * gimple-fold.cc (gimple_fold_builtin_assume_aligned): Remove.
            (gimple_fold_builtin): Don't fold __builtin_assume_aligned
    
    gcc/testsuite/ChangeLog:
    
            * c-c++-common/ubsan/align-5.c: Xfail.
            * gcc.dg/pr107389.c: Move to...
            * gcc.dg/torture/pr107389.c: ...here. Skip for lto.
            * gcc.dg/builtin-assume-aligned-1.c: Instead of
            testing for deleting of assume-align, test for
            the alignment/misalignment. Also disable the
            vectorizer.
    
    Signed-off-by: Andrew Pinski <[email protected]>

Diff:
---
 gcc/gimple-fold.cc                              | 21 ---------------------
 gcc/testsuite/c-c++-common/ubsan/align-5.c      |  4 +++-
 gcc/testsuite/gcc.dg/builtin-assume-aligned-1.c | 10 ++++++++--
 gcc/testsuite/gcc.dg/{ => torture}/pr107389.c   |  3 ++-
 4 files changed, 13 insertions(+), 25 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index edcc04adc08c..8f72dbb929be 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -5233,24 +5233,6 @@ gimple_fold_builtin_constant_p (gimple_stmt_iterator 
*gsi)
   return true;
 }
 
-/* Fold __builtin_assume_aligned builtin.  */
-
-static bool
-gimple_fold_builtin_assume_aligned (gimple_stmt_iterator *gsi)
-{
-  if (!fold_before_rtl_expansion_p ())
-    return false;
-
-  gcall *call = as_a<gcall*>(gsi_stmt (*gsi));
-
-  if (gimple_call_num_args (call) < 2)
-    return false;
-
-  gimplify_and_update_call_from_tree (gsi, gimple_call_arg (call, 0));
-
-  return true;
-}
-
 /* If va_list type is a simple pointer and nothing special is needed,
    optimize __builtin_va_start (&ap, 0) into ap = __builtin_next_arg (0),
    __builtin_va_end (&ap) out as NOP and __builtin_va_copy into a simple
@@ -5548,9 +5530,6 @@ gimple_fold_builtin (gimple_stmt_iterator *gsi)
     case BUILT_IN_CONSTANT_P:
       return gimple_fold_builtin_constant_p (gsi);
 
-    case BUILT_IN_ASSUME_ALIGNED:
-      return gimple_fold_builtin_assume_aligned (gsi);
-
     default:;
     }
 
diff --git a/gcc/testsuite/c-c++-common/ubsan/align-5.c 
b/gcc/testsuite/c-c++-common/ubsan/align-5.c
index 484790134a66..6d2ac26612bb 100644
--- a/gcc/testsuite/c-c++-common/ubsan/align-5.c
+++ b/gcc/testsuite/c-c++-common/ubsan/align-5.c
@@ -11,4 +11,6 @@ foo (char *p)
   return *q;
 }
 
-/* { dg-final { scan-assembler "__ubsan_handle" } } */
+/* xfail, see PR 122038 as __builtin_assume_aligned should be instrumented 
instead
+   of only the load. */
+/* { dg-final { scan-assembler "__ubsan_handle" { xfail *-*-* } } } */
diff --git a/gcc/testsuite/gcc.dg/builtin-assume-aligned-1.c 
b/gcc/testsuite/gcc.dg/builtin-assume-aligned-1.c
index a74eccee4ab8..01aa884d0bc5 100644
--- a/gcc/testsuite/gcc.dg/builtin-assume-aligned-1.c
+++ b/gcc/testsuite/gcc.dg/builtin-assume-aligned-1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O3 -fdump-tree-optimized" } */
+/* { dg-options "-O3 -fno-tree-vectorize -fdump-tree-optimized-alias" } */
 
 void
 test1 (double *out1, double *out2, double *out3, double *in1,
@@ -19,6 +19,8 @@ test1 (double *out1, double *out2, double *out3, double *in1,
     }
 }
 
+/* { dg-final { scan-tree-dump-times " ALIGN = 16, MISALIGN = 0" 5 "optimized" 
} } */
+
 void
 test2 (double *out1, double *out2, double *out3, double *in1,
        double *in2, int len)
@@ -37,4 +39,8 @@ test2 (double *out1, double *out2, double *out3, double *in1,
     }
 }
 
-/* { dg-final { scan-tree-dump-not "__builtin_assume_aligned" "optimized" } } 
*/
+
+/* { dg-final { scan-tree-dump-times " ALIGN = 32" 5 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " ALIGN = 32, MISALIGN = 16" 4 
"optimized" } } */
+/* { dg-final { scan-tree-dump-times " ALIGN = 32, MISALIGN = 0" 1 "optimized" 
} } */
+
diff --git a/gcc/testsuite/gcc.dg/pr107389.c 
b/gcc/testsuite/gcc.dg/torture/pr107389.c
similarity index 73%
rename from gcc/testsuite/gcc.dg/pr107389.c
rename to gcc/testsuite/gcc.dg/torture/pr107389.c
index deb633807044..23c2776ab736 100644
--- a/gcc/testsuite/gcc.dg/pr107389.c
+++ b/gcc/testsuite/gcc.dg/torture/pr107389.c
@@ -1,5 +1,6 @@
 /* { dg-do compile } */
-/* { dg-options "-fdump-tree-optimized-alias" } */
+/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
+/* { dg-additional-options "-fdump-tree-optimized-alias" } */
 
 unsigned foo (void *p)
 {

Reply via email to