https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120925

            Bug ID: 120925
           Summary: partial kortest pattern not recognized
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mkretz at gcc dot gnu.org
  Target Milestone: ---
            Target: x86_64-* i?86-*-*

Test case (https://compiler-explorer.com/z/ebTT6W664):

static constexpr unsigned char im = 0x3f;

inline
bool all_of1(unsigned char k)
{ return (k & im) == im; }

inline
bool all_of2(unsigned char k)
{ return __builtin_ia32_kortestcqi(k, ~im); }

using V [[gnu::vector_size(8 * 8)]] = double;

inline
unsigned char eq(V a, V b)
{ return __builtin_ia32_cmppd512_mask(a, b, 0x00, -1, 0x04); }

V f1(V a, V b)
{
  if (all_of1(eq(a, b)))
    return a;
  else
    return V();
}

V f2(V a, V b)
{
  if (all_of2(eq(a, b)))
    return a;
  else
    return V();
}


f1 and f2 are equivalent functions. The all_of1 & branch in f1 should be
recognized and transformed into a kortest instruction.
I can think of two patterns:
1. if((__mmaskN & k1) == k1)
2. if((__mmaskN | __mmaskN(~k1)) == ~__mmaskN)

Reply via email to