On Thu, 2020-06-04 at 02:37 +0200, Ilya Leoshkevich wrote:
> Bootstrapped and regtested on x86_64-redhat-linux, ppc64le-redhat-
> linux
> and s390x-redhat-linux.
> 
> 
> Linux Kernel (specifically, drivers/leds/trigger/ledtrig-cpu.c) build
> with GCC 10 fails on s390 with "impossible constraint".
> 
> The problem is that jump threading makes __builtin_constant_p lie
> when
> an expression in question appears to be a constant on a threading
> path.
> 
> Fix by disallowing __builtin_constant_p on threading paths.
> 
> gcc/ChangeLog:
> 
> 2020-06-03  Ilya Leoshkevich  <i...@linux.ibm.com>
> 
>       * tree-ssa-threadbackward.c
> (thread_jumps::profitable_jump_thread_path):
>       Do not allow __builtin_constant_p on a threading path.
> 
> gcc/testsuite/ChangeLog:
> 
> 2020-06-03  Ilya Leoshkevich  <i...@linux.ibm.com>
> 
>       * gcc.target/s390/builtin-constant-p-threading.c: New test.
> ---
>  .../s390/builtin-constant-p-threading.c       | 46
> +++++++++++++++++++
>  gcc/tree-ssa-threadbackward.c                 |  7 ++-
>  2 files changed, 52 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/s390/builtin-constant-p-
> threading.c
> 
> diff --git a/gcc/testsuite/gcc.target/s390/builtin-constant-p-
> threading.c b/gcc/testsuite/gcc.target/s390/builtin-constant-p-
> threading.c
> new file mode 100644
> index 00000000000..5f0acdce0b0
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/s390/builtin-constant-p-threading.c
> @@ -0,0 +1,46 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -march=z196 -mzarch" } */
> +
> +typedef struct
> +{
> +  int counter;
> +} atomic_t;
> +
> +static inline __attribute__ ((__gnu_inline__)) int
> +__atomic_add (int val, int *ptr)
> +{
> +  int old;
> +  asm volatile("laa %[old],%[val],%[ptr]\n"
> +            : [old] "=d" (old), [ptr] "+Q"(*ptr)
> +            : [val] "d" (val)
> +            : "cc", "memory");
> +  return old;
> +}
> +
> +static inline __attribute__ ((__gnu_inline__)) void
> +__atomic_add_const (int val, int *ptr)
> +{
> +  asm volatile("asi %[ptr],%[val]\n"
> +            : [ptr] "+Q" (*ptr)
> +            : [val] "i" (val)
> +            : "cc", "memory");
> +}
> +
> +static inline __attribute__ ((__gnu_inline__)) void
> +atomic_add (int i, atomic_t *v)
> +{
> +  if (__builtin_constant_p (i) && (i > -129) && (i < 128))
> +    {
> +      __atomic_add_const (i, &v->counter);
> +      return;
> +    }
> +  __atomic_add (i, &v->counter);
> +}
> +
> +static atomic_t num_active_cpus = { (0) };
> +
> +void
> +ledtrig_cpu (_Bool is_active)
> +{
> +  atomic_add (is_active ? 1 : -1, &num_active_cpus);
> +}
> diff --git a/gcc/tree-ssa-threadbackward.c b/gcc/tree-ssa-
> threadbackward.c
> index 327628f1662..668932f6d85 100644
> --- a/gcc/tree-ssa-threadbackward.c
> +++ b/gcc/tree-ssa-threadbackward.c
> @@ -259,8 +259,13 @@ thread_jumps::profitable_jump_thread_path
> (basic_block bbi, tree name,
>              !gsi_end_p (gsi);
>              gsi_next_nondebug (&gsi))
>           {
> +           /* Do not allow OpenACC loop markers and
> __builtin_constant_p on
> +              a threading path.  The latter is disallowed, because
> an
> +              expression being constant on a threading path does not
> mean it
> +              can be considered constant in the entire function.  */
>             gimple *stmt = gsi_stmt (gsi);
> -           if (gimple_call_internal_p (stmt, IFN_UNIQUE))
> +           if (gimple_call_internal_p (stmt, IFN_UNIQUE)
> +               || gimple_call_builtin_p (stmt, BUILT_IN_CONSTANT_P))
>               {
>                 m_path.pop ();
>                 return NULL;

Gentle ping.

Reply via email to