[PATCH] Check optab before transforming atomic bit test and operations

H.J. Lu hjl.tools@gmail.com
Mon Nov 15 19:05:43 GMT 2021


On Mon, Nov 15, 2021 at 10:59 AM Jeff Law <jeffreyalaw@gmail.com> wrote:
>
>
>
> On 11/15/2021 6:39 AM, H.J. Lu via Gcc-patches wrote:
> > Check optab before transforming equivalent, but slighly different cases
> > of atomic bit test and operations to their canonical forms.
> >
> > gcc/
> >
> >       PR middle-end/103184
> >       * tree-ssa-ccp.c (optimize_atomic_bit_test_and): Check optab
> >       before transforming equivalent, but slighly different cases to
> >       their canonical forms.
> >
> > gcc/testsuite/
> >
> >       PR middle-end/103184
> >       * gcc.dg/pr103184-1.c: New test.
> >       * gcc.dg/pr103184-2.c: Likewise.
>
> >       }
> >       }
> >
> > -  switch (fn)
> > -    {
> > -    case IFN_ATOMIC_BIT_TEST_AND_SET:
> > -      optab = atomic_bit_test_and_set_optab;
> > -      break;
> > -    case IFN_ATOMIC_BIT_TEST_AND_COMPLEMENT:
> > -      optab = atomic_bit_test_and_complement_optab;
> > -      break;
> > -    case IFN_ATOMIC_BIT_TEST_AND_RESET:
> > -      optab = atomic_bit_test_and_reset_optab;
> > -      break;
> > -    default:
> > -      return;
> > -    }
> > -
> >     if (optab_handler (optab, TYPE_MODE (TREE_TYPE (lhs))) == CODE_FOR_nothing)
> >       return;
> Shouldn't the test of the return value of optab_handler here just go
> away since we're testing it earlier?  OK with that fix.
>

The earlier check is predicated on if (rhs_code != BIT_AND_EXPR):

  if (rhs_code != BIT_AND_EXPR)
    {
      if (rhs_code != NOP_EXPR && rhs_code != BIT_NOT_EXPR)
        return;

      tree use_lhs = gimple_assign_lhs (use_stmt);
      if (TREE_CODE (use_lhs) == SSA_NAME
          && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (use_lhs))
        return;

      tree use_rhs = gimple_assign_rhs1 (use_stmt);
      if (lhs != use_rhs)
        return;

      if (optab_handler (optab, TYPE_MODE (TREE_TYPE (lhs)))
          == CODE_FOR_nothing)
        return;

I can add an "else"

else  if (optab_handler (optab, TYPE_MODE (TREE_TYPE (lhs)))
            == CODE_FOR_nothing)
    return;

Will it be OK?

Thanks.

-- 
H.J.


More information about the Gcc-patches mailing list