On Sat, Nov 25, 2023 at 8:19 AM Jakub Jelinek <ja...@redhat.com> wrote:
>
> Hi!
>
> The following testcase is miscompiled in GCC 14 because the
> *jcc_bt<mode>_mask and *jcc_bt<SWI48:mode>_mask_1 patterns have just
> one argument in (match_operator 0 "bt_comparison_operator" [...])
> but as bt_comparison_operator is eq,ne, we need two.
> The md readers don't warn about it, after all, some checks can
> be done in the predicate rather than specified explicitly, and the
> behavior is that anything is accepted as the second argument.
>
> I went through all other i386.md match_operator uses and all others
> looked right (extract_operator using 3 operands, all others 2).
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> I think we'll want to fix this at different spots in older releases
> because I think the bug was introduced already in 2008, though most
> likely just latent.
>
> 2023-11-25  Jakub Jelinek  <ja...@redhat.com>
>
>         PR target/111408
>         * config/i386/i386.md (*jcc_bt<mode>_mask,
>         *jcc_bt<SWI48:mode>_mask_1): Add (const_int 0) as expected
>         second operand of bt_comparison_operator.
>
>         * gcc.c-torture/execute/pr111408.c: New test.

OK, also for backports.

Thanks,
Uros.

>
> --- gcc/config/i386/i386.md.jj  2023-11-24 08:43:31.892529819 +0100
> +++ gcc/config/i386/i386.md     2023-11-24 14:26:38.645009163 +0100
> @@ -16879,7 +16879,8 @@ (define_insn_and_split "*jcc_bt<mode>_ma
>                            (const_int 1)
>                            (and:QI
>                              (match_operand:QI 2 "register_operand")
> -                            (match_operand 3 "const_int_operand")))])
> +                            (match_operand 3 "const_int_operand")))
> +                        (const_int 0)])
>                       (label_ref (match_operand 4))
>                       (pc)))
>     (clobber (reg:CC FLAGS_REG))]
> @@ -16915,7 +16916,8 @@ (define_insn_and_split "*jcc_bt<SWI48:mo
>                            (subreg:QI
>                              (and:SWI248
>                                (match_operand:SWI248 2 "register_operand")
> -                              (match_operand 3 "const_int_operand")) 0))])
> +                              (match_operand 3 "const_int_operand")) 0))
> +                        (const_int 0)])
>                       (label_ref (match_operand 4))
>                       (pc)))
>     (clobber (reg:CC FLAGS_REG))]
> --- gcc/testsuite/gcc.c-torture/execute/pr111408.c.jj   2023-11-24 
> 14:45:51.992871046 +0100
> +++ gcc/testsuite/gcc.c-torture/execute/pr111408.c      2023-11-24 
> 14:44:54.809671610 +0100
> @@ -0,0 +1,26 @@
> +/* PR target/111408 */
> +
> +int a, b, c, d;
> +short e;
> +
> +int
> +foo ()
> +{
> +  c = a % (sizeof (int) * 8);
> +  if (b & 1 << c)
> +    return -1;
> +  return 0;
> +}
> +
> +int
> +main ()
> +{
> +  for (; e != 1; e++)
> +    {
> +      int g = foo ();
> +      if (g + d - 9 + d)
> +       continue;
> +      for (;;)
> +       __builtin_abort ();
> +    }
> +}
>
>         Jakub
>

Reply via email to